author | lbessard |
Tue, 27 Feb 2007 17:24:10 +0100 | |
changeset 18 | e6af5eb5f546 |
parent 17 | 38754701ac41 |
child 19 | cee3c4e5afe2 |
permissions | -rw-r--r-- |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
1 |
/* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
2 |
* (c) 2007 Mario de Sousa, Laurent Bessard |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
3 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
4 |
* Offered to the public under the terms of the GNU General Public License |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
6 |
* License, or (at your option) any later version. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
7 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
8 |
* This program is distributed in the hope that it will be useful, but |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
11 |
* Public License for more details. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
12 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
13 |
* This code is made available on the understanding that it will not be |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
14 |
* used in safety-critical situations without a full and competent review. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
15 |
*/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
16 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
17 |
/* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
18 |
* An IEC 61131-3 IL and ST compiler. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
19 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
20 |
* Based on the |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
22 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
23 |
*/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
24 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
25 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
26 |
/* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
27 |
* Conversion of sfc networks (i.e. SFC code). |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
28 |
* |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
29 |
* This is part of the 4th stage that generates |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
30 |
* a c++ source program equivalent to the SFC, IL and ST |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
31 |
* code. |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
32 |
*/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
33 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
34 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
35 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
36 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
37 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
38 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
39 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
40 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
41 |
class generate_cc_sfc_transitiontest_c: public generate_cc_base_c { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
42 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
43 |
private: |
18 | 44 |
char transition_number; |
45 |
||
46 |
private: |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
47 |
generate_cc_il_c *generate_cc_il; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
48 |
generate_cc_st_c *generate_cc_st; |
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 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
51 |
generate_cc_sfc_transitiontest_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
52 |
: generate_cc_base_c(s4o_ptr) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
53 |
generate_cc_il = new generate_cc_il_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
54 |
generate_cc_st = new generate_cc_st_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
55 |
this->set_variable_prefix(variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
56 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
57 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
58 |
~generate_cc_sfc_transitiontest_c(void) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
59 |
delete generate_cc_il; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
60 |
delete generate_cc_st; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
61 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
62 |
|
18 | 63 |
void reset_transition_number(void) {transition_number = 0;} |
64 |
void print_transition_number(void) { |
|
65 |
char str[10]; |
|
66 |
sprintf(str, "%d", transition_number); |
|
67 |
s4o.print(str); |
|
68 |
} |
|
69 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
70 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
71 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
72 |
s4o.print("step_list["); |
18 | 73 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
74 |
step_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
75 |
s4o.print("]."); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
76 |
s4o.print(argument); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
77 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
78 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
79 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
80 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
81 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
82 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
83 |
void *visit(initial_step_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
84 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
85 |
void *visit(step_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
86 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
87 |
void *visit(transition_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
88 |
s4o.print(s4o.indent_spaces + "if ("); |
18 | 89 |
symbol->from_steps->accept(*this); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
90 |
s4o.print(") {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
91 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
92 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
93 |
// Calculate transition value |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
94 |
if (symbol->transition_condition_il != NULL) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
95 |
generate_cc_il->declare_backup_variable(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
96 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
97 |
symbol->transition_condition_il->accept(*generate_cc_il); |
18 | 98 |
print_variable_prefix(); |
99 |
s4o.print("transition_list["); |
|
100 |
print_transition_number(); |
|
101 |
s4o.print("] = "); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
102 |
generate_cc_il->print_backup_variable(); |
18 | 103 |
s4o.print(";\n"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
104 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
105 |
if (symbol->transition_condition_st != NULL) { |
18 | 106 |
print_variable_prefix(); |
107 |
s4o.print("transition_list["); |
|
108 |
print_transition_number(); |
|
109 |
s4o.print("] = "); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
110 |
symbol->transition_condition_st->accept(*generate_cc_st); |
18 | 111 |
s4o.print(";\n"); |
112 |
} |
|
113 |
s4o.indent_left(); |
|
114 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n"); |
|
115 |
s4o.indent_right(); |
|
116 |
s4o.print(s4o.indent_spaces); |
|
117 |
print_variable_prefix(); |
|
118 |
s4o.print("transition_list["); |
|
119 |
print_transition_number(); |
|
120 |
s4o.print("] = 0;\n"); |
|
121 |
s4o.indent_left(); |
|
122 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
123 |
||
124 |
transition_number++; |
|
125 |
return NULL; |
|
126 |
} |
|
127 |
||
128 |
void *visit(steps_c *symbol) { |
|
129 |
if (symbol->step_name != NULL) { |
|
130 |
print_step_argument(symbol->step_name, "state"); |
|
131 |
} |
|
132 |
if (symbol->step_name_list != NULL) { |
|
133 |
symbol->step_name_list->accept(*this); |
|
134 |
} |
|
135 |
return NULL; |
|
136 |
} |
|
137 |
||
138 |
void *visit(step_name_list_c *symbol) { |
|
139 |
for(int i = 0; i < symbol->n; i++) { |
|
140 |
print_step_argument(symbol->elements[i], "state"); |
|
141 |
if (i < symbol->n - 1) { |
|
142 |
s4o.print(" && "); |
|
143 |
} |
|
144 |
} |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
145 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
146 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
147 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
148 |
void *visit(action_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
149 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
150 |
}; /* generate_cc_sfc_transitiontest_c */ |
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 |
|
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 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
156 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
157 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
158 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
159 |
|
18 | 160 |
class generate_cc_sfc_transitionresetsteps_c: public generate_cc_base_c { |
161 |
||
162 |
private: |
|
163 |
char transition_number; |
|
164 |
||
165 |
public: |
|
166 |
generate_cc_sfc_transitionresetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
|
167 |
: generate_cc_base_c(s4o_ptr) { |
|
168 |
this->set_variable_prefix(variable_prefix); |
|
169 |
} |
|
170 |
||
171 |
void reset_transition_number(void) {transition_number = 0;} |
|
172 |
void print_transition_number(void) { |
|
173 |
char str[10]; |
|
174 |
sprintf(str, "%d", transition_number); |
|
175 |
s4o.print(str); |
|
176 |
} |
|
177 |
||
178 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
|
179 |
print_variable_prefix(); |
|
180 |
s4o.print("step_list["); |
|
181 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
|
182 |
step_name->accept(*this); |
|
183 |
s4o.print("]."); |
|
184 |
s4o.print(argument); |
|
185 |
} |
|
186 |
||
187 |
void print_reset_step(symbol_c *step_name) { |
|
188 |
s4o.print(s4o.indent_spaces); |
|
189 |
print_step_argument(step_name, "state"); |
|
190 |
s4o.print(" = 0;\n" + s4o.indent_spaces); |
|
191 |
print_step_argument(step_name, "elapsed_time"); |
|
192 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
193 |
} |
|
194 |
||
195 |
/*********************************************/ |
|
196 |
/* B.1.6 Sequential function chart elements */ |
|
197 |
/*********************************************/ |
|
198 |
||
199 |
void *visit(initial_step_c *symbol) {return NULL;} |
|
200 |
||
201 |
void *visit(step_c *symbol) {return NULL;} |
|
202 |
||
203 |
void *visit(transition_c *symbol) { |
|
204 |
s4o.print(s4o.indent_spaces + "if ("); |
|
205 |
print_variable_prefix(); |
|
206 |
s4o.print("transition_list["); |
|
207 |
print_transition_number(); |
|
208 |
s4o.print("]) {\n"); |
|
209 |
s4o.indent_right(); |
|
210 |
symbol->from_steps->accept(*this); |
|
211 |
s4o.indent_left(); |
|
212 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
213 |
transition_number++; |
|
214 |
return NULL; |
|
215 |
} |
|
216 |
||
217 |
void *visit(steps_c *symbol) { |
|
218 |
if (symbol->step_name != NULL) { |
|
219 |
print_reset_step(symbol->step_name); |
|
220 |
} |
|
221 |
if (symbol->step_name_list != NULL) { |
|
222 |
symbol->step_name_list->accept(*this); |
|
223 |
} |
|
224 |
return NULL; |
|
225 |
} |
|
226 |
||
227 |
void *visit(step_name_list_c *symbol) { |
|
228 |
for(int i = 0; i < symbol->n; i++) { |
|
229 |
print_reset_step(symbol->elements[i]); |
|
230 |
} |
|
231 |
return NULL; |
|
232 |
} |
|
233 |
||
234 |
void *visit(action_c *symbol) {return NULL;} |
|
235 |
||
236 |
}; /* generate_cc_sfc_transitionresetsteps_c */ |
|
237 |
||
238 |
||
239 |
||
240 |
||
241 |
/***********************************************************************/ |
|
242 |
/***********************************************************************/ |
|
243 |
/***********************************************************************/ |
|
244 |
/***********************************************************************/ |
|
245 |
||
246 |
class generate_cc_sfc_transitionsetsteps_c: public generate_cc_base_c { |
|
247 |
||
248 |
private: |
|
249 |
char transition_number; |
|
250 |
||
251 |
public: |
|
252 |
generate_cc_sfc_transitionsetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
|
253 |
: generate_cc_base_c(s4o_ptr) { |
|
254 |
this->set_variable_prefix(variable_prefix); |
|
255 |
} |
|
256 |
||
257 |
void reset_transition_number(void) {transition_number = 0;} |
|
258 |
void print_transition_number(void) { |
|
259 |
char str[10]; |
|
260 |
sprintf(str, "%d", transition_number); |
|
261 |
s4o.print(str); |
|
262 |
} |
|
263 |
||
264 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
|
265 |
print_variable_prefix(); |
|
266 |
s4o.print("step_list["); |
|
267 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
|
268 |
step_name->accept(*this); |
|
269 |
s4o.print("]."); |
|
270 |
s4o.print(argument); |
|
271 |
} |
|
272 |
||
273 |
void print_set_step(symbol_c *step_name) { |
|
274 |
s4o.print(s4o.indent_spaces); |
|
275 |
print_step_argument(step_name, "state"); |
|
276 |
s4o.print(" = 1;\n"); |
|
277 |
} |
|
278 |
||
279 |
/*********************************************/ |
|
280 |
/* B.1.6 Sequential function chart elements */ |
|
281 |
/*********************************************/ |
|
282 |
||
283 |
void *visit(initial_step_c *symbol) {return NULL;} |
|
284 |
||
285 |
void *visit(step_c *symbol) {return NULL;} |
|
286 |
||
287 |
void *visit(transition_c *symbol) { |
|
288 |
s4o.print(s4o.indent_spaces + "if ("); |
|
289 |
print_variable_prefix(); |
|
290 |
s4o.print("transition_list["); |
|
291 |
print_transition_number(); |
|
292 |
s4o.print("]) {\n"); |
|
293 |
s4o.indent_right(); |
|
294 |
symbol->to_steps->accept(*this); |
|
295 |
s4o.indent_left(); |
|
296 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
297 |
transition_number++; |
|
298 |
return NULL; |
|
299 |
} |
|
300 |
||
301 |
void *visit(steps_c *symbol) { |
|
302 |
if (symbol->step_name != NULL) { |
|
303 |
print_set_step(symbol->step_name); |
|
304 |
} |
|
305 |
if (symbol->step_name_list != NULL) { |
|
306 |
symbol->step_name_list->accept(*this); |
|
307 |
} |
|
308 |
return NULL; |
|
309 |
} |
|
310 |
||
311 |
void *visit(step_name_list_c *symbol) { |
|
312 |
for(int i = 0; i < symbol->n; i++) { |
|
313 |
print_set_step(symbol->elements[i]); |
|
314 |
} |
|
315 |
return NULL; |
|
316 |
} |
|
317 |
||
318 |
void *visit(action_c *symbol) {return NULL;} |
|
319 |
||
320 |
}; /* generate_cc_sfc_transitionsetsteps_c */ |
|
321 |
||
322 |
||
323 |
||
324 |
||
325 |
/***********************************************************************/ |
|
326 |
/***********************************************************************/ |
|
327 |
/***********************************************************************/ |
|
328 |
/***********************************************************************/ |
|
329 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
330 |
class generate_cc_sfc_stepassociation_c: public generate_cc_base_c { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
331 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
332 |
private: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
333 |
symbol_c *current_step; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
334 |
symbol_c *current_action; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
335 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
336 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
337 |
generate_cc_sfc_stepassociation_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
338 |
: generate_cc_base_c(s4o_ptr) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
339 |
this->set_variable_prefix(variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
340 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
341 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
342 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
343 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
344 |
s4o.print("step_list["); |
18 | 345 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
346 |
step_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
347 |
s4o.print("]."); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
348 |
s4o.print(argument); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
349 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
350 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
351 |
void print_action_argument(symbol_c *action_name, const char* argument) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
352 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
353 |
s4o.print("action_list["); |
18 | 354 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
355 |
action_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
356 |
s4o.print("]."); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
357 |
s4o.print(argument); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
358 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
359 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
360 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
361 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
362 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
363 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
364 |
void *visit(initial_step_c *symbol) { |
18 | 365 |
if (((list_c*)symbol->action_association_list)->n > 0) { |
366 |
s4o.print(s4o.indent_spaces + "// "); |
|
367 |
symbol->step_name->accept(*this); |
|
368 |
s4o.print(" action associations\n"); |
|
369 |
current_step = symbol->step_name; |
|
370 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
371 |
s4o.indent_right(); |
|
372 |
s4o.print(s4o.indent_spaces + "char activated = "); |
|
373 |
print_step_argument(current_step, "state"); |
|
374 |
s4o.print(" && !"); |
|
375 |
print_step_argument(current_step, "prev_state"); |
|
376 |
s4o.print(";\n"); |
|
377 |
s4o.print(s4o.indent_spaces + "char desactivated = !"); |
|
378 |
print_step_argument(current_step, "state"); |
|
379 |
s4o.print(" && "); |
|
380 |
print_step_argument(current_step, "prev_state"); |
|
381 |
s4o.print(";\n"); |
|
382 |
s4o.print(s4o.indent_spaces + "char active = "); |
|
383 |
print_step_argument(current_step, "state"); |
|
384 |
s4o.print(";\n"); |
|
385 |
symbol->action_association_list->accept(*this); |
|
386 |
s4o.indent_left(); |
|
387 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
388 |
} |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
389 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
390 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
391 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
392 |
void *visit(step_c *symbol) { |
18 | 393 |
if (((list_c*)symbol->action_association_list)->n > 0) { |
394 |
s4o.print(s4o.indent_spaces + "// "); |
|
395 |
symbol->step_name->accept(*this); |
|
396 |
s4o.print(" action associations\n"); |
|
397 |
current_step = symbol->step_name; |
|
398 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
399 |
s4o.indent_right(); |
|
400 |
s4o.print(s4o.indent_spaces + "char activated = "); |
|
401 |
print_step_argument(current_step, "state"); |
|
402 |
s4o.print(" && !"); |
|
403 |
print_step_argument(current_step, "prev_state"); |
|
404 |
s4o.print(";\n"); |
|
405 |
s4o.print(s4o.indent_spaces + "char desactivated = !"); |
|
406 |
print_step_argument(current_step, "state"); |
|
407 |
s4o.print(" && "); |
|
408 |
print_step_argument(current_step, "prev_state"); |
|
409 |
s4o.print(";\n"); |
|
410 |
s4o.print(s4o.indent_spaces + "char active = "); |
|
411 |
print_step_argument(current_step, "state"); |
|
412 |
s4o.print(";\n"); |
|
413 |
symbol->action_association_list->accept(*this); |
|
414 |
s4o.indent_left(); |
|
415 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
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(transition_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
421 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
422 |
void *visit(action_c *symbol) {return NULL;} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
423 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
424 |
void *visit(action_association_list_c* symbol) { |
18 | 425 |
print_list(symbol, "", "\n", "\n"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
426 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
427 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
428 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
429 |
void *visit(action_association_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
430 |
if (symbol->action_qualifier != NULL) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
431 |
current_action = symbol->action_name; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
432 |
symbol->action_qualifier->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
433 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
434 |
else { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
435 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
436 |
print_step_argument(current_step, "state"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
437 |
s4o.print(") {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
438 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
439 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
440 |
print_action_argument(symbol->action_name, "state"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
441 |
s4o.print(" = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
442 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
443 |
s4o.print(s4o.indent_spaces + "}"); |
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 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
446 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
447 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
448 |
void *visit(action_qualifier_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
449 |
char *qualifier = (char *)symbol->action_qualifier->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
450 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
451 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
452 |
if (strcmp(qualifier, "N") == 0) { |
18 | 453 |
s4o.print("active"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
454 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
455 |
if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
456 |
strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0) { |
18 | 457 |
s4o.print("activated"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
458 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
459 |
if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
18 | 460 |
s4o.print("active && "); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
461 |
print_step_argument(current_step, "elapsed_time"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
462 |
if (strcmp(qualifier, "D") == 0) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
463 |
s4o.print(" >= "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
464 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
465 |
else { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
466 |
s4o.print(" < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
467 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
468 |
symbol->action_time->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
469 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
470 |
s4o.print(") {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
471 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
472 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
473 |
if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
474 |
strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
475 |
print_action_argument(current_action, "state"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
476 |
s4o.print(" = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
477 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
478 |
if (strcmp(qualifier, "SD") == 0 || strcmp(qualifier, "DS") == 0 || |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
479 |
strcmp(qualifier, "SL") == 0) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
480 |
if (strcmp(qualifier, "SL") == 0) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
481 |
print_action_argument(current_action, "reset_remaining_time"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
482 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
483 |
else { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
484 |
print_action_argument(current_action, "set_remaining_time"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
485 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
486 |
s4o.print(" = "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
487 |
symbol->action_time->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
488 |
s4o.print(";\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
489 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
490 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
491 |
s4o.print(s4o.indent_spaces + "}"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
492 |
if (strcmp(qualifier, "DS") == 0) { |
18 | 493 |
s4o.print("desactivated"); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
494 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
495 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
496 |
print_action_argument(current_action, "set_remaining_time"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
497 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
498 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
499 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
500 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
501 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
502 |
void *visit(qualifier_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
503 |
return (void *)symbol->value; |
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(timed_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 |
}; /* generate_cc_sfc_actiondecl_c */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
511 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
512 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
513 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
514 |
|
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 |
class generate_cc_sfc_actionexecution_c: public generate_cc_base_c { |
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 |
private: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
523 |
generate_cc_SFC_IL_ST_c *generate_cc_code; |
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 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
526 |
generate_cc_sfc_actionexecution_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
527 |
: generate_cc_base_c(s4o_ptr) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
528 |
generate_cc_code = new generate_cc_SFC_IL_ST_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
529 |
this->set_variable_prefix(variable_prefix); |
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 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
532 |
~generate_cc_sfc_actionexecution_c(void) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
533 |
delete generate_cc_code; |
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 |
|
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 |
/* B.1.6 Sequential function chart elements */ |
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 |
void *visit(initial_step_c *symbol) {return NULL;} |
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 |
void *visit(step_c *symbol) {return NULL;} |
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 |
void *visit(transition_c *symbol) {return NULL;} |
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 |
void *visit(action_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
547 |
s4o.print(s4o.indent_spaces + "if("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
548 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
549 |
s4o.print("action_list["); |
18 | 550 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
551 |
symbol->action_name->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
552 |
s4o.print("].state) {"); |
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 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
555 |
// generate action code |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
556 |
symbol->function_block_body->accept(*generate_cc_code); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
557 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
558 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
559 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
560 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
561 |
} |
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 |
}; /* generate_cc_sfc_actiondecl_c */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
564 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
565 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
566 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
567 |
/***********************************************************************/ |
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 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
570 |
/***********************************************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
571 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
572 |
class generate_cc_sfc_c: public generate_cc_typedecl_c { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
573 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
574 |
private: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
575 |
generate_cc_sfc_transitiontest_c *generate_cc_sfc_transitiontest; |
18 | 576 |
generate_cc_sfc_transitionresetsteps_c *generate_cc_sfc_transitionresetsteps; |
577 |
generate_cc_sfc_transitionsetsteps_c *generate_cc_sfc_transitionsetsteps; |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
578 |
generate_cc_sfc_stepassociation_c *generate_cc_sfc_stepassociation; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
579 |
generate_cc_sfc_actionexecution_c *generate_cc_sfc_actionexecution; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
580 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
581 |
public: |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
582 |
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
|
583 |
: generate_cc_typedecl_c(s4o_ptr) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
584 |
generate_cc_sfc_transitiontest = new generate_cc_sfc_transitiontest_c(s4o_ptr, scope, variable_prefix); |
18 | 585 |
generate_cc_sfc_transitionresetsteps = new generate_cc_sfc_transitionresetsteps_c(s4o_ptr, scope, variable_prefix); |
586 |
generate_cc_sfc_transitionsetsteps = new generate_cc_sfc_transitionsetsteps_c(s4o_ptr, scope, variable_prefix); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
587 |
generate_cc_sfc_stepassociation = new generate_cc_sfc_stepassociation_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
588 |
generate_cc_sfc_actionexecution = new generate_cc_sfc_actionexecution_c(s4o_ptr, scope, variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
589 |
this->set_variable_prefix(variable_prefix); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
590 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
591 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
592 |
virtual ~generate_cc_sfc_c(void) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
593 |
delete generate_cc_sfc_transitiontest; |
18 | 594 |
delete generate_cc_sfc_transitionresetsteps; |
595 |
delete generate_cc_sfc_transitionsetsteps; |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
596 |
delete generate_cc_sfc_stepassociation; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
597 |
delete generate_cc_sfc_actionexecution; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
598 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
599 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
600 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
601 |
/* B.1.6 Sequential function chart elements */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
602 |
/*********************************************/ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
603 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
604 |
void *visit(sfc_network_c *symbol) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
605 |
s4o.print(s4o.indent_spaces +"INT i;\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
606 |
s4o.print(s4o.indent_spaces +"BOOL transition;\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
607 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
608 |
/* generate step initilizations */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
609 |
s4o.print(s4o.indent_spaces + "// Steps initialisation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
610 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
611 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
612 |
s4o.print("nb_steps; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
613 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
614 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
615 |
print_variable_prefix(); |
18 | 616 |
s4o.print("step_list[i].prev_state = "); |
617 |
print_variable_prefix(); |
|
618 |
s4o.print("step_list[i].state;\n"); |
|
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
619 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
620 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
621 |
s4o.print("step_list[i].state) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
622 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
623 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
624 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
625 |
s4o.print("step_list[i].elapsed_time = __add_timespec("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
626 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
627 |
s4o.print("step_list[i].elapsed_time, PERIOD);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
628 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
629 |
s4o.print(s4o.indent_spaces + "}\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 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
633 |
/* generate action initilizations */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
634 |
s4o.print(s4o.indent_spaces + "// Actions initialisation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
635 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
636 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
637 |
s4o.print("nb_actions; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
638 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
639 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
640 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
641 |
s4o.print("action_list[i].state = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
642 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
643 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
644 |
s4o.print("action_list[i].set = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
645 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
646 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
647 |
s4o.print("action_list[i].reset = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
648 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
649 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
650 |
s4o.print("__compare_timespec(>, action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
651 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
652 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
653 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
654 |
s4o.print("action_list[i].set_remaining_time = __sub_timespec("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
655 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
656 |
s4o.print("action_list[i].set_remaining_time, PERIOD);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
657 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
658 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
659 |
s4o.print("__compare_timespec(<=, action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
660 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
661 |
s4o.print(s4o.indent_spaces); |
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("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
|
664 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
665 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
666 |
s4o.print("action_list[i].set = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
667 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
668 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
669 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
670 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
671 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
672 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
673 |
s4o.print("__compare_timespec(>, action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
674 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
675 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
676 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
677 |
s4o.print("action_list[i].reset_remaining_time = __sub_timespec("); |
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].reset_remaining_time, PERIOD);\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
680 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
681 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
682 |
s4o.print("__compare_timespec(<=, action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
683 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
684 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
685 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
686 |
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
|
687 |
s4o.print(s4o.indent_spaces); |
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].reset = 1;\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"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
692 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
693 |
s4o.print(s4o.indent_spaces + "}\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
694 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
695 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
696 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
697 |
/* generate transition tests */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
698 |
s4o.print(s4o.indent_spaces + "// Transitions fire test\n"); |
18 | 699 |
generate_cc_sfc_transitiontest->reset_transition_number(); |
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
700 |
symbol->accept(*generate_cc_sfc_transitiontest); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
701 |
s4o.print("\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
702 |
|
18 | 703 |
/* generate transition reset steps */ |
704 |
s4o.print(s4o.indent_spaces + "// Transitions reset steps\n"); |
|
705 |
generate_cc_sfc_transitionresetsteps->reset_transition_number(); |
|
706 |
symbol->accept(*generate_cc_sfc_transitionresetsteps); |
|
707 |
s4o.print("\n"); |
|
708 |
||
709 |
/* generate transition set steps */ |
|
710 |
s4o.print(s4o.indent_spaces + "// Transitions set steps\n"); |
|
711 |
generate_cc_sfc_transitionsetsteps->reset_transition_number(); |
|
712 |
symbol->accept(*generate_cc_sfc_transitionsetsteps); |
|
713 |
s4o.print("\n"); |
|
714 |
||
17
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
715 |
/* generate step association */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
716 |
s4o.print(s4o.indent_spaces + "// Steps association\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
717 |
symbol->accept(*generate_cc_sfc_stepassociation); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
718 |
s4o.print("\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
719 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
720 |
/* generate action state evaluation */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
721 |
s4o.print(s4o.indent_spaces + "// Actions state evaluation\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
722 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
723 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
724 |
s4o.print("nb_actions; i++) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
725 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
726 |
s4o.print(s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
727 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
728 |
s4o.print("action_list[i].set) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
729 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
730 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
731 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
732 |
s4o.print("action_list[i].stored = 1;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
733 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
734 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "if ("); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
735 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
736 |
s4o.print("action_list[i].set) {\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
737 |
s4o.indent_right(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
738 |
s4o.print(s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
739 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
740 |
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
|
741 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
742 |
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
|
743 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
744 |
s4o.print("action_list[i].stored = 0;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
745 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
746 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
747 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
748 |
s4o.print("action_list[i].state |= "); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
749 |
print_variable_prefix(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
750 |
s4o.print("action_list[i].stored;\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
751 |
s4o.indent_left(); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
752 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
753 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
754 |
/* generate action execution */ |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
755 |
s4o.print(s4o.indent_spaces + "// Actions execution\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
756 |
symbol->accept(*generate_cc_sfc_actionexecution); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
757 |
s4o.print("\n"); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
758 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
759 |
return NULL; |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
760 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
761 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
762 |
void generate(sequential_function_chart_c *sfc) { |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
763 |
sfc->accept(*this); |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
764 |
} |
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
765 |
|
38754701ac41
SFC state machine first approach generator implemented
lbessard
parents:
diff
changeset
|
766 |
}; /* generate_cc_sfc_c */ |