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