1 /* methods for implementation of automaton from promela description */
3 /* Copyright (c) 2011-2012. The SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "xbt/automatonparse_promela.h"
10 xbt_automaton_t automaton;
14 automaton = xbt_automaton_new_automaton();
17 void new_state(char* id, int src){
19 char* id_state = strdup(id);
20 char* first_part = strtok(id,"_");
21 int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
23 if(strcmp(first_part,"accept")==0){
26 char* second_part = strtok(NULL,"_");
27 if(strcmp(second_part,"init")==0){
32 xbt_state_t state = NULL;
33 state = xbt_automaton_state_exists(automaton, id_state);
35 state = xbt_automaton_new_state(automaton, type, id_state);
39 automaton->current_state = state;
42 state_id_src = strdup(id_state);
46 void new_transition(char* id, xbt_exp_label_t label){
48 char* id_state = strdup(id);
49 xbt_state_t state_dst = NULL;
51 state_dst = xbt_automaton_state_exists(automaton, id_state);
52 xbt_state_t state_src = xbt_automaton_state_exists(automaton, state_id_src);
54 //xbt_transition_t trans = NULL;
55 xbt_automaton_new_transition(automaton, state_src, state_dst, label);
59 xbt_exp_label_t new_label(int type, ...){
60 xbt_exp_label_t label = NULL;
65 xbt_exp_label_t left = va_arg(ap, xbt_exp_label_t);
66 xbt_exp_label_t right = va_arg(ap, xbt_exp_label_t);
67 label = xbt_automaton_new_label(type, left, right);
71 xbt_exp_label_t left = va_arg(ap, xbt_exp_label_t);
72 xbt_exp_label_t right = va_arg(ap, xbt_exp_label_t);
73 label = xbt_automaton_new_label(type, left, right);
77 xbt_exp_label_t exp_not = va_arg(ap, xbt_exp_label_t);
78 label = xbt_automaton_new_label(type, exp_not);
82 char* p = va_arg(ap, char*);
83 label = xbt_automaton_new_label(type, p);
87 label = xbt_automaton_new_label(type);
95 xbt_automaton_t get_automaton(){