author | lbessard |
Fri, 19 Dec 2008 15:09:29 +0100 | |
changeset 160 | 59d58f5e6caa |
parent 158 | eb8a5df69bb0 |
child 166 | 09004f402097 |
permissions | -rw-r--r-- |
111 | 1 |
/* |
2 |
* (c) 2007 Mario de Sousa and Laurent Bessard |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
/* |
|
26 |
* This is one of the versions available for the 4th stage. |
|
27 |
* |
|
28 |
* This 4th stage generates a c++ source program equivalent |
|
29 |
* to the IL and ST code. |
|
30 |
*/ |
|
31 |
||
32 |
//#include <stdio.h> /* required for NULL */ |
|
33 |
//#include <string> |
|
34 |
//#include <iostream> |
|
35 |
||
36 |
//#include "../../util/symtable.hh" |
|
37 |
||
38 |
||
39 |
||
40 |
||
41 |
typedef struct |
|
42 |
{ |
|
43 |
symbol_c *symbol; |
|
44 |
} SYMBOL; |
|
45 |
||
46 |
||
47 |
||
48 |
||
49 |
/***********************************************************************/ |
|
50 |
/***********************************************************************/ |
|
51 |
/***********************************************************************/ |
|
52 |
/***********************************************************************/ |
|
53 |
/***********************************************************************/ |
|
54 |
/***********************************************************************/ |
|
55 |
/***********************************************************************/ |
|
56 |
/***********************************************************************/ |
|
57 |
||
58 |
class generate_var_list_c: protected generate_c_typedecl_c { |
|
59 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
60 |
public: |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
61 |
typedef enum { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
62 |
none_dt, |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
63 |
programs_dt, |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
64 |
variables_dt |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
65 |
} declarationtype_t; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
66 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
67 |
declarationtype_t current_declarationtype; |
160 | 68 |
|
69 |
typedef enum { |
|
70 |
none_vtc, |
|
71 |
variable_vtc, |
|
72 |
pointer_vtc, |
|
73 |
array_vtc, |
|
74 |
structure_vtc, |
|
75 |
function_block_vtc |
|
76 |
} vartypecategory_t; |
|
77 |
||
78 |
vartypecategory_t current_var_type_category; |
|
79 |
||
111 | 80 |
private: |
81 |
symbol_c *current_var_type_symbol; |
|
160 | 82 |
symbol_c *current_var_type_name; |
111 | 83 |
unsigned int current_var_number; |
84 |
unsigned int step_number; |
|
85 |
unsigned int transition_number; |
|
86 |
unsigned int action_number; |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
87 |
bool configuration_defined; |
111 | 88 |
std::list<SYMBOL> current_symbol_list; |
89 |
search_base_type_c search_base_type; |
|
90 |
search_fb_typedecl_c *search_fb_typedecl; |
|
91 |
||
92 |
public: |
|
93 |
generate_var_list_c(stage4out_c *s4o_ptr, symbol_c *scope) |
|
94 |
: generate_c_typedecl_c(s4o_ptr) { |
|
95 |
search_fb_typedecl = new search_fb_typedecl_c(scope); |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
96 |
current_var_number = 0; |
160 | 97 |
current_var_type_symbol = current_var_type_name = NULL; |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
98 |
current_declarationtype = none_dt; |
160 | 99 |
current_var_type_category = none_vtc; |
111 | 100 |
} |
101 |
||
102 |
~generate_var_list_c(void) { |
|
103 |
delete search_fb_typedecl; |
|
104 |
} |
|
105 |
||
160 | 106 |
void update_var_type_symbol(symbol_c *symbol) { |
107 |
||
108 |
this->current_var_type_name = spec_init_sperator_c::get_spec(symbol); |
|
109 |
if (this->current_var_type_name == NULL) |
|
111 | 110 |
ERROR; |
111 |
||
160 | 112 |
this->current_var_type_symbol = search_fb_typedecl->get_decl(this->current_var_type_name); |
113 |
if (this->current_var_type_symbol != NULL) |
|
114 |
this->current_var_type_category = function_block_vtc; |
|
115 |
else { |
|
116 |
this->current_var_type_symbol = (symbol_c *)(this->current_var_type_name->accept(search_base_type)); |
|
117 |
||
118 |
structure_element_declaration_list_c *structure_symbol = dynamic_cast<structure_element_declaration_list_c *>(this->current_var_type_symbol); |
|
119 |
if (structure_symbol != NULL) |
|
120 |
this->current_var_type_category = structure_vtc; |
|
121 |
else |
|
122 |
this->current_var_type_category = variable_vtc; |
|
123 |
} |
|
124 |
||
111 | 125 |
if (this->current_var_type_symbol == NULL) |
126 |
ERROR; |
|
127 |
} |
|
128 |
||
129 |
void reset_var_type_symbol(void) { |
|
130 |
this->current_var_type_symbol = NULL; |
|
131 |
} |
|
132 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
133 |
void generate_programs(symbol_c *symbol) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
134 |
s4o.print("// Programs\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
135 |
current_var_number = 0; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
136 |
configuration_defined = false; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
137 |
current_declarationtype = programs_dt; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
138 |
symbol->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
139 |
current_declarationtype = none_dt; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
140 |
s4o.print("\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
141 |
} |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
142 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
143 |
void generate_variables(symbol_c *symbol) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
144 |
s4o.print("// Variables\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
145 |
current_var_number = 0; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
146 |
configuration_defined = false; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
147 |
current_declarationtype = variables_dt; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
148 |
symbol->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
149 |
current_declarationtype = none_dt; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
150 |
s4o.print("\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
151 |
} |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
152 |
|
160 | 153 |
void declare_variables(symbol_c *symbol) { |
111 | 154 |
list_c *list = dynamic_cast<list_c *>(symbol); |
155 |
/* should NEVER EVER occur!! */ |
|
156 |
if (list == NULL) ERROR; |
|
157 |
||
158 |
for(int i = 0; i < list->n; i++) { |
|
160 | 159 |
declare_variable(list->elements[i]); |
160 |
} |
|
161 |
} |
|
162 |
||
163 |
void declare_variable(symbol_c *symbol) { |
|
157 | 164 |
print_var_number(); |
165 |
s4o.print(";"); |
|
160 | 166 |
switch (this->current_var_type_category) { |
167 |
case pointer_vtc: |
|
168 |
s4o.print("PT"); |
|
169 |
break; |
|
170 |
case array_vtc: |
|
171 |
s4o.print("ARRAY"); |
|
172 |
break; |
|
173 |
case structure_vtc: |
|
174 |
s4o.print("STRUCT"); |
|
175 |
break; |
|
176 |
case function_block_vtc: |
|
177 |
s4o.print("FB"); |
|
178 |
break; |
|
179 |
default: |
|
180 |
s4o.print("VAR"); |
|
181 |
break; |
|
182 |
} |
|
157 | 183 |
s4o.print(";"); |
184 |
print_symbol_list(); |
|
185 |
symbol->accept(*this); |
|
186 |
s4o.print(";"); |
|
187 |
print_symbol_list(); |
|
188 |
symbol->accept(*this); |
|
189 |
s4o.print(";"); |
|
160 | 190 |
switch (this->current_var_type_category) { |
191 |
case structure_vtc: |
|
192 |
case function_block_vtc: |
|
193 |
this->current_var_type_name->accept(*this); |
|
194 |
s4o.print(";\n"); |
|
195 |
SYMBOL *current_name; |
|
196 |
current_name = new SYMBOL; |
|
197 |
current_name->symbol = symbol; |
|
198 |
current_symbol_list.push_back(*current_name); |
|
199 |
this->current_var_type_symbol->accept(*this); |
|
200 |
current_symbol_list.pop_back(); |
|
201 |
break; |
|
202 |
case array_vtc: |
|
203 |
this->current_var_type_name->accept(*this); |
|
204 |
s4o.print(";\n"); |
|
205 |
break; |
|
206 |
default: |
|
207 |
this->current_var_type_symbol->accept(*this); |
|
208 |
s4o.print(";\n"); |
|
209 |
break; |
|
111 | 210 |
} |
211 |
} |
|
212 |
||
213 |
void print_var_number(void) { |
|
214 |
char str[10]; |
|
215 |
sprintf(str, "%d", current_var_number); |
|
216 |
s4o.print(str); |
|
217 |
current_var_number++; |
|
218 |
} |
|
219 |
||
220 |
void print_step_number(void) { |
|
221 |
char str[10]; |
|
222 |
sprintf(str, "%d", step_number); |
|
223 |
s4o.print(str); |
|
224 |
} |
|
225 |
||
226 |
void print_transition_number(void) { |
|
227 |
char str[10]; |
|
228 |
sprintf(str, "%d", transition_number); |
|
229 |
s4o.print(str); |
|
230 |
} |
|
231 |
||
232 |
void print_action_number(void) { |
|
233 |
char str[10]; |
|
234 |
sprintf(str, "%d", action_number); |
|
235 |
s4o.print(str); |
|
236 |
} |
|
237 |
||
238 |
void print_symbol_list(void) { |
|
239 |
std::list<SYMBOL>::iterator pt; |
|
240 |
for(pt = current_symbol_list.begin(); pt != current_symbol_list.end(); pt++) { |
|
241 |
pt->symbol->accept(*this); |
|
242 |
s4o.print("."); |
|
243 |
} |
|
244 |
} |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
245 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
246 |
/********************************************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
247 |
/* B.1.4.3 - Declaration and initialization */ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
248 |
/********************************************/ |
111 | 249 |
|
250 |
/* [variable_name] location ':' located_var_spec_init */ |
|
251 |
/* variable_name -> may be NULL ! */ |
|
252 |
//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
253 |
void *visit(located_var_decl_c *symbol) { |
|
254 |
/* Start off by setting the current_var_type_symbol and |
|
255 |
* current_var_init_symbol private variables... |
|
256 |
*/ |
|
257 |
update_var_type_symbol(symbol->located_var_spec_init); |
|
258 |
||
160 | 259 |
if (symbol->variable_name != NULL) { |
260 |
this->current_var_type_category = pointer_vtc; |
|
261 |
declare_variable(symbol->variable_name); |
|
262 |
} |
|
111 | 263 |
|
264 |
current_var_type_symbol = NULL; |
|
265 |
return NULL; |
|
266 |
} |
|
267 |
||
268 |
/* var1_list ':' array_spec_init */ |
|
269 |
// SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
270 |
void *visit(array_var_init_decl_c *symbol) { |
|
271 |
TRACE("array_var_init_decl_c"); |
|
272 |
/* Start off by setting the current_var_type_symbol and |
|
273 |
* current_var_init_symbol private variables... |
|
274 |
*/ |
|
275 |
update_var_type_symbol(symbol->array_spec_init); |
|
160 | 276 |
|
277 |
this->current_var_type_category = array_vtc; |
|
111 | 278 |
declare_variables(symbol->var1_list); |
279 |
||
280 |
/* Values no longer in scope, and therefore no longer used. |
|
281 |
* Make an effort to keep them set to NULL when not in use |
|
282 |
* in order to catch bugs as soon as possible... |
|
283 |
*/ |
|
284 |
reset_var_type_symbol(); |
|
285 |
||
286 |
return NULL; |
|
287 |
} |
|
288 |
||
289 |
/* var1_list ':' initialized_structure */ |
|
290 |
// SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
291 |
void *visit(structured_var_init_decl_c *symbol) { |
|
292 |
TRACE("structured_var_init_decl_c"); |
|
293 |
/* Please read the comments inside the var1_init_decl_c |
|
294 |
* visitor, as they apply here too. |
|
295 |
*/ |
|
296 |
||
297 |
/* Start off by setting the current_var_type_symbol and |
|
298 |
* current_var_init_symbol private variables... |
|
299 |
*/ |
|
300 |
update_var_type_symbol(symbol->initialized_structure); |
|
301 |
||
302 |
/* now to produce the c equivalent... */ |
|
303 |
declare_variables(symbol->var1_list); |
|
304 |
||
305 |
/* Values no longer in scope, and therefore no longer used. |
|
306 |
* Make an effort to keep them set to NULL when not in use |
|
307 |
* in order to catch bugs as soon as possible... |
|
308 |
*/ |
|
309 |
reset_var_type_symbol(); |
|
310 |
||
311 |
return NULL; |
|
312 |
} |
|
313 |
||
314 |
/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
315 |
/* structure_initialization -> may be NULL ! */ |
|
316 |
void *visit(fb_name_decl_c *symbol) { |
|
317 |
TRACE("fb_name_decl_c"); |
|
318 |
/* Please read the comments inside the var1_init_decl_c |
|
319 |
* visitor, as they apply here too. |
|
320 |
*/ |
|
321 |
||
322 |
/* Start off by setting the current_var_type_symbol and |
|
323 |
* current_var_init_symbol private variables... |
|
324 |
*/ |
|
160 | 325 |
update_var_type_symbol(symbol); |
111 | 326 |
|
327 |
/* now to produce the c equivalent... */ |
|
160 | 328 |
declare_variables(symbol->fb_name_list); |
111 | 329 |
|
330 |
/* Values no longer in scope, and therefore no longer used. |
|
331 |
* Make an effort to keep them set to NULL when not in use |
|
332 |
* in order to catch bugs as soon as possible... |
|
333 |
*/ |
|
334 |
reset_var_type_symbol(); |
|
335 |
||
336 |
return NULL; |
|
337 |
} |
|
338 |
||
339 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
340 |
//SYM_REF2(external_declaration_c, global_var_name, specification) |
|
341 |
void *visit(external_declaration_c *symbol) { |
|
342 |
TRACE("external_declaration_c"); |
|
343 |
/* Please read the comments inside the var1_init_decl_c |
|
344 |
* visitor, as they apply here too. |
|
345 |
*/ |
|
346 |
||
347 |
/* Start off by setting the current_var_type_symbol and |
|
348 |
* current_var_init_symbol private variables... |
|
349 |
*/ |
|
160 | 350 |
update_var_type_symbol(symbol); |
351 |
||
352 |
/* now to produce the c equivalent... */ |
|
353 |
if (this->current_var_type_category == variable_vtc) |
|
354 |
this->current_var_type_category = pointer_vtc; |
|
355 |
declare_variable(symbol->global_var_name); |
|
111 | 356 |
|
357 |
/* Values no longer in scope, and therefore no longer used. |
|
358 |
* Make an effort to keep them set to NULL when not in use |
|
359 |
* in order to catch bugs as soon as possible... |
|
360 |
*/ |
|
361 |
reset_var_type_symbol(); |
|
362 |
||
363 |
return NULL; |
|
364 |
} |
|
365 |
||
366 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
367 |
/* type_specification ->may be NULL ! */ |
|
368 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
369 |
void *visit(global_var_decl_c *symbol) { |
|
370 |
TRACE("global_var_decl_c"); |
|
371 |
/* Please read the comments inside the var1_init_decl_c |
|
372 |
* visitor, as they apply here too. |
|
373 |
*/ |
|
374 |
||
375 |
/* Start off by setting the current_var_type_symbol and |
|
376 |
* current_var_init_symbol private variables... |
|
377 |
*/ |
|
378 |
update_var_type_symbol(symbol->type_specification); |
|
379 |
||
380 |
/* now to produce the c equivalent... */ |
|
381 |
symbol->global_var_spec->accept(*this); |
|
382 |
||
383 |
/* Values no longer in scope, and therefore no longer used. |
|
384 |
* Make an effort to keep them set to NULL when not in use |
|
385 |
* in order to catch bugs as soon as possible... |
|
386 |
*/ |
|
387 |
reset_var_type_symbol(); |
|
388 |
||
389 |
return NULL; |
|
390 |
} |
|
391 |
||
392 |
void *visit(global_var_list_c *symbol) { |
|
393 |
declare_variables(symbol); |
|
394 |
return NULL; |
|
395 |
} |
|
396 |
||
397 |
/*| global_var_name location */ |
|
398 |
// SYM_REF2(global_var_spec_c, global_var_name, location) |
|
399 |
void *visit(global_var_spec_c *symbol) { |
|
400 |
if (symbol->global_var_name != NULL) |
|
160 | 401 |
this->current_var_type_category = pointer_vtc; |
402 |
declare_variable(symbol->global_var_name); |
|
111 | 403 |
return NULL; |
404 |
} |
|
405 |
||
406 |
void *visit(var1_init_decl_c *symbol) { |
|
407 |
TRACE("var1_init_decl_c"); |
|
408 |
||
409 |
/* Start off by setting the current_var_type_symbol and |
|
410 |
* current_var_init_symbol private variables... |
|
411 |
*/ |
|
412 |
update_var_type_symbol(symbol->spec_init); |
|
413 |
||
414 |
/* now to produce the c equivalent... */ |
|
415 |
declare_variables(symbol->var1_list); |
|
416 |
||
417 |
/* Values no longer in scope, and therefore no longer used. |
|
418 |
* Make an effort to keep them set to NULL when not in use |
|
419 |
* in order to catch bugs as soon as possible... |
|
420 |
*/ |
|
421 |
reset_var_type_symbol(); |
|
422 |
||
423 |
return NULL; |
|
424 |
} |
|
425 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
426 |
/********************************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
427 |
/* B 1.3.3 - Derived data types */ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
428 |
/********************************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
429 |
void *visit(data_type_declaration_c *symbol) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
430 |
return NULL; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
431 |
} |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
432 |
|
160 | 433 |
void *visit(structure_element_declaration_list_c *symbol) { |
434 |
for(int i = 0; i < symbol->n; i++) { |
|
435 |
symbol->elements[i]->accept(*this); |
|
436 |
} |
|
437 |
return NULL; |
|
438 |
} |
|
439 |
||
440 |
void *visit(structure_element_declaration_c *symbol) { |
|
441 |
/* Start off by setting the current_var_type_symbol and |
|
442 |
* current_var_init_symbol private variables... |
|
443 |
*/ |
|
444 |
update_var_type_symbol(symbol->spec_init); |
|
445 |
||
446 |
/* now to produce the c equivalent... */ |
|
447 |
declare_variable(symbol->structure_element_name); |
|
448 |
||
449 |
/* Values no longer in scope, and therefore no longer used. |
|
450 |
* Make an effort to keep them set to NULL when not in use |
|
451 |
* in order to catch bugs as soon as possible... |
|
452 |
*/ |
|
453 |
reset_var_type_symbol(); |
|
454 |
||
455 |
return NULL; |
|
456 |
} |
|
457 |
||
111 | 458 |
/**************************************/ |
459 |
/* B.1.5 - Program organization units */ |
|
460 |
/**************************************/ |
|
461 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
462 |
/***********************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
463 |
/* B 1.5.1 - Functions */ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
464 |
/***********************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
465 |
void *visit(function_declaration_c *symbol) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
466 |
return NULL; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
467 |
} |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
468 |
|
111 | 469 |
/*****************************/ |
470 |
/* B 1.5.2 - Function Blocks */ |
|
471 |
/*****************************/ |
|
472 |
void *visit(function_block_declaration_c *symbol) { |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
473 |
if (current_declarationtype == variables_dt && configuration_defined) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
474 |
symbol->var_declarations->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
475 |
symbol->fblock_body->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
476 |
} |
111 | 477 |
return NULL; |
478 |
} |
|
479 |
||
480 |
/**********************/ |
|
481 |
/* B 1.5.3 - Programs */ |
|
482 |
/**********************/ |
|
483 |
void *visit(program_declaration_c *symbol) { |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
484 |
if (current_declarationtype == variables_dt && configuration_defined) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
485 |
symbol->var_declarations->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
486 |
symbol->function_block_body->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
487 |
} |
111 | 488 |
return NULL; |
489 |
} |
|
490 |
||
491 |
/**********************************************/ |
|
492 |
/* B 1.6 - Sequential function chart elements */ |
|
493 |
/**********************************************/ |
|
494 |
||
495 |
/* | sequential_function_chart sfc_network */ |
|
496 |
//SYM_LIST(sequential_function_chart_c) |
|
497 |
void *visit(sequential_function_chart_c *symbol) { |
|
498 |
step_number = 0; |
|
499 |
transition_number = 0; |
|
500 |
action_number = 0; |
|
501 |
for(int i = 0; i < symbol->n; i++) { |
|
502 |
symbol->elements[i]->accept(*this); |
|
503 |
} |
|
504 |
return NULL; |
|
505 |
} |
|
506 |
||
507 |
/* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
|
508 |
//SYM_REF2(initial_step_c, step_name, action_association_list) |
|
509 |
void *visit(initial_step_c *symbol) { |
|
510 |
print_var_number(); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
511 |
s4o.print(";VAR;"); |
111 | 512 |
print_symbol_list(); |
513 |
symbol->step_name->accept(*this); |
|
514 |
s4o.print(".X;"); |
|
515 |
print_symbol_list(); |
|
141 | 516 |
s4o.print("__step_list["); |
111 | 517 |
print_step_number(); |
518 |
s4o.print("].state;STEP;\n"); |
|
519 |
step_number++; |
|
520 |
return NULL; |
|
521 |
} |
|
522 |
||
523 |
/* STEP step_name ':' action_association_list END_STEP */ |
|
524 |
//SYM_REF2(step_c, step_name, action_association_list) |
|
525 |
void *visit(step_c *symbol) { |
|
526 |
print_var_number(); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
527 |
s4o.print(";VAR;"); |
111 | 528 |
print_symbol_list(); |
529 |
symbol->step_name->accept(*this); |
|
530 |
s4o.print(".X;"); |
|
531 |
print_symbol_list(); |
|
141 | 532 |
s4o.print("__step_list["); |
111 | 533 |
print_step_number(); |
534 |
s4o.print("].state;STEP;\n"); |
|
535 |
step_number++; |
|
536 |
return NULL; |
|
537 |
} |
|
538 |
||
539 |
/* TRANSITION [transition_name] ['(' PRIORITY ASSIGN integer ')'] |
|
540 |
* FROM steps TO steps |
|
541 |
* transition_condition |
|
542 |
* END_TRANSITION |
|
543 |
*/ |
|
544 |
/* transition_name -> may be NULL ! */ |
|
545 |
/* integer -> may be NULL ! */ |
|
546 |
//SYM_REF5(transition_c, transition_name, integer, from_steps, to_steps, transition_condition) |
|
547 |
void *visit(transition_c *symbol) { |
|
548 |
print_var_number(); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
549 |
s4o.print(";VAR;"); |
111 | 550 |
print_symbol_list(); |
551 |
symbol->from_steps->accept(*this); |
|
552 |
s4o.print("->"); |
|
553 |
symbol->to_steps->accept(*this); |
|
554 |
s4o.print(";"); |
|
555 |
print_symbol_list(); |
|
141 | 556 |
s4o.print("__debug_transition_list["); |
111 | 557 |
print_transition_number(); |
558 |
s4o.print("];TRANSITION;\n"); |
|
559 |
transition_number++; |
|
560 |
return NULL; |
|
561 |
} |
|
562 |
||
563 |
/* step_name | '(' step_name_list ')' */ |
|
564 |
/* step_name -> may be NULL ! */ |
|
565 |
/* step_name_list -> may be NULL ! */ |
|
566 |
//SYM_REF2(steps_c, step_name, step_name_list) |
|
567 |
void *visit(steps_c *symbol) { |
|
568 |
if (symbol->step_name != NULL) |
|
569 |
symbol->step_name->accept(*this); |
|
570 |
if (symbol->step_name_list != NULL) |
|
571 |
symbol->step_name_list->accept(*this); |
|
572 |
return NULL; |
|
573 |
} |
|
574 |
||
575 |
/* | step_name_list ',' step_name */ |
|
576 |
//SYM_LIST(step_name_list_c) |
|
577 |
void *visit(step_name_list_c *symbol) { |
|
578 |
for(int i = 0; i < symbol->n; i++) { |
|
579 |
symbol->elements[i]->accept(*this); |
|
580 |
if (i < symbol->n - 1) |
|
581 |
s4o.print(","); |
|
582 |
} |
|
583 |
return NULL; |
|
584 |
} |
|
585 |
||
586 |
/* ACTION action_name ':' function_block_body END_ACTION */ |
|
587 |
//SYM_REF2(action_c, action_name, function_block_body) |
|
588 |
void *visit(action_c *symbol) { |
|
589 |
print_var_number(); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
590 |
s4o.print(";VAR;"); |
111 | 591 |
print_symbol_list(); |
592 |
symbol->action_name->accept(*this); |
|
593 |
s4o.print(".Q;"); |
|
594 |
print_symbol_list(); |
|
141 | 595 |
s4o.print("__action_list["); |
111 | 596 |
print_action_number(); |
597 |
s4o.print("].state;ACTION;\n"); |
|
598 |
action_number++; |
|
599 |
return NULL; |
|
600 |
} |
|
601 |
||
602 |
||
603 |
/**************************************/ |
|
604 |
/* B.1.7 - Configuration elements */ |
|
605 |
/**************************************/ |
|
606 |
||
607 |
/* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
608 |
//SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
609 |
void *visit(program_configuration_c *symbol) { |
|
610 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
611 |
switch (current_declarationtype) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
612 |
case programs_dt: |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
613 |
print_var_number(); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
614 |
s4o.print(";"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
615 |
print_symbol_list(); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
616 |
symbol->program_name->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
617 |
s4o.print(";"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
618 |
symbol->program_type_name->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
619 |
s4o.print(";\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
620 |
break; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
621 |
case variables_dt: |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
622 |
/* Start off by setting the current_var_type_symbol and |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
623 |
* current_var_init_symbol private variables... |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
624 |
*/ |
160 | 625 |
update_var_type_symbol(symbol->program_type_name); |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
626 |
|
160 | 627 |
declare_variable(symbol->program_name); |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
628 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
629 |
/* Values no longer in scope, and therefore no longer used. |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
630 |
* Make an effort to keep them set to NULL when not in use |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
631 |
* in order to catch bugs as soon as possible... |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
632 |
*/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
633 |
reset_var_type_symbol(); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
634 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
635 |
break; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
636 |
default: |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
637 |
break; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
638 |
} |
111 | 639 |
|
640 |
return NULL; |
|
641 |
} |
|
642 |
||
643 |
/* CONFIGURATION configuration_name |
|
644 |
* optional_global_var_declarations |
|
645 |
* (resource_declaration_list | single_resource_declaration) |
|
646 |
* optional_access_declarations |
|
647 |
* optional_instance_specific_initializations |
|
648 |
* END_CONFIGURATION |
|
649 |
*/ |
|
650 |
//SYM_REF5(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations) |
|
651 |
void *visit(configuration_declaration_c *symbol) { |
|
652 |
SYMBOL *current_name; |
|
653 |
current_name = new SYMBOL; |
|
654 |
current_name->symbol = symbol->configuration_name; |
|
655 |
current_symbol_list.push_back(*current_name); |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
656 |
configuration_defined = true; |
135
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
657 |
|
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
658 |
switch (current_declarationtype) { |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
659 |
case variables_dt: |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
660 |
if (symbol->global_var_declarations != NULL) |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
661 |
symbol->global_var_declarations->accept(*this); |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
662 |
break; |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
663 |
default: |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
664 |
break; |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
665 |
} |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
666 |
|
111 | 667 |
symbol->resource_declarations->accept(*this); |
668 |
current_symbol_list.pop_back(); |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
669 |
configuration_defined = false; |
111 | 670 |
return NULL; |
671 |
} |
|
672 |
||
673 |
/* RESOURCE resource_name ON resource_type_name |
|
674 |
* optional_global_var_declarations |
|
675 |
* single_resource_declaration |
|
676 |
* END_RESOURCE |
|
677 |
*/ |
|
678 |
//SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
679 |
void *visit(resource_declaration_c *symbol) { |
|
680 |
SYMBOL *current_name; |
|
681 |
current_name = new SYMBOL; |
|
682 |
current_name->symbol = symbol->resource_name; |
|
683 |
current_symbol_list.push_back(*current_name); |
|
135
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
684 |
|
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
685 |
switch (current_declarationtype) { |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
686 |
case variables_dt: |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
687 |
if (symbol->global_var_declarations != NULL) |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
688 |
symbol->global_var_declarations->accept(*this); |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
689 |
break; |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
690 |
default: |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
691 |
break; |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
692 |
} |
0f3f6714b938
Fixed generation of VARIABLES.csv, some variables appeared in program section
etisserant
parents:
121
diff
changeset
|
693 |
|
111 | 694 |
|
695 |
symbol->resource_declaration->accept(*this); |
|
696 |
||
697 |
current_symbol_list.pop_back(); |
|
698 |
return NULL; |
|
699 |
} |
|
700 |
||
701 |
/* task_configuration_list program_configuration_list */ |
|
702 |
//SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
703 |
void *visit(single_resource_declaration_c *symbol) { |
|
704 |
symbol->program_configuration_list->accept(*this); |
|
705 |
return NULL; |
|
706 |
} |
|
707 |
||
708 |
||
709 |
/*************************************/ |
|
710 |
/* B 2.1 - Instructions and operands */ |
|
711 |
/*************************************/ |
|
712 |
void *visit(instruction_list_c *symbol) { |
|
713 |
return NULL; |
|
714 |
} |
|
715 |
||
716 |
/************************/ |
|
717 |
/* B 3.2 - Statements */ |
|
718 |
/************************/ |
|
719 |
void *visit(statement_list_c *symbol) { |
|
720 |
return NULL; |
|
721 |
} |
|
722 |
||
723 |
}; |