Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Dig through git history, and update copyright lines.
[simgrid.git] / src / xbt / automaton / automatonparse_promela.c
1 /* methods for implementation of automaton from promela description */
2
3 /* Copyright (c) 2011-2013. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "xbt/automaton.h"
10
11 static xbt_automaton_t parsed_automaton;
12 char* state_id_src;
13
14 static void new_state(char* id, int src){
15
16   char* id_state = strdup(id);
17   char* first_part = strtok(id,"_");
18   int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
19
20   if(strcmp(first_part,"accept")==0){
21     type = 1;
22   }else{
23     char* second_part = strtok(NULL,"_");
24     if(strcmp(second_part,"init")==0){
25       type = -1;
26     }
27   }
28
29   xbt_automaton_state_t state = NULL;
30   state = xbt_automaton_state_exists(parsed_automaton, id_state);
31   if(state == NULL){
32     state = xbt_automaton_state_new(parsed_automaton, type, id_state);
33   }
34
35   if(type==-1)
36     parsed_automaton->current_state = state;
37
38   if(src)
39     state_id_src = strdup(id_state);
40     
41 }
42
43 static void new_transition(char* id, xbt_automaton_exp_label_t label){
44
45   char* id_state = strdup(id);
46   xbt_automaton_state_t state_dst = NULL;
47   new_state(id, 0);
48   state_dst = xbt_automaton_state_exists(parsed_automaton, id_state);
49   xbt_automaton_state_t state_src = xbt_automaton_state_exists(parsed_automaton, state_id_src);
50   
51   //xbt_transition_t trans = NULL;
52   xbt_automaton_transition_new(parsed_automaton, state_src, state_dst, label);
53
54 }
55
56 static xbt_automaton_exp_label_t new_label(int type, ...){
57   xbt_automaton_exp_label_t label = NULL;
58   va_list ap;
59   va_start(ap,type);
60   switch(type){
61   case 0 : {
62     xbt_automaton_exp_label_t left = va_arg(ap, xbt_automaton_exp_label_t);
63     xbt_automaton_exp_label_t right = va_arg(ap, xbt_automaton_exp_label_t);
64     label = xbt_automaton_exp_label_new(type, left, right);
65     break;
66   }
67   case 1 : {
68     xbt_automaton_exp_label_t left = va_arg(ap, xbt_automaton_exp_label_t);
69     xbt_automaton_exp_label_t right = va_arg(ap, xbt_automaton_exp_label_t);
70     label = xbt_automaton_exp_label_new(type, left, right);
71     break;
72   }
73   case 2 : {
74     xbt_automaton_exp_label_t exp_not = va_arg(ap, xbt_automaton_exp_label_t);
75     label = xbt_automaton_exp_label_new(type, exp_not);
76     break;
77   }
78   case 3 : {
79     char* p = va_arg(ap, char*);
80     label = xbt_automaton_exp_label_new(type, p);
81     break;
82   }
83   case 4 : {
84     label = xbt_automaton_exp_label_new(type);
85     break;
86   }
87   }
88   va_end(ap);
89   return label;
90 }
91
92
93 #include "parserPromela.tab.cacc"
94
95 void xbt_automaton_load(xbt_automaton_t a, const char *file){
96   parsed_automaton = a;
97   yyin = fopen(file, "r");
98   yyparse();
99 }