author | lbessard |
Wed, 28 Feb 2007 15:55:41 +0100 | |
changeset 19 | cee3c4e5afe2 |
parent 18 | e6af5eb5f546 |
child 21 | ae19aa4ff2d9 |
permissions | -rw-r--r-- |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
1 |
/* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
2 |
* (c) 2007 Mario de Sousa, Laurent Bessard |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
3 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
4 |
* Offered to the public under the terms of the GNU General Public License |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
6 |
* License, or (at your option) any later version. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
7 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
8 |
* This program is distributed in the hope that it will be useful, but |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
11 |
* Public License for more details. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
12 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
13 |
* This code is made available on the understanding that it will not be |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
14 |
* used in safety-critical situations without a full and competent review. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
15 |
*/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
16 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
17 |
/* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
18 |
* An IEC 61131-3 IL and ST compiler. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
19 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
20 |
* Based on the |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
22 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
23 |
*/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
24 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
25 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
26 |
/* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
27 |
* Conversion of sfc networks (i.e. SFC code). |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
28 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
29 |
* This is part of the 4th stage that generates |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
30 |
* a c++ source program equivalent to the SFC, IL and ST |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
31 |
* code. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
32 |
*/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
33 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
34 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
35 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
36 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
37 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
38 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
39 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
40 |
|
19 | 41 |
class transition_element { |
42 |
||
43 |
private: |
|
44 |
transition_c *transition; |
|
45 |
char priority; |
|
46 |
char index; |
|
47 |
transition_element *prev; |
|
48 |
transition_element *next; |
|
49 |
||
50 |
public: |
|
51 |
transition_element(transition_c *tr, char pr, char idx) { |
|
52 |
transition = tr; |
|
53 |
priority = pr; |
|
54 |
index = idx; |
|
55 |
} |
|
56 |
||
57 |
void set_prev(transition_element *tr) {prev = tr;} |
|
58 |
void set_next(transition_element *tr) {next = tr;} |
|
59 |
transition_element *get_prev(void) {return prev;} |
|
60 |
transition_element *get_next(void) {return next;} |
|
61 |
transition_c *get_transition(void) {return transition;} |
|
62 |
char get_priority(void) {return priority;} |
|
63 |
char get_index(void) {return index;} |
|
64 |
}; |
|
65 |
||
66 |
||
67 |
||
68 |
||
69 |
/***********************************************************************/ |
|
70 |
/***********************************************************************/ |
|
71 |
/***********************************************************************/ |
|
72 |
/***********************************************************************/ |
|
73 |
||
74 |
class generate_cc_sfc_transitionresetsteps_c: public generate_cc_base_c { |
|
75 |
||
76 |
private: |
|
77 |
char transition_number; |
|
78 |
||
79 |
public: |
|
80 |
generate_cc_sfc_transitionresetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
|
81 |
: generate_cc_base_c(s4o_ptr) { |
|
82 |
this->set_variable_prefix(variable_prefix); |
|
83 |
} |
|
84 |
||
85 |
void set_transition_number(char number) {transition_number = number;} |
|
86 |
void reset_transition_number(void) {transition_number = 0;} |
|
87 |
void print_transition_number(void) { |
|
88 |
char str[10]; |
|
89 |
sprintf(str, "%d", transition_number); |
|
90 |
s4o.print(str); |
|
91 |
} |
|
92 |
||
93 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
|
94 |
print_variable_prefix(); |
|
95 |
s4o.print("step_list["); |
|
96 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
|
97 |
step_name->accept(*this); |
|
98 |
s4o.print("]."); |
|
99 |
s4o.print(argument); |
|
100 |
} |
|
101 |
||
102 |
void print_reset_step(symbol_c *step_name) { |
|
103 |
s4o.print(s4o.indent_spaces); |
|
104 |
print_step_argument(step_name, "state"); |
|
105 |
s4o.print(" = 0;\n" + s4o.indent_spaces); |
|
106 |
print_step_argument(step_name, "elapsed_time"); |
|
107 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
108 |
} |
|
109 |
||
110 |
/*********************************************/ |
|
111 |
/* B.1.6 Sequential function chart elements */ |
|
112 |
/*********************************************/ |
|
113 |
||
114 |
void *visit(initial_step_c *symbol) {return NULL;} |
|
115 |
||
116 |
void *visit(step_c *symbol) {return NULL;} |
|
117 |
||
118 |
void *visit(transition_c *symbol) { |
|
119 |
if (symbol->integer == NULL) { |
|
120 |
s4o.print(s4o.indent_spaces + "if ("); |
|
121 |
print_variable_prefix(); |
|
122 |
s4o.print("transition_list["); |
|
123 |
print_transition_number(); |
|
124 |
s4o.print("]) {\n"); |
|
125 |
s4o.indent_right(); |
|
126 |
symbol->from_steps->accept(*this); |
|
127 |
s4o.indent_left(); |
|
128 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
129 |
} |
|
130 |
transition_number++; |
|
131 |
return NULL; |
|
132 |
} |
|
133 |
||
134 |
void *visit(steps_c *symbol) { |
|
135 |
if (symbol->step_name != NULL) { |
|
136 |
print_reset_step(symbol->step_name); |
|
137 |
} |
|
138 |
if (symbol->step_name_list != NULL) { |
|
139 |
symbol->step_name_list->accept(*this); |
|
140 |
} |
|
141 |
return NULL; |
|
142 |
} |
|
143 |
||
144 |
void *visit(step_name_list_c *symbol) { |
|
145 |
for(int i = 0; i < symbol->n; i++) { |
|
146 |
print_reset_step(symbol->elements[i]); |
|
147 |
} |
|
148 |
return NULL; |
|
149 |
} |
|
150 |
||
151 |
void *visit(action_c *symbol) {return NULL;} |
|
152 |
||
153 |
}; /* generate_cc_sfc_transitionresetsteps_c */ |
|
154 |
||
155 |
||
156 |
||
157 |
||
158 |
/***********************************************************************/ |
|
159 |
/***********************************************************************/ |
|
160 |
/***********************************************************************/ |
|
161 |
/***********************************************************************/ |
|
162 |
||
163 |
class generate_cc_sfc_transitionsetsteps_c: public generate_cc_base_c { |
|
164 |
||
165 |
private: |
|
166 |
char transition_number; |
|
167 |
||
168 |
public: |
|
169 |
generate_cc_sfc_transitionsetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
|
170 |
: generate_cc_base_c(s4o_ptr) { |
|
171 |
this->set_variable_prefix(variable_prefix); |
|
172 |
} |
|
173 |
||
174 |
void reset_transition_number(void) {transition_number = 0;} |
|
175 |
void print_transition_number(void) { |
|
176 |
char str[10]; |
|
177 |
sprintf(str, "%d", transition_number); |
|
178 |
s4o.print(str); |
|
179 |
} |
|
180 |
||
181 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
|
182 |
print_variable_prefix(); |
|
183 |
s4o.print("step_list["); |
|
184 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
|
185 |
step_name->accept(*this); |
|
186 |
s4o.print("]."); |
|
187 |
s4o.print(argument); |
|
188 |
} |
|
189 |
||
190 |
void print_set_step(symbol_c *step_name) { |
|
191 |
s4o.print(s4o.indent_spaces); |
|
192 |
print_step_argument(step_name, "state"); |
|
193 |
s4o.print(" = 1;\n"); |
|
194 |
} |
|
195 |
||
196 |
/*********************************************/ |
|
197 |
/* B.1.6 Sequential function chart elements */ |
|
198 |
/*********************************************/ |
|
199 |
||
200 |
void *visit(initial_step_c *symbol) {return NULL;} |
|
201 |
||
202 |
void *visit(step_c *symbol) {return NULL;} |
|
203 |
||
204 |
void *visit(transition_c *symbol) { |
|
205 |
s4o.print(s4o.indent_spaces + "if ("); |
|
206 |
print_variable_prefix(); |
|
207 |
s4o.print("transition_list["); |
|
208 |
print_transition_number(); |
|
209 |
s4o.print("]) {\n"); |
|
210 |
s4o.indent_right(); |
|
211 |
symbol->to_steps->accept(*this); |
|
212 |
s4o.indent_left(); |
|
213 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
214 |
transition_number++; |
|
215 |
return NULL; |
|
216 |
} |
|
217 |
||
218 |
void *visit(steps_c *symbol) { |
|
219 |
if (symbol->step_name != NULL) { |
|
220 |
print_set_step(symbol->step_name); |
|
221 |
} |
|
222 |
if (symbol->step_name_list != NULL) { |
|
223 |
symbol->step_name_list->accept(*this); |
|
224 |
} |
|
225 |
return NULL; |
|
226 |
} |
|
227 |
||
228 |
void *visit(step_name_list_c *symbol) { |
|
229 |
for(int i = 0; i < symbol->n; i++) { |
|
230 |
print_set_step(symbol->elements[i]); |
|
231 |
} |
|
232 |
return NULL; |
|
233 |
} |
|
234 |
||
235 |
void *visit(action_c *symbol) {return NULL;} |
|
236 |
||
237 |
}; /* generate_cc_sfc_transitionsetsteps_c */ |
|
238 |
||
239 |
||
240 |
||
241 |
||
242 |
/***********************************************************************/ |
|
243 |
/***********************************************************************/ |
|
244 |
/***********************************************************************/ |
|
245 |
/***********************************************************************/ |
|
246 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
247 |
class generate_cc_sfc_transitiontest_c: public generate_cc_base_c { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
248 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
249 |
private: |
18 | 250 |
char transition_number; |
251 |
||
252 |
private: |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
253 |
generate_cc_il_c *generate_cc_il; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
254 |
generate_cc_st_c *generate_cc_st; |
19 | 255 |
generate_cc_sfc_transitionresetsteps_c *generate_cc_sfc_transitionresetsteps; |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
256 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
257 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
258 |
generate_cc_sfc_transitiontest_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
259 |
: generate_cc_base_c(s4o_ptr) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
260 |
generate_cc_il = new generate_cc_il_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
261 |
generate_cc_st = new generate_cc_st_c(s4o_ptr, scope, variable_prefix); |
19 | 262 |
generate_cc_sfc_transitionresetsteps = new generate_cc_sfc_transitionresetsteps_c(s4o_ptr, scope, variable_prefix); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
263 |
this->set_variable_prefix(variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
264 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
265 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
266 |
~generate_cc_sfc_transitiontest_c(void) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
267 |
delete generate_cc_il; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
268 |
delete generate_cc_st; |
19 | 269 |
delete generate_cc_sfc_transitionresetsteps; |
270 |
} |
|
271 |
||
272 |
void set_transition_number(char number) {transition_number = number;} |
|
18 | 273 |
void print_transition_number(void) { |
274 |
char str[10]; |
|
275 |
sprintf(str, "%d", transition_number); |
|
276 |
s4o.print(str); |
|
277 |
} |
|
278 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
279 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
280 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
281 |
s4o.print("step_list["); |
18 | 282 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
283 |
step_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
284 |
s4o.print("]."); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
285 |
s4o.print(argument); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
286 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
287 |
|
19 | 288 |
void print_reset_step(symbol_c *step_name) { |
289 |
s4o.print(s4o.indent_spaces); |
|
290 |
print_step_argument(step_name, "state"); |
|
291 |
s4o.print(" = 0;\n" + s4o.indent_spaces); |
|
292 |
print_step_argument(step_name, "elapsed_time"); |
|
293 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
294 |
} |
|
295 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
296 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
297 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
298 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
299 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
300 |
void *visit(transition_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
301 |
s4o.print(s4o.indent_spaces + "if ("); |
18 | 302 |
symbol->from_steps->accept(*this); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
303 |
s4o.print(") {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
304 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
305 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
306 |
// Calculate transition value |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
307 |
if (symbol->transition_condition_il != NULL) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
308 |
generate_cc_il->declare_backup_variable(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
309 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
310 |
symbol->transition_condition_il->accept(*generate_cc_il); |
18 | 311 |
print_variable_prefix(); |
312 |
s4o.print("transition_list["); |
|
313 |
print_transition_number(); |
|
314 |
s4o.print("] = "); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
315 |
generate_cc_il->print_backup_variable(); |
18 | 316 |
s4o.print(";\n"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
317 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
318 |
if (symbol->transition_condition_st != NULL) { |
18 | 319 |
print_variable_prefix(); |
320 |
s4o.print("transition_list["); |
|
321 |
print_transition_number(); |
|
322 |
s4o.print("] = "); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
323 |
symbol->transition_condition_st->accept(*generate_cc_st); |
18 | 324 |
s4o.print(";\n"); |
325 |
} |
|
19 | 326 |
if (symbol->integer != NULL) { |
327 |
s4o.print(s4o.indent_spaces + "if ("); |
|
328 |
print_variable_prefix(); |
|
329 |
s4o.print("transition_list["); |
|
330 |
print_transition_number(); |
|
331 |
s4o.print("]) {\n"); |
|
332 |
s4o.indent_right(); |
|
333 |
symbol->from_steps->accept(*generate_cc_sfc_transitionresetsteps); |
|
334 |
s4o.indent_left(); |
|
335 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
336 |
} |
|
18 | 337 |
s4o.indent_left(); |
338 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n"); |
|
339 |
s4o.indent_right(); |
|
340 |
s4o.print(s4o.indent_spaces); |
|
341 |
print_variable_prefix(); |
|
342 |
s4o.print("transition_list["); |
|
343 |
print_transition_number(); |
|
344 |
s4o.print("] = 0;\n"); |
|
345 |
s4o.indent_left(); |
|
346 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
347 |
||
348 |
transition_number++; |
|
349 |
return NULL; |
|
350 |
} |
|
351 |
||
352 |
void *visit(steps_c *symbol) { |
|
353 |
if (symbol->step_name != NULL) { |
|
354 |
print_step_argument(symbol->step_name, "state"); |
|
355 |
} |
|
356 |
if (symbol->step_name_list != NULL) { |
|
357 |
symbol->step_name_list->accept(*this); |
|
358 |
} |
|
359 |
return NULL; |
|
360 |
} |
|
361 |
||
362 |
void *visit(step_name_list_c *symbol) { |
|
363 |
for(int i = 0; i < symbol->n; i++) { |
|
364 |
print_step_argument(symbol->elements[i], "state"); |
|
365 |
if (i < symbol->n - 1) { |
|
366 |
s4o.print(" && "); |
|
367 |
} |
|
368 |
} |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
369 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
370 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
371 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
372 |
}; /* generate_cc_sfc_transitiontest_c */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
373 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
374 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
375 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
376 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
377 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
378 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
379 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
380 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
381 |
|
19 | 382 |
class generate_cc_sfc_transitionsort_c: public iterator_visitor_c { |
18 | 383 |
|
384 |
private: |
|
385 |
char transition_number; |
|
19 | 386 |
transition_element *first_transition; |
387 |
transition_element *last_transition; |
|
388 |
||
389 |
private: |
|
390 |
generate_cc_sfc_transitiontest_c *generate_cc_sfc_transitiontest; |
|
391 |
||
18 | 392 |
public: |
19 | 393 |
generate_cc_sfc_transitionsort_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) { |
394 |
generate_cc_sfc_transitiontest = new generate_cc_sfc_transitiontest_c(s4o_ptr, scope, variable_prefix); |
|
395 |
first_transition = NULL; |
|
396 |
last_transition = NULL; |
|
397 |
} |
|
398 |
||
399 |
~generate_cc_sfc_transitionsort_c(void) { |
|
400 |
delete generate_cc_sfc_transitiontest; |
|
401 |
} |
|
402 |
||
403 |
void append_transition(transition_c *transition, char priority, char index) { |
|
404 |
transition_element *new_transition = new transition_element(transition, priority, index); |
|
405 |
new_transition->set_prev(last_transition); |
|
406 |
if (last_transition != NULL) { |
|
407 |
last_transition->set_next(new_transition); |
|
408 |
} |
|
409 |
else { |
|
410 |
first_transition = new_transition; |
|
411 |
} |
|
412 |
last_transition = new_transition; |
|
413 |
transition_number++; |
|
414 |
} |
|
415 |
||
416 |
void sort_transitions(void) { |
|
417 |
int i, j; |
|
418 |
transition_element *current_transition; |
|
419 |
transition_element *next_transition; |
|
420 |
for (i = transition_number; i > 1; i--) { |
|
421 |
current_transition = first_transition; |
|
422 |
for (j = 0; j < i - 1; j++) { |
|
423 |
next_transition = current_transition->get_next(); |
|
424 |
if (current_transition->get_priority() > next_transition->get_priority()) { |
|
425 |
if (current_transition->get_prev() != NULL) { |
|
426 |
current_transition->get_prev()->set_next(next_transition); |
|
427 |
} |
|
428 |
else { |
|
429 |
first_transition = next_transition; |
|
430 |
} |
|
431 |
if (next_transition->get_next() != NULL) { |
|
432 |
next_transition->get_next()->set_prev(current_transition); |
|
433 |
} |
|
434 |
else { |
|
435 |
last_transition = current_transition; |
|
436 |
} |
|
437 |
current_transition->set_next(next_transition->get_next()); |
|
438 |
next_transition->set_prev(current_transition->get_prev()); |
|
439 |
current_transition->set_prev(next_transition); |
|
440 |
next_transition->set_next(current_transition); |
|
441 |
} |
|
442 |
else { |
|
443 |
current_transition = next_transition; |
|
444 |
} |
|
445 |
} |
|
446 |
} |
|
18 | 447 |
} |
448 |
||
449 |
void reset_transition_number(void) {transition_number = 0;} |
|
19 | 450 |
|
451 |
void generate(symbol_c *symbol) { |
|
452 |
symbol->accept(*this); |
|
453 |
sort_transitions(); |
|
454 |
transition_element *next_transition = first_transition; |
|
455 |
while (next_transition != NULL) { |
|
456 |
generate_cc_sfc_transitiontest->set_transition_number(next_transition->get_index()); |
|
457 |
next_transition->get_transition()->accept(*generate_cc_sfc_transitiontest); |
|
458 |
next_transition = next_transition->get_next(); |
|
459 |
} |
|
18 | 460 |
} |
461 |
||
462 |
/*********************************************/ |
|
463 |
/* B.1.6 Sequential function chart elements */ |
|
464 |
/*********************************************/ |
|
465 |
||
466 |
void *visit(initial_step_c *symbol) {return NULL;} |
|
467 |
||
468 |
void *visit(step_c *symbol) {return NULL;} |
|
19 | 469 |
|
18 | 470 |
void *visit(transition_c *symbol) { |
19 | 471 |
if (symbol->integer != NULL) { |
472 |
append_transition(symbol, atoi(((token_c *)symbol->integer)->value), transition_number); |
|
473 |
} |
|
474 |
else { |
|
475 |
append_transition(symbol, 0, transition_number); |
|
18 | 476 |
} |
477 |
return NULL; |
|
478 |
} |
|
479 |
||
480 |
void *visit(action_c *symbol) {return NULL;} |
|
481 |
||
19 | 482 |
};/* generate_cc_sfc_transitionsort_c */ |
18 | 483 |
|
484 |
||
485 |
||
486 |
||
487 |
/***********************************************************************/ |
|
488 |
/***********************************************************************/ |
|
489 |
/***********************************************************************/ |
|
490 |
/***********************************************************************/ |
|
491 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
492 |
class generate_cc_sfc_stepassociation_c: public generate_cc_base_c { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
493 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
494 |
private: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
495 |
symbol_c *current_step; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
496 |
symbol_c *current_action; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
497 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
498 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
499 |
generate_cc_sfc_stepassociation_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
500 |
: generate_cc_base_c(s4o_ptr) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
501 |
this->set_variable_prefix(variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
502 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
503 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
504 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
505 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
506 |
s4o.print("step_list["); |
18 | 507 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
508 |
step_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
509 |
s4o.print("]."); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
510 |
s4o.print(argument); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
511 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
512 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
513 |
void print_action_argument(symbol_c *action_name, const char* argument) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
514 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
515 |
s4o.print("action_list["); |
18 | 516 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
517 |
action_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
518 |
s4o.print("]."); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
519 |
s4o.print(argument); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
520 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
521 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
522 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
523 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
524 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
525 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
526 |
void *visit(initial_step_c *symbol) { |
18 | 527 |
if (((list_c*)symbol->action_association_list)->n > 0) { |
528 |
s4o.print(s4o.indent_spaces + "// "); |
|
529 |
symbol->step_name->accept(*this); |
|
530 |
s4o.print(" action associations\n"); |
|
531 |
current_step = symbol->step_name; |
|
532 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
533 |
s4o.indent_right(); |
|
534 |
s4o.print(s4o.indent_spaces + "char activated = "); |
|
535 |
print_step_argument(current_step, "state"); |
|
536 |
s4o.print(" && !"); |
|
537 |
print_step_argument(current_step, "prev_state"); |
|
538 |
s4o.print(";\n"); |
|
539 |
s4o.print(s4o.indent_spaces + "char desactivated = !"); |
|
540 |
print_step_argument(current_step, "state"); |
|
541 |
s4o.print(" && "); |
|
542 |
print_step_argument(current_step, "prev_state"); |
|
543 |
s4o.print(";\n"); |
|
544 |
s4o.print(s4o.indent_spaces + "char active = "); |
|
545 |
print_step_argument(current_step, "state"); |
|
546 |
s4o.print(";\n"); |
|
547 |
symbol->action_association_list->accept(*this); |
|
548 |
s4o.indent_left(); |
|
549 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
550 |
} |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
551 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
552 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
553 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
554 |
void *visit(step_c *symbol) { |
18 | 555 |
if (((list_c*)symbol->action_association_list)->n > 0) { |
556 |
s4o.print(s4o.indent_spaces + "// "); |
|
557 |
symbol->step_name->accept(*this); |
|
558 |
s4o.print(" action associations\n"); |
|
559 |
current_step = symbol->step_name; |
|
560 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
561 |
s4o.indent_right(); |
|
562 |
s4o.print(s4o.indent_spaces + "char activated = "); |
|
563 |
print_step_argument(current_step, "state"); |
|
564 |
s4o.print(" && !"); |
|
565 |
print_step_argument(current_step, "prev_state"); |
|
566 |
s4o.print(";\n"); |
|
567 |
s4o.print(s4o.indent_spaces + "char desactivated = !"); |
|
568 |
print_step_argument(current_step, "state"); |
|
569 |
s4o.print(" && "); |
|
570 |
print_step_argument(current_step, "prev_state"); |
|
571 |
s4o.print(";\n"); |
|
572 |
s4o.print(s4o.indent_spaces + "char active = "); |
|
573 |
print_step_argument(current_step, "state"); |
|
574 |
s4o.print(";\n"); |
|
575 |
symbol->action_association_list->accept(*this); |
|
576 |
s4o.indent_left(); |
|
577 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
578 |
} |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
579 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
580 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
581 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
582 |
void *visit(transition_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
583 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
584 |
void *visit(action_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
585 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
586 |
void *visit(action_association_list_c* symbol) { |
18 | 587 |
print_list(symbol, "", "\n", "\n"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
588 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
589 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
590 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
591 |
void *visit(action_association_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
592 |
if (symbol->action_qualifier != NULL) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
593 |
current_action = symbol->action_name; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
594 |
symbol->action_qualifier->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
595 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
596 |
else { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
597 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
598 |
print_step_argument(current_step, "state"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
599 |
s4o.print(") {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
600 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
601 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
602 |
print_action_argument(symbol->action_name, "state"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
603 |
s4o.print(" = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
604 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
605 |
s4o.print(s4o.indent_spaces + "}"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
606 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
607 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
608 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
609 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
610 |
void *visit(action_qualifier_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
611 |
char *qualifier = (char *)symbol->action_qualifier->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
612 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
613 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
614 |
if (strcmp(qualifier, "N") == 0) { |
18 | 615 |
s4o.print("active"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
616 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
617 |
if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
618 |
strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0) { |
18 | 619 |
s4o.print("activated"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
620 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
621 |
if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
18 | 622 |
s4o.print("active && "); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
623 |
print_step_argument(current_step, "elapsed_time"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
624 |
if (strcmp(qualifier, "D") == 0) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
625 |
s4o.print(" >= "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
626 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
627 |
else { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
628 |
s4o.print(" < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
629 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
630 |
symbol->action_time->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
631 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
632 |
s4o.print(") {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
633 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
634 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
635 |
if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
636 |
strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
637 |
print_action_argument(current_action, "state"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
638 |
s4o.print(" = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
639 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
640 |
if (strcmp(qualifier, "SD") == 0 || strcmp(qualifier, "DS") == 0 || |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
641 |
strcmp(qualifier, "SL") == 0) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
642 |
if (strcmp(qualifier, "SL") == 0) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
643 |
print_action_argument(current_action, "reset_remaining_time"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
644 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
645 |
else { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
646 |
print_action_argument(current_action, "set_remaining_time"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
647 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
648 |
s4o.print(" = "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
649 |
symbol->action_time->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
650 |
s4o.print(";\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
651 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
652 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
653 |
s4o.print(s4o.indent_spaces + "}"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
654 |
if (strcmp(qualifier, "DS") == 0) { |
18 | 655 |
s4o.print("desactivated"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
656 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
657 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
658 |
print_action_argument(current_action, "set_remaining_time"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
659 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
660 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
661 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
662 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
663 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
664 |
void *visit(qualifier_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
665 |
return (void *)symbol->value; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
666 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
667 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
668 |
void *visit(timed_qualifier_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
669 |
return (void *)symbol->value; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
670 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
671 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
672 |
}; /* generate_cc_sfc_actiondecl_c */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
673 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
674 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
675 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
676 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
677 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
678 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
679 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
680 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
681 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
682 |
class generate_cc_sfc_actionexecution_c: public generate_cc_base_c { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
683 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
684 |
private: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
685 |
generate_cc_SFC_IL_ST_c *generate_cc_code; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
686 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
687 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
688 |
generate_cc_sfc_actionexecution_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
689 |
: generate_cc_base_c(s4o_ptr) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
690 |
generate_cc_code = new generate_cc_SFC_IL_ST_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
691 |
this->set_variable_prefix(variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
692 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
693 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
694 |
~generate_cc_sfc_actionexecution_c(void) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
695 |
delete generate_cc_code; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
696 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
697 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
698 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
699 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
700 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
701 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
702 |
void *visit(initial_step_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
703 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
704 |
void *visit(step_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
705 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
706 |
void *visit(transition_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
707 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
708 |
void *visit(action_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
709 |
s4o.print(s4o.indent_spaces + "if("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
710 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
711 |
s4o.print("action_list["); |
18 | 712 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
713 |
symbol->action_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
714 |
s4o.print("].state) {"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
715 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
716 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
717 |
// generate action code |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
718 |
symbol->function_block_body->accept(*generate_cc_code); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
719 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
720 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
721 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
722 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
723 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
724 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
725 |
}; /* generate_cc_sfc_actiondecl_c */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
726 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
727 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
728 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
729 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
730 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
731 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
732 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
733 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
734 |
class generate_cc_sfc_c: public generate_cc_typedecl_c { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
735 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
736 |
private: |
19 | 737 |
generate_cc_sfc_transitionsort_c *generate_cc_sfc_transitionsort; |
18 | 738 |
generate_cc_sfc_transitionresetsteps_c *generate_cc_sfc_transitionresetsteps; |
739 |
generate_cc_sfc_transitionsetsteps_c *generate_cc_sfc_transitionsetsteps; |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
740 |
generate_cc_sfc_stepassociation_c *generate_cc_sfc_stepassociation; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
741 |
generate_cc_sfc_actionexecution_c *generate_cc_sfc_actionexecution; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
742 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
743 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
744 |
generate_cc_sfc_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
745 |
: generate_cc_typedecl_c(s4o_ptr) { |
19 | 746 |
generate_cc_sfc_transitionsort = new generate_cc_sfc_transitionsort_c(s4o_ptr, scope, variable_prefix); |
18 | 747 |
generate_cc_sfc_transitionresetsteps = new generate_cc_sfc_transitionresetsteps_c(s4o_ptr, scope, variable_prefix); |
748 |
generate_cc_sfc_transitionsetsteps = new generate_cc_sfc_transitionsetsteps_c(s4o_ptr, scope, variable_prefix); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
749 |
generate_cc_sfc_stepassociation = new generate_cc_sfc_stepassociation_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
750 |
generate_cc_sfc_actionexecution = new generate_cc_sfc_actionexecution_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
751 |
this->set_variable_prefix(variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
752 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
753 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
754 |
virtual ~generate_cc_sfc_c(void) { |
19 | 755 |
delete generate_cc_sfc_transitionsort; |
18 | 756 |
delete generate_cc_sfc_transitionresetsteps; |
757 |
delete generate_cc_sfc_transitionsetsteps; |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
758 |
delete generate_cc_sfc_stepassociation; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
759 |
delete generate_cc_sfc_actionexecution; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
760 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
761 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
762 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
763 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
764 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
765 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
766 |
void *visit(sfc_network_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
767 |
s4o.print(s4o.indent_spaces +"INT i;\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
768 |
s4o.print(s4o.indent_spaces +"BOOL transition;\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
769 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
770 |
/* generate step initilizations */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
771 |
s4o.print(s4o.indent_spaces + "// Steps initialisation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
772 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
773 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
774 |
s4o.print("nb_steps; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
775 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
776 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
777 |
print_variable_prefix(); |
18 | 778 |
s4o.print("step_list[i].prev_state = "); |
779 |
print_variable_prefix(); |
|
780 |
s4o.print("step_list[i].state;\n"); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
781 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
782 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
783 |
s4o.print("step_list[i].state) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
784 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
785 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
786 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
787 |
s4o.print("step_list[i].elapsed_time = __add_timespec("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
788 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
789 |
s4o.print("step_list[i].elapsed_time, PERIOD);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
790 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
791 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
792 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
793 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
794 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
795 |
/* generate action initilizations */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
796 |
s4o.print(s4o.indent_spaces + "// Actions initialisation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
797 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
798 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
799 |
s4o.print("nb_actions; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
800 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
801 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
802 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
803 |
s4o.print("action_list[i].state = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
804 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
805 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
806 |
s4o.print("action_list[i].set = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
807 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
808 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
809 |
s4o.print("action_list[i].reset = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
810 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
811 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
812 |
s4o.print("__compare_timespec(>, action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
813 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
814 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
815 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
816 |
s4o.print("action_list[i].set_remaining_time = __sub_timespec("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
817 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
818 |
s4o.print("action_list[i].set_remaining_time, PERIOD);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
819 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
820 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
821 |
s4o.print("__compare_timespec(<=, action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
822 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
823 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
824 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
825 |
s4o.print("action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
826 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
827 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
828 |
s4o.print("action_list[i].set = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
829 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
830 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
831 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
832 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
833 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
834 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
835 |
s4o.print("__compare_timespec(>, action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
836 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
837 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
838 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
839 |
s4o.print("action_list[i].reset_remaining_time = __sub_timespec("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
840 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
841 |
s4o.print("action_list[i].reset_remaining_time, PERIOD);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
842 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
843 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
844 |
s4o.print("__compare_timespec(<=, action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
845 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
846 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
847 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
848 |
s4o.print("action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
849 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
850 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
851 |
s4o.print("action_list[i].reset = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
852 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
853 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
854 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
855 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
856 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
857 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
858 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
859 |
/* generate transition tests */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
860 |
s4o.print(s4o.indent_spaces + "// Transitions fire test\n"); |
19 | 861 |
generate_cc_sfc_transitionsort->reset_transition_number(); |
862 |
generate_cc_sfc_transitionsort->generate(symbol); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
863 |
s4o.print("\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
864 |
|
18 | 865 |
/* generate transition reset steps */ |
866 |
s4o.print(s4o.indent_spaces + "// Transitions reset steps\n"); |
|
867 |
generate_cc_sfc_transitionresetsteps->reset_transition_number(); |
|
868 |
symbol->accept(*generate_cc_sfc_transitionresetsteps); |
|
869 |
s4o.print("\n"); |
|
870 |
||
871 |
/* generate transition set steps */ |
|
872 |
s4o.print(s4o.indent_spaces + "// Transitions set steps\n"); |
|
873 |
generate_cc_sfc_transitionsetsteps->reset_transition_number(); |
|
874 |
symbol->accept(*generate_cc_sfc_transitionsetsteps); |
|
875 |
s4o.print("\n"); |
|
876 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
877 |
/* generate step association */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
878 |
s4o.print(s4o.indent_spaces + "// Steps association\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
879 |
symbol->accept(*generate_cc_sfc_stepassociation); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
880 |
s4o.print("\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
881 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
882 |
/* generate action state evaluation */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
883 |
s4o.print(s4o.indent_spaces + "// Actions state evaluation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
884 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
885 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
886 |
s4o.print("nb_actions; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
887 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
888 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
889 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
890 |
s4o.print("action_list[i].set) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
891 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
892 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
893 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
894 |
s4o.print("action_list[i].stored = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
895 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
896 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
897 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
898 |
s4o.print("action_list[i].set) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
899 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
900 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
901 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
902 |
s4o.print("action_list[i].set_remaining_time = 0;\n" + s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
903 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
904 |
s4o.print("action_list[i].reset_remaining_time = 0;\n" + s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
905 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
906 |
s4o.print("action_list[i].stored = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
907 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
908 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
909 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
910 |
s4o.print("action_list[i].state |= "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
911 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
912 |
s4o.print("action_list[i].stored;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
913 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
914 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
915 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
916 |
/* generate action execution */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
917 |
s4o.print(s4o.indent_spaces + "// Actions execution\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
918 |
symbol->accept(*generate_cc_sfc_actionexecution); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
919 |
s4o.print("\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
920 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
921 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
922 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
923 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
924 |
void generate(sequential_function_chart_c *sfc) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
925 |
sfc->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
926 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
927 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
928 |
}; /* generate_cc_sfc_c */ |