Logo AND Algorithmique Numérique Distribuée

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