author | lbessard |
Mon, 27 Aug 2007 17:38:26 +0200 | |
changeset 53 | 7f0cea717342 |
parent 52 | f44458d1fa29 |
child 66 | 501e9d494744 |
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 |
|
52 | 34 |
#include <list> |
35 |
||
36 |
typedef struct |
|
37 |
{ |
|
38 |
transition_c *symbol; |
|
39 |
int priority; |
|
40 |
int index; |
|
41 |
} TRANSITION; |
|
42 |
||
43 |
||
44 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
45 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
46 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
47 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
48 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
49 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
50 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
51 |
|
52 | 52 |
class generate_cc_sfc_elements_c: public generate_cc_base_c { |
19 | 53 |
|
54 |
public: |
|
52 | 55 |
typedef enum { |
56 |
transitionlist_sg, |
|
57 |
transitiontest_sg, |
|
58 |
stepset_sg, |
|
59 |
stepreset_sg, |
|
60 |
actionassociation_sg, |
|
61 |
actionbody_sg |
|
62 |
} sfcgeneration_t; |
|
63 |
||
64 |
private: |
|
65 |
generate_cc_il_c *generate_cc_il; |
|
66 |
generate_cc_st_c *generate_cc_st; |
|
67 |
generate_cc_SFC_IL_ST_c *generate_cc_code; |
|
68 |
||
69 |
int transition_number; |
|
70 |
std::list<TRANSITION> transition_list; |
|
71 |
||
72 |
symbol_c *current_step; |
|
73 |
symbol_c *current_action; |
|
74 |
||
75 |
sfcgeneration_t wanted_sfcgeneration; |
|
76 |
||
77 |
public: |
|
78 |
generate_cc_sfc_elements_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
|
19 | 79 |
: generate_cc_base_c(s4o_ptr) { |
52 | 80 |
generate_cc_il = new generate_cc_il_c(s4o_ptr, scope, variable_prefix); |
81 |
generate_cc_st = new generate_cc_st_c(s4o_ptr, scope, variable_prefix); |
|
82 |
generate_cc_code = new generate_cc_SFC_IL_ST_c(s4o_ptr, scope, variable_prefix); |
|
19 | 83 |
this->set_variable_prefix(variable_prefix); |
84 |
} |
|
85 |
||
52 | 86 |
~generate_cc_sfc_elements_c(void) { |
87 |
delete generate_cc_il; |
|
88 |
delete generate_cc_st; |
|
89 |
delete generate_cc_code; |
|
90 |
} |
|
91 |
||
19 | 92 |
void reset_transition_number(void) {transition_number = 0;} |
52 | 93 |
|
94 |
void generate(symbol_c *symbol, sfcgeneration_t generation_type) { |
|
95 |
wanted_sfcgeneration = generation_type; |
|
96 |
switch (wanted_sfcgeneration) { |
|
97 |
case transitiontest_sg: |
|
98 |
{ |
|
99 |
std::list<TRANSITION>::iterator pt; |
|
100 |
for(pt = transition_list.begin(); pt != transition_list.end(); pt++) { |
|
101 |
transition_number = pt->index; |
|
102 |
pt->symbol->accept(*this); |
|
103 |
} |
|
104 |
} |
|
105 |
break; |
|
106 |
default: |
|
107 |
symbol->accept(*this); |
|
108 |
break; |
|
109 |
} |
|
110 |
} |
|
111 |
||
19 | 112 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
113 |
print_variable_prefix(); |
|
114 |
s4o.print("step_list["); |
|
115 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
|
116 |
step_name->accept(*this); |
|
117 |
s4o.print("]."); |
|
118 |
s4o.print(argument); |
|
119 |
} |
|
120 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
121 |
void print_action_argument(symbol_c *action_name, const char* argument) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
122 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
123 |
s4o.print("action_list["); |
18 | 124 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
125 |
action_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
126 |
s4o.print("]."); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
127 |
s4o.print(argument); |
52 | 128 |
} |
129 |
||
130 |
void print_transition_number(void) { |
|
131 |
char str[10]; |
|
132 |
sprintf(str, "%d", transition_number); |
|
133 |
s4o.print(str); |
|
134 |
} |
|
135 |
||
136 |
void print_reset_step(symbol_c *step_name) { |
|
137 |
s4o.print(s4o.indent_spaces); |
|
138 |
print_step_argument(step_name, "state"); |
|
139 |
s4o.print(" = 0;\n"); |
|
140 |
} |
|
141 |
||
142 |
void print_set_step(symbol_c *step_name) { |
|
143 |
s4o.print(s4o.indent_spaces); |
|
144 |
print_step_argument(step_name, "state"); |
|
145 |
s4o.print(" = 1;\n" + s4o.indent_spaces); |
|
146 |
print_step_argument(step_name, "elapsed_time"); |
|
147 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
148 |
} |
|
149 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
150 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
151 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
152 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
153 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
154 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
155 |
void *visit(initial_step_c *symbol) { |
52 | 156 |
switch (wanted_sfcgeneration) { |
157 |
case actionassociation_sg: |
|
158 |
if (((list_c*)symbol->action_association_list)->n > 0) { |
|
159 |
s4o.print(s4o.indent_spaces + "// "); |
|
160 |
symbol->step_name->accept(*this); |
|
161 |
s4o.print(" action associations\n"); |
|
162 |
current_step = symbol->step_name; |
|
163 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
164 |
s4o.indent_right(); |
|
165 |
s4o.print(s4o.indent_spaces + "char activated = "); |
|
166 |
print_step_argument(current_step, "state"); |
|
167 |
s4o.print(" && !"); |
|
168 |
print_step_argument(current_step, "prev_state"); |
|
169 |
s4o.print(";\n"); |
|
170 |
s4o.print(s4o.indent_spaces + "char desactivated = !"); |
|
171 |
print_step_argument(current_step, "state"); |
|
172 |
s4o.print(" && "); |
|
173 |
print_step_argument(current_step, "prev_state"); |
|
174 |
s4o.print(";\n"); |
|
175 |
s4o.print(s4o.indent_spaces + "char active = "); |
|
176 |
print_step_argument(current_step, "state"); |
|
177 |
s4o.print(";\n"); |
|
178 |
symbol->action_association_list->accept(*this); |
|
179 |
s4o.indent_left(); |
|
180 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
181 |
} |
|
182 |
break; |
|
183 |
default: |
|
184 |
break; |
|
18 | 185 |
} |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
186 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
187 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
188 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
189 |
void *visit(step_c *symbol) { |
52 | 190 |
switch (wanted_sfcgeneration) { |
191 |
case actionassociation_sg: |
|
192 |
if (((list_c*)symbol->action_association_list)->n > 0) { |
|
193 |
s4o.print(s4o.indent_spaces + "// "); |
|
194 |
symbol->step_name->accept(*this); |
|
195 |
s4o.print(" action associations\n"); |
|
196 |
current_step = symbol->step_name; |
|
197 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
198 |
s4o.indent_right(); |
|
199 |
s4o.print(s4o.indent_spaces + "char activated = "); |
|
200 |
print_step_argument(current_step, "state"); |
|
201 |
s4o.print(" && !"); |
|
202 |
print_step_argument(current_step, "prev_state"); |
|
203 |
s4o.print(";\n"); |
|
204 |
s4o.print(s4o.indent_spaces + "char desactivated = !"); |
|
205 |
print_step_argument(current_step, "state"); |
|
206 |
s4o.print(" && "); |
|
207 |
print_step_argument(current_step, "prev_state"); |
|
208 |
s4o.print(";\n"); |
|
209 |
s4o.print(s4o.indent_spaces + "char active = "); |
|
210 |
print_step_argument(current_step, "state"); |
|
211 |
s4o.print(";\n"); |
|
212 |
symbol->action_association_list->accept(*this); |
|
213 |
s4o.indent_left(); |
|
214 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
215 |
} |
|
216 |
break; |
|
217 |
default: |
|
218 |
break; |
|
219 |
} |
|
220 |
return NULL; |
|
221 |
} |
|
222 |
||
223 |
void *visit(transition_c *symbol) { |
|
224 |
switch (wanted_sfcgeneration) { |
|
225 |
case transitionlist_sg: |
|
226 |
{ |
|
227 |
TRANSITION *transition; |
|
228 |
transition = new TRANSITION; |
|
229 |
transition->symbol = symbol; |
|
230 |
transition->index = transition_number; |
|
231 |
if (symbol->integer != NULL) { |
|
232 |
transition->priority = atoi(((token_c *)symbol->integer)->value); |
|
233 |
std::list<TRANSITION>::iterator pt = transition_list.begin(); |
|
234 |
while (pt != transition_list.end() && pt->priority > transition->priority) { |
|
235 |
pt++; |
|
236 |
} |
|
237 |
transition_list.insert(pt, *transition); |
|
238 |
} |
|
239 |
else { |
|
240 |
transition->priority = 0; |
|
241 |
transition_list.push_back(*transition); |
|
242 |
} |
|
243 |
transition_number++; |
|
244 |
} |
|
245 |
break; |
|
246 |
case transitiontest_sg: |
|
247 |
s4o.print(s4o.indent_spaces + "if ("); |
|
248 |
symbol->from_steps->accept(*this); |
|
249 |
s4o.print(") {\n"); |
|
250 |
s4o.indent_right(); |
|
251 |
||
252 |
// Calculate transition value |
|
253 |
if (symbol->transition_condition_il != NULL) { |
|
254 |
generate_cc_il->declare_backup_variable(); |
|
255 |
s4o.print(s4o.indent_spaces); |
|
256 |
symbol->transition_condition_il->accept(*generate_cc_il); |
|
257 |
print_variable_prefix(); |
|
258 |
s4o.print("transition_list["); |
|
259 |
print_transition_number(); |
|
260 |
s4o.print("] = "); |
|
261 |
generate_cc_il->print_backup_variable(); |
|
262 |
s4o.print(";\n"); |
|
263 |
} |
|
264 |
if (symbol->transition_condition_st != NULL) { |
|
265 |
s4o.print(s4o.indent_spaces); |
|
266 |
print_variable_prefix(); |
|
267 |
s4o.print("transition_list["); |
|
268 |
print_transition_number(); |
|
269 |
s4o.print("] = "); |
|
270 |
symbol->transition_condition_st->accept(*generate_cc_st); |
|
271 |
s4o.print(";\n"); |
|
272 |
} |
|
273 |
if (symbol->integer != NULL) { |
|
274 |
s4o.print(s4o.indent_spaces + "if ("); |
|
275 |
print_variable_prefix(); |
|
276 |
s4o.print("transition_list["); |
|
277 |
print_transition_number(); |
|
278 |
s4o.print("]) {\n"); |
|
279 |
s4o.indent_right(); |
|
280 |
wanted_sfcgeneration = stepreset_sg; |
|
281 |
symbol->from_steps->accept(*this); |
|
282 |
wanted_sfcgeneration = transitiontest_sg; |
|
283 |
s4o.indent_left(); |
|
284 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
285 |
} |
|
286 |
s4o.indent_left(); |
|
287 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n"); |
|
288 |
s4o.indent_right(); |
|
289 |
s4o.print(s4o.indent_spaces); |
|
290 |
print_variable_prefix(); |
|
291 |
s4o.print("transition_list["); |
|
292 |
print_transition_number(); |
|
293 |
s4o.print("] = 0;\n"); |
|
294 |
s4o.indent_left(); |
|
295 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
296 |
break; |
|
297 |
case stepset_sg: |
|
298 |
s4o.print(s4o.indent_spaces + "if ("); |
|
299 |
print_variable_prefix(); |
|
300 |
s4o.print("transition_list["); |
|
301 |
print_transition_number(); |
|
302 |
s4o.print("]) {\n"); |
|
303 |
s4o.indent_right(); |
|
304 |
symbol->to_steps->accept(*this); |
|
305 |
s4o.indent_left(); |
|
306 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
307 |
transition_number++; |
|
308 |
break; |
|
309 |
case stepreset_sg: |
|
310 |
if (symbol->integer == NULL) { |
|
311 |
s4o.print(s4o.indent_spaces + "if ("); |
|
312 |
print_variable_prefix(); |
|
313 |
s4o.print("transition_list["); |
|
314 |
print_transition_number(); |
|
315 |
s4o.print("]) {\n"); |
|
316 |
s4o.indent_right(); |
|
317 |
symbol->from_steps->accept(*this); |
|
318 |
s4o.indent_left(); |
|
319 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
320 |
} |
|
321 |
transition_number++; |
|
322 |
break; |
|
323 |
default: |
|
324 |
break; |
|
325 |
} |
|
326 |
return NULL; |
|
327 |
} |
|
328 |
||
329 |
void *visit(action_c *symbol) { |
|
330 |
switch (wanted_sfcgeneration) { |
|
331 |
case actionbody_sg: |
|
332 |
s4o.print(s4o.indent_spaces + "if("); |
|
333 |
print_variable_prefix(); |
|
334 |
s4o.print("action_list["); |
|
335 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
|
336 |
symbol->action_name->accept(*this); |
|
337 |
s4o.print("].state) {"); |
|
338 |
s4o.indent_right(); |
|
339 |
||
340 |
// generate action code |
|
341 |
symbol->function_block_body->accept(*generate_cc_code); |
|
342 |
||
343 |
s4o.indent_left(); |
|
344 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
345 |
break; |
|
346 |
default: |
|
347 |
break; |
|
348 |
} |
|
349 |
return NULL; |
|
350 |
} |
|
351 |
||
352 |
void *visit(steps_c *symbol) { |
|
353 |
if (symbol->step_name != NULL) { |
|
354 |
switch (wanted_sfcgeneration) { |
|
355 |
case transitiontest_sg: |
|
356 |
print_step_argument(symbol->step_name, "state"); |
|
357 |
break; |
|
358 |
case stepset_sg: |
|
359 |
print_set_step(symbol->step_name); |
|
360 |
break; |
|
361 |
case stepreset_sg: |
|
362 |
print_reset_step(symbol->step_name); |
|
363 |
break; |
|
364 |
default: |
|
365 |
break; |
|
366 |
} |
|
367 |
} |
|
368 |
else if (symbol->step_name_list != NULL) { |
|
369 |
symbol->step_name_list->accept(*this); |
|
370 |
} |
|
371 |
return NULL; |
|
372 |
} |
|
373 |
||
374 |
void *visit(step_name_list_c *symbol) { |
|
375 |
switch (wanted_sfcgeneration) { |
|
376 |
case transitiontest_sg: |
|
377 |
for(int i = 0; i < symbol->n; i++) { |
|
378 |
print_step_argument(symbol->elements[i], "state"); |
|
379 |
if (i < symbol->n - 1) { |
|
380 |
s4o.print(" && "); |
|
381 |
} |
|
382 |
} |
|
383 |
break; |
|
384 |
case stepset_sg: |
|
385 |
for(int i = 0; i < symbol->n; i++) { |
|
386 |
print_set_step(symbol->elements[i]); |
|
387 |
} |
|
388 |
break; |
|
389 |
case stepreset_sg: |
|
390 |
for(int i = 0; i < symbol->n; i++) { |
|
391 |
print_reset_step(symbol->elements[i]); |
|
392 |
} |
|
393 |
break; |
|
394 |
default: |
|
395 |
break; |
|
396 |
} |
|
397 |
return NULL; |
|
398 |
} |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
399 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
400 |
void *visit(action_association_list_c* symbol) { |
52 | 401 |
switch (wanted_sfcgeneration) { |
402 |
case actionassociation_sg: |
|
403 |
print_list(symbol, "", "\n", "\n"); |
|
404 |
break; |
|
405 |
default: |
|
406 |
break; |
|
407 |
} |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
408 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
409 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
410 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
411 |
void *visit(action_association_c *symbol) { |
52 | 412 |
switch (wanted_sfcgeneration) { |
413 |
case actionassociation_sg: |
|
414 |
if (symbol->action_qualifier != NULL) { |
|
415 |
current_action = symbol->action_name; |
|
416 |
symbol->action_qualifier->accept(*this); |
|
417 |
} |
|
418 |
else { |
|
419 |
s4o.print(s4o.indent_spaces + "if ("); |
|
420 |
print_step_argument(current_step, "state"); |
|
421 |
s4o.print(") {\n"); |
|
422 |
s4o.indent_right(); |
|
423 |
s4o.print(s4o.indent_spaces); |
|
424 |
print_action_argument(symbol->action_name, "state"); |
|
425 |
s4o.print(" = 1;\n"); |
|
426 |
s4o.indent_left(); |
|
427 |
s4o.print(s4o.indent_spaces + "}"); |
|
428 |
} |
|
429 |
break; |
|
430 |
default: |
|
431 |
break; |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
432 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
433 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
434 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
435 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
436 |
void *visit(action_qualifier_c *symbol) { |
52 | 437 |
switch (wanted_sfcgeneration) { |
438 |
case actionassociation_sg: |
|
439 |
{ |
|
440 |
char *qualifier = (char *)symbol->action_qualifier->accept(*this); |
|
441 |
s4o.print(s4o.indent_spaces + "if ("); |
|
442 |
if (strcmp(qualifier, "N") == 0) { |
|
443 |
s4o.print("active"); |
|
444 |
} |
|
445 |
if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || |
|
446 |
strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0 || |
|
447 |
strcmp(qualifier, "S") == 0 || strcmp(qualifier, "R") == 0) { |
|
448 |
s4o.print("activated"); |
|
449 |
} |
|
450 |
if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
|
451 |
s4o.print("active && "); |
|
452 |
print_step_argument(current_step, "elapsed_time"); |
|
453 |
if (strcmp(qualifier, "D") == 0) { |
|
454 |
s4o.print(" >= "); |
|
455 |
} |
|
456 |
else { |
|
457 |
s4o.print(" < "); |
|
458 |
} |
|
459 |
symbol->action_time->accept(*this); |
|
460 |
} |
|
461 |
s4o.print(") {\n"); |
|
462 |
s4o.indent_right(); |
|
463 |
s4o.print(s4o.indent_spaces); |
|
464 |
if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || |
|
465 |
strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
|
466 |
print_action_argument(current_action, "state"); |
|
467 |
s4o.print(" = 1;\n"); |
|
468 |
} |
|
469 |
if (strcmp(qualifier, "S") == 0) { |
|
470 |
print_action_argument(current_action, "set"); |
|
471 |
s4o.print(" = 1;\n"); |
|
472 |
} |
|
473 |
if (strcmp(qualifier, "R") == 0) { |
|
474 |
print_action_argument(current_action, "reset"); |
|
475 |
s4o.print(" = 1;\n"); |
|
476 |
} |
|
477 |
if (strcmp(qualifier, "SD") == 0 || strcmp(qualifier, "DS") == 0 || |
|
478 |
strcmp(qualifier, "SL") == 0) { |
|
479 |
if (strcmp(qualifier, "SL") == 0) { |
|
480 |
print_action_argument(current_action, "reset_remaining_time"); |
|
481 |
} |
|
482 |
else { |
|
483 |
print_action_argument(current_action, "set_remaining_time"); |
|
484 |
} |
|
485 |
s4o.print(" = "); |
|
486 |
symbol->action_time->accept(*this); |
|
487 |
s4o.print(";\n"); |
|
488 |
} |
|
489 |
s4o.indent_left(); |
|
490 |
s4o.print(s4o.indent_spaces + "}"); |
|
491 |
if (strcmp(qualifier, "DS") == 0) { |
|
492 |
s4o.print("desactivated"); |
|
493 |
s4o.indent_right(); |
|
494 |
s4o.print(s4o.indent_spaces); |
|
495 |
print_action_argument(current_action, "set_remaining_time"); |
|
496 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
497 |
} |
|
498 |
} |
|
499 |
break; |
|
500 |
default: |
|
501 |
break; |
|
17
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 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
504 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
505 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
506 |
void *visit(qualifier_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
507 |
return (void *)symbol->value; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
508 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
509 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
510 |
void *visit(timed_qualifier_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
511 |
return (void *)symbol->value; |
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 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
514 |
}; /* generate_cc_sfc_actiondecl_c */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
515 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
516 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
517 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
518 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
519 |
/***********************************************************************/ |
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 |
class generate_cc_sfc_c: public generate_cc_typedecl_c { |
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 |
private: |
52 | 526 |
generate_cc_sfc_elements_c *generate_cc_sfc_elements; |
527 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
528 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
529 |
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
|
530 |
: generate_cc_typedecl_c(s4o_ptr) { |
52 | 531 |
generate_cc_sfc_elements = new generate_cc_sfc_elements_c(s4o_ptr, scope, variable_prefix); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
532 |
this->set_variable_prefix(variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
533 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
534 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
535 |
virtual ~generate_cc_sfc_c(void) { |
52 | 536 |
delete generate_cc_sfc_elements; |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
537 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
538 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
539 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
540 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
541 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
542 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
543 |
void *visit(sfc_network_c *symbol) { |
52 | 544 |
generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::transitionlist_sg); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
545 |
s4o.print(s4o.indent_spaces +"INT i;\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
546 |
s4o.print(s4o.indent_spaces +"BOOL transition;\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
547 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
548 |
/* generate step initilizations */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
549 |
s4o.print(s4o.indent_spaces + "// Steps initialisation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
550 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
551 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
552 |
s4o.print("nb_steps; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
553 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
554 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
555 |
print_variable_prefix(); |
18 | 556 |
s4o.print("step_list[i].prev_state = "); |
557 |
print_variable_prefix(); |
|
558 |
s4o.print("step_list[i].state;\n"); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
559 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
560 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
561 |
s4o.print("step_list[i].state) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
562 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
563 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
564 |
print_variable_prefix(); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
565 |
s4o.print("step_list[i].elapsed_time = __time_add("); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
566 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
567 |
s4o.print("step_list[i].elapsed_time, PERIOD);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
568 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
569 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
570 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
571 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
572 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
573 |
/* generate action initilizations */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
574 |
s4o.print(s4o.indent_spaces + "// Actions initialisation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
575 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
576 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
577 |
s4o.print("nb_actions; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
578 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
579 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
580 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
581 |
s4o.print("action_list[i].state = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
582 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
583 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
584 |
s4o.print("action_list[i].set = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
585 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
586 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
587 |
s4o.print("action_list[i].reset = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
588 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
589 |
print_variable_prefix(); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
590 |
s4o.print("__gt_TIME(action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
591 |
s4o.indent_right(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
592 |
s4o.print(s4o.indent_spaces); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
593 |
print_variable_prefix(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
594 |
s4o.print("action_list[i].set_remaining_time = __time_sub("); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
595 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
596 |
s4o.print("action_list[i].set_remaining_time, PERIOD);\n"); |
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_variable_prefix(); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
599 |
s4o.print("__le_TIME(action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
17
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_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
603 |
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
|
604 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
605 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
606 |
s4o.print("action_list[i].set = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
607 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
608 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
609 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
610 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
611 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
612 |
print_variable_prefix(); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
613 |
s4o.print("__gt_TIME(action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
614 |
s4o.indent_right(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
615 |
s4o.print(s4o.indent_spaces); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
616 |
print_variable_prefix(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
617 |
s4o.print("action_list[i].reset_remaining_time = __time_sub("); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
618 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
619 |
s4o.print("action_list[i].reset_remaining_time, PERIOD);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
620 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
621 |
print_variable_prefix(); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
22
diff
changeset
|
622 |
s4o.print("__le_TIME(action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
623 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
624 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
625 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
626 |
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
|
627 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
628 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
629 |
s4o.print("action_list[i].reset = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
630 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
631 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
632 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
633 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
634 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
635 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
636 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
637 |
/* generate transition tests */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
638 |
s4o.print(s4o.indent_spaces + "// Transitions fire test\n"); |
52 | 639 |
generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::transitiontest_sg); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
640 |
s4o.print("\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
641 |
|
18 | 642 |
/* generate transition reset steps */ |
643 |
s4o.print(s4o.indent_spaces + "// Transitions reset steps\n"); |
|
53 | 644 |
generate_cc_sfc_elements->reset_transition_number(); |
52 | 645 |
generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::stepreset_sg); |
18 | 646 |
s4o.print("\n"); |
647 |
||
648 |
/* generate transition set steps */ |
|
649 |
s4o.print(s4o.indent_spaces + "// Transitions set steps\n"); |
|
53 | 650 |
generate_cc_sfc_elements->reset_transition_number(); |
52 | 651 |
generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::stepset_sg); |
18 | 652 |
s4o.print("\n"); |
653 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
654 |
/* generate step association */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
655 |
s4o.print(s4o.indent_spaces + "// Steps association\n"); |
52 | 656 |
generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::actionassociation_sg); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
657 |
s4o.print("\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
658 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
659 |
/* generate action state evaluation */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
660 |
s4o.print(s4o.indent_spaces + "// Actions state evaluation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
661 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
662 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
663 |
s4o.print("nb_actions; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
664 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
665 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
666 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
667 |
s4o.print("action_list[i].set) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
668 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
669 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
670 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
671 |
s4o.print("action_list[i].stored = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
672 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
673 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
674 |
print_variable_prefix(); |
52 | 675 |
s4o.print("action_list[i].reset) {\n"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
676 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
677 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
678 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
679 |
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
|
680 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
681 |
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
|
682 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
683 |
s4o.print("action_list[i].stored = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
684 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
685 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
686 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
687 |
s4o.print("action_list[i].state |= "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
688 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
689 |
s4o.print("action_list[i].stored;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
690 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
691 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
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 |
/* generate action execution */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
694 |
s4o.print(s4o.indent_spaces + "// Actions execution\n"); |
52 | 695 |
generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::actionbody_sg); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
696 |
s4o.print("\n"); |
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 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
699 |
} |
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 |
void generate(sequential_function_chart_c *sfc) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
702 |
sfc->accept(*this); |
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 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
705 |
}; /* generate_cc_sfc_c */ |