Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
beb79a685f0dc4b0b1089be11e496c8ac4450e3c
[simgrid.git] / src / xbt / automaton / automatonparse_promela.c
1 /* methods for implementation of automaton from promela description */
2
3 /* Copyright (c) 2011-2012. The SimGrid Team. All rights reserved.          */
4
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. */
7
8 #include "xbt/automatonparse_promela.h"
9
10 xbt_automaton_t automaton;
11 char* state_id_src;
12
13 void init(){
14   automaton = xbt_automaton_new_automaton();
15 }
16
17 void new_state(char* id, int src){
18
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
22
23   if(strcmp(first_part,"accept")==0){
24     type = 1;
25   }else{
26     char* second_part = strtok(NULL,"_");
27     if(strcmp(second_part,"init")==0){
28       type = -1;
29     }
30   }
31
32   xbt_state_t state = NULL;
33   state = xbt_automaton_state_exists(automaton, id_state);
34   if(state == NULL){
35     state = xbt_automaton_new_state(automaton, type, id_state);
36   }
37
38   if(type==-1)
39     automaton->current_state = state;
40
41   if(src)
42     state_id_src = strdup(id_state);
43     
44 }
45
46 void new_transition(char* id, xbt_exp_label_t label){
47
48   char* id_state = strdup(id);
49   xbt_state_t state_dst = NULL;
50   new_state(id, 0);
51   state_dst = xbt_automaton_state_exists(automaton, id_state);
52   xbt_state_t state_src = xbt_automaton_state_exists(automaton, state_id_src); 
53   
54   //xbt_transition_t trans = NULL;
55   xbt_automaton_new_transition(automaton, state_src, state_dst, label);
56
57 }
58
59 xbt_exp_label_t new_label(int type, ...){
60   xbt_exp_label_t label = NULL;
61   va_list ap;
62   va_start(ap,type);
63   switch(type){
64   case 0 : {
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);
68     break;
69   }
70   case 1 : {
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);
74     break;
75   }
76   case 2 : {
77     xbt_exp_label_t exp_not = va_arg(ap, xbt_exp_label_t);
78     label = xbt_automaton_new_label(type, exp_not);
79     break;
80   }
81   case 3 : {
82     char* p = va_arg(ap, char*);
83     label = xbt_automaton_new_label(type, p);
84     break;
85   }
86   case 4 : {
87     label = xbt_automaton_new_label(type);
88     break;
89   }
90   }
91   va_end(ap);
92   return label;
93 }
94
95 xbt_automaton_t get_automaton(){
96   return automaton;
97 }
98
99
100