author | etisserant |
Mon, 23 Jun 2008 18:02:09 +0200 | |
changeset 122 | 9e57c6d79398 |
parent 121 | 9e8ce092e169 |
child 135 | 0f3f6714b938 |
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; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
68 |
|
111 | 69 |
private: |
70 |
symbol_c *current_var_type_symbol; |
|
71 |
unsigned int current_var_number; |
|
72 |
unsigned int step_number; |
|
73 |
unsigned int transition_number; |
|
74 |
unsigned int action_number; |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
75 |
bool configuration_defined; |
111 | 76 |
std::list<SYMBOL> current_symbol_list; |
77 |
search_base_type_c search_base_type; |
|
78 |
search_fb_typedecl_c *search_fb_typedecl; |
|
79 |
||
80 |
public: |
|
81 |
generate_var_list_c(stage4out_c *s4o_ptr, symbol_c *scope) |
|
82 |
: generate_c_typedecl_c(s4o_ptr) { |
|
83 |
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
|
84 |
current_var_number = 0; |
111 | 85 |
current_var_type_symbol = NULL; |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
86 |
current_declarationtype = none_dt; |
111 | 87 |
} |
88 |
||
89 |
~generate_var_list_c(void) { |
|
90 |
delete search_fb_typedecl; |
|
91 |
} |
|
92 |
||
93 |
void update_var_type_symbol(symbol_c *symbol, bool is_fb = false) { |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
94 |
|
111 | 95 |
this->current_var_type_symbol = spec_init_sperator_c::get_spec(symbol); |
96 |
if (this->current_var_type_symbol == NULL) |
|
97 |
ERROR; |
|
98 |
||
99 |
if (is_fb) |
|
100 |
this->current_var_type_symbol = search_fb_typedecl->get_decl(this->current_var_type_symbol); |
|
101 |
else |
|
102 |
this->current_var_type_symbol = (symbol_c *)(this->current_var_type_symbol->accept(search_base_type)); |
|
103 |
if (this->current_var_type_symbol == NULL) |
|
104 |
ERROR; |
|
105 |
} |
|
106 |
||
107 |
void reset_var_type_symbol(void) { |
|
108 |
this->current_var_type_symbol = NULL; |
|
109 |
} |
|
110 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
111 |
void generate_programs(symbol_c *symbol) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
112 |
s4o.print("// Programs\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
113 |
current_var_number = 0; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
114 |
configuration_defined = false; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
115 |
current_declarationtype = programs_dt; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
116 |
symbol->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
117 |
current_declarationtype = none_dt; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
118 |
s4o.print("\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
119 |
} |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
120 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
121 |
void generate_variables(symbol_c *symbol) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
122 |
s4o.print("// Variables\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
123 |
current_var_number = 0; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
124 |
configuration_defined = false; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
125 |
current_declarationtype = variables_dt; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
126 |
symbol->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
127 |
current_declarationtype = none_dt; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
128 |
s4o.print("\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
129 |
} |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
130 |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
131 |
void declare_variables(symbol_c *symbol, const char* type = "VAR") { |
111 | 132 |
list_c *list = dynamic_cast<list_c *>(symbol); |
133 |
/* should NEVER EVER occur!! */ |
|
134 |
if (list == NULL) ERROR; |
|
135 |
||
136 |
for(int i = 0; i < list->n; i++) { |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
137 |
declare_variable(list->elements[i], type); |
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
138 |
} |
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
139 |
} |
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
140 |
|
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
141 |
void declare_variable(symbol_c *symbol, const char* type = "VAR") { |
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
142 |
if (strcmp(type, "FB") == 0) { |
111 | 143 |
SYMBOL *current_name; |
144 |
current_name = new SYMBOL; |
|
145 |
current_name->symbol = symbol; |
|
146 |
current_symbol_list.push_back(*current_name); |
|
147 |
this->current_var_type_symbol->accept(*this); |
|
148 |
current_symbol_list.pop_back(); |
|
149 |
} |
|
150 |
else { |
|
151 |
print_var_number(); |
|
152 |
s4o.print(";"); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
153 |
s4o.print(type); |
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
154 |
s4o.print(";"); |
111 | 155 |
print_symbol_list(); |
156 |
symbol->accept(*this); |
|
157 |
s4o.print(";"); |
|
158 |
print_symbol_list(); |
|
159 |
symbol->accept(*this); |
|
160 |
s4o.print(";"); |
|
161 |
this->current_var_type_symbol->accept(*this); |
|
162 |
s4o.print(";\n"); |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
void print_var_number(void) { |
|
167 |
char str[10]; |
|
168 |
sprintf(str, "%d", current_var_number); |
|
169 |
s4o.print(str); |
|
170 |
current_var_number++; |
|
171 |
} |
|
172 |
||
173 |
void print_step_number(void) { |
|
174 |
char str[10]; |
|
175 |
sprintf(str, "%d", step_number); |
|
176 |
s4o.print(str); |
|
177 |
} |
|
178 |
||
179 |
void print_transition_number(void) { |
|
180 |
char str[10]; |
|
181 |
sprintf(str, "%d", transition_number); |
|
182 |
s4o.print(str); |
|
183 |
} |
|
184 |
||
185 |
void print_action_number(void) { |
|
186 |
char str[10]; |
|
187 |
sprintf(str, "%d", action_number); |
|
188 |
s4o.print(str); |
|
189 |
} |
|
190 |
||
191 |
void print_symbol_list(void) { |
|
192 |
std::list<SYMBOL>::iterator pt; |
|
193 |
for(pt = current_symbol_list.begin(); pt != current_symbol_list.end(); pt++) { |
|
194 |
pt->symbol->accept(*this); |
|
195 |
s4o.print("."); |
|
196 |
} |
|
197 |
} |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
198 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
199 |
/********************************************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
200 |
/* B.1.4.3 - Declaration and initialization */ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
201 |
/********************************************/ |
111 | 202 |
|
203 |
/* [variable_name] location ':' located_var_spec_init */ |
|
204 |
/* variable_name -> may be NULL ! */ |
|
205 |
//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
206 |
void *visit(located_var_decl_c *symbol) { |
|
207 |
/* Start off by setting the current_var_type_symbol and |
|
208 |
* current_var_init_symbol private variables... |
|
209 |
*/ |
|
210 |
update_var_type_symbol(symbol->located_var_spec_init); |
|
211 |
||
212 |
if (symbol->variable_name != NULL) |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
213 |
declare_variable(symbol->variable_name, "PT"); |
111 | 214 |
|
215 |
current_var_type_symbol = NULL; |
|
216 |
return NULL; |
|
217 |
} |
|
218 |
||
219 |
/* var1_list ':' array_spec_init */ |
|
220 |
// SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
221 |
void *visit(array_var_init_decl_c *symbol) { |
|
222 |
TRACE("array_var_init_decl_c"); |
|
223 |
/* Start off by setting the current_var_type_symbol and |
|
224 |
* current_var_init_symbol private variables... |
|
225 |
*/ |
|
226 |
update_var_type_symbol(symbol->array_spec_init); |
|
227 |
||
228 |
declare_variables(symbol->var1_list); |
|
229 |
||
230 |
/* Values no longer in scope, and therefore no longer used. |
|
231 |
* Make an effort to keep them set to NULL when not in use |
|
232 |
* in order to catch bugs as soon as possible... |
|
233 |
*/ |
|
234 |
reset_var_type_symbol(); |
|
235 |
||
236 |
return NULL; |
|
237 |
} |
|
238 |
||
239 |
/* var1_list ':' initialized_structure */ |
|
240 |
// SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
241 |
void *visit(structured_var_init_decl_c *symbol) { |
|
242 |
TRACE("structured_var_init_decl_c"); |
|
243 |
/* Please read the comments inside the var1_init_decl_c |
|
244 |
* visitor, as they apply here too. |
|
245 |
*/ |
|
246 |
||
247 |
/* Start off by setting the current_var_type_symbol and |
|
248 |
* current_var_init_symbol private variables... |
|
249 |
*/ |
|
250 |
update_var_type_symbol(symbol->initialized_structure); |
|
251 |
||
252 |
/* now to produce the c equivalent... */ |
|
253 |
declare_variables(symbol->var1_list); |
|
254 |
||
255 |
/* Values no longer in scope, and therefore no longer used. |
|
256 |
* Make an effort to keep them set to NULL when not in use |
|
257 |
* in order to catch bugs as soon as possible... |
|
258 |
*/ |
|
259 |
reset_var_type_symbol(); |
|
260 |
||
261 |
return NULL; |
|
262 |
} |
|
263 |
||
264 |
/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
265 |
/* structure_initialization -> may be NULL ! */ |
|
266 |
void *visit(fb_name_decl_c *symbol) { |
|
267 |
TRACE("fb_name_decl_c"); |
|
268 |
/* Please read the comments inside the var1_init_decl_c |
|
269 |
* visitor, as they apply here too. |
|
270 |
*/ |
|
271 |
||
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, true); |
|
276 |
||
277 |
/* now to produce the c equivalent... */ |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
278 |
declare_variables(symbol->fb_name_list, "FB"); |
111 | 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 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
290 |
//SYM_REF2(external_declaration_c, global_var_name, specification) |
|
291 |
void *visit(external_declaration_c *symbol) { |
|
292 |
TRACE("external_declaration_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 |
this->current_var_type_symbol = (symbol_c *)(symbol->specification->accept(*search_fb_typedecl)); |
|
301 |
if (this->current_var_type_symbol == NULL) { |
|
302 |
this->current_var_type_symbol = symbol->specification; |
|
303 |
||
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
304 |
declare_variable(symbol->global_var_name, "PT"); |
111 | 305 |
} |
306 |
else |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
307 |
declare_variable(symbol->global_var_name, "FB"); |
111 | 308 |
|
309 |
/* Values no longer in scope, and therefore no longer used. |
|
310 |
* Make an effort to keep them set to NULL when not in use |
|
311 |
* in order to catch bugs as soon as possible... |
|
312 |
*/ |
|
313 |
reset_var_type_symbol(); |
|
314 |
||
315 |
return NULL; |
|
316 |
} |
|
317 |
||
318 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
319 |
/* type_specification ->may be NULL ! */ |
|
320 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
321 |
void *visit(global_var_decl_c *symbol) { |
|
322 |
TRACE("global_var_decl_c"); |
|
323 |
/* Please read the comments inside the var1_init_decl_c |
|
324 |
* visitor, as they apply here too. |
|
325 |
*/ |
|
326 |
||
327 |
/* Start off by setting the current_var_type_symbol and |
|
328 |
* current_var_init_symbol private variables... |
|
329 |
*/ |
|
330 |
update_var_type_symbol(symbol->type_specification); |
|
331 |
||
332 |
/* now to produce the c equivalent... */ |
|
333 |
symbol->global_var_spec->accept(*this); |
|
334 |
||
335 |
/* Values no longer in scope, and therefore no longer used. |
|
336 |
* Make an effort to keep them set to NULL when not in use |
|
337 |
* in order to catch bugs as soon as possible... |
|
338 |
*/ |
|
339 |
reset_var_type_symbol(); |
|
340 |
||
341 |
return NULL; |
|
342 |
} |
|
343 |
||
344 |
void *visit(global_var_list_c *symbol) { |
|
345 |
declare_variables(symbol); |
|
346 |
return NULL; |
|
347 |
} |
|
348 |
||
349 |
/*| global_var_name location */ |
|
350 |
// SYM_REF2(global_var_spec_c, global_var_name, location) |
|
351 |
void *visit(global_var_spec_c *symbol) { |
|
352 |
if (symbol->global_var_name != NULL) |
|
353 |
declare_variable(symbol->global_var_name); |
|
354 |
return NULL; |
|
355 |
} |
|
356 |
||
357 |
void *visit(var1_init_decl_c *symbol) { |
|
358 |
TRACE("var1_init_decl_c"); |
|
359 |
||
360 |
/* Start off by setting the current_var_type_symbol and |
|
361 |
* current_var_init_symbol private variables... |
|
362 |
*/ |
|
363 |
update_var_type_symbol(symbol->spec_init); |
|
364 |
||
365 |
/* now to produce the c equivalent... */ |
|
366 |
declare_variables(symbol->var1_list); |
|
367 |
||
368 |
/* Values no longer in scope, and therefore no longer used. |
|
369 |
* Make an effort to keep them set to NULL when not in use |
|
370 |
* in order to catch bugs as soon as possible... |
|
371 |
*/ |
|
372 |
reset_var_type_symbol(); |
|
373 |
||
374 |
return NULL; |
|
375 |
} |
|
376 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
377 |
/********************************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
378 |
/* B 1.3.3 - Derived data types */ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
379 |
/********************************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
380 |
void *visit(data_type_declaration_c *symbol) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
381 |
return NULL; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
382 |
} |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
383 |
|
111 | 384 |
/**************************************/ |
385 |
/* B.1.5 - Program organization units */ |
|
386 |
/**************************************/ |
|
387 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
388 |
/***********************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
389 |
/* B 1.5.1 - Functions */ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
390 |
/***********************/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
391 |
void *visit(function_declaration_c *symbol) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
392 |
return NULL; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
393 |
} |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
394 |
|
111 | 395 |
/*****************************/ |
396 |
/* B 1.5.2 - Function Blocks */ |
|
397 |
/*****************************/ |
|
398 |
void *visit(function_block_declaration_c *symbol) { |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
399 |
if (current_declarationtype == variables_dt && configuration_defined) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
400 |
symbol->var_declarations->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
401 |
symbol->fblock_body->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
402 |
} |
111 | 403 |
return NULL; |
404 |
} |
|
405 |
||
406 |
/**********************/ |
|
407 |
/* B 1.5.3 - Programs */ |
|
408 |
/**********************/ |
|
409 |
void *visit(program_declaration_c *symbol) { |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
410 |
if (current_declarationtype == variables_dt && configuration_defined) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
411 |
symbol->var_declarations->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
412 |
symbol->function_block_body->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
413 |
} |
111 | 414 |
return NULL; |
415 |
} |
|
416 |
||
417 |
/**********************************************/ |
|
418 |
/* B 1.6 - Sequential function chart elements */ |
|
419 |
/**********************************************/ |
|
420 |
||
421 |
/* | sequential_function_chart sfc_network */ |
|
422 |
//SYM_LIST(sequential_function_chart_c) |
|
423 |
void *visit(sequential_function_chart_c *symbol) { |
|
424 |
step_number = 0; |
|
425 |
transition_number = 0; |
|
426 |
action_number = 0; |
|
427 |
for(int i = 0; i < symbol->n; i++) { |
|
428 |
symbol->elements[i]->accept(*this); |
|
429 |
} |
|
430 |
return NULL; |
|
431 |
} |
|
432 |
||
433 |
/* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
|
434 |
//SYM_REF2(initial_step_c, step_name, action_association_list) |
|
435 |
void *visit(initial_step_c *symbol) { |
|
436 |
print_var_number(); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
437 |
s4o.print(";VAR;"); |
111 | 438 |
print_symbol_list(); |
439 |
symbol->step_name->accept(*this); |
|
440 |
s4o.print(".X;"); |
|
441 |
print_symbol_list(); |
|
442 |
s4o.print("step_list["); |
|
443 |
print_step_number(); |
|
444 |
s4o.print("].state;STEP;\n"); |
|
445 |
step_number++; |
|
446 |
return NULL; |
|
447 |
} |
|
448 |
||
449 |
/* STEP step_name ':' action_association_list END_STEP */ |
|
450 |
//SYM_REF2(step_c, step_name, action_association_list) |
|
451 |
void *visit(step_c *symbol) { |
|
452 |
print_var_number(); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
453 |
s4o.print(";VAR;"); |
111 | 454 |
print_symbol_list(); |
455 |
symbol->step_name->accept(*this); |
|
456 |
s4o.print(".X;"); |
|
457 |
print_symbol_list(); |
|
458 |
s4o.print("step_list["); |
|
459 |
print_step_number(); |
|
460 |
s4o.print("].state;STEP;\n"); |
|
461 |
step_number++; |
|
462 |
return NULL; |
|
463 |
} |
|
464 |
||
465 |
/* TRANSITION [transition_name] ['(' PRIORITY ASSIGN integer ')'] |
|
466 |
* FROM steps TO steps |
|
467 |
* transition_condition |
|
468 |
* END_TRANSITION |
|
469 |
*/ |
|
470 |
/* transition_name -> may be NULL ! */ |
|
471 |
/* integer -> may be NULL ! */ |
|
472 |
//SYM_REF5(transition_c, transition_name, integer, from_steps, to_steps, transition_condition) |
|
473 |
void *visit(transition_c *symbol) { |
|
474 |
print_var_number(); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
475 |
s4o.print(";VAR;"); |
111 | 476 |
print_symbol_list(); |
477 |
symbol->from_steps->accept(*this); |
|
478 |
s4o.print("->"); |
|
479 |
symbol->to_steps->accept(*this); |
|
480 |
s4o.print(";"); |
|
481 |
print_symbol_list(); |
|
482 |
s4o.print("transition_list["); |
|
483 |
print_transition_number(); |
|
484 |
s4o.print("];TRANSITION;\n"); |
|
485 |
transition_number++; |
|
486 |
return NULL; |
|
487 |
} |
|
488 |
||
489 |
/* step_name | '(' step_name_list ')' */ |
|
490 |
/* step_name -> may be NULL ! */ |
|
491 |
/* step_name_list -> may be NULL ! */ |
|
492 |
//SYM_REF2(steps_c, step_name, step_name_list) |
|
493 |
void *visit(steps_c *symbol) { |
|
494 |
if (symbol->step_name != NULL) |
|
495 |
symbol->step_name->accept(*this); |
|
496 |
if (symbol->step_name_list != NULL) |
|
497 |
symbol->step_name_list->accept(*this); |
|
498 |
return NULL; |
|
499 |
} |
|
500 |
||
501 |
/* | step_name_list ',' step_name */ |
|
502 |
//SYM_LIST(step_name_list_c) |
|
503 |
void *visit(step_name_list_c *symbol) { |
|
504 |
for(int i = 0; i < symbol->n; i++) { |
|
505 |
symbol->elements[i]->accept(*this); |
|
506 |
if (i < symbol->n - 1) |
|
507 |
s4o.print(","); |
|
508 |
} |
|
509 |
return NULL; |
|
510 |
} |
|
511 |
||
512 |
/* ACTION action_name ':' function_block_body END_ACTION */ |
|
513 |
//SYM_REF2(action_c, action_name, function_block_body) |
|
514 |
void *visit(action_c *symbol) { |
|
515 |
print_var_number(); |
|
115
3dd564ff94e4
Adding support to distinguish direct variables and pointed variables
lbessard
parents:
111
diff
changeset
|
516 |
s4o.print(";VAR;"); |
111 | 517 |
print_symbol_list(); |
518 |
symbol->action_name->accept(*this); |
|
519 |
s4o.print(".Q;"); |
|
520 |
print_symbol_list(); |
|
521 |
s4o.print("action_list["); |
|
522 |
print_action_number(); |
|
523 |
s4o.print("].state;ACTION;\n"); |
|
524 |
action_number++; |
|
525 |
return NULL; |
|
526 |
} |
|
527 |
||
528 |
||
529 |
/**************************************/ |
|
530 |
/* B.1.7 - Configuration elements */ |
|
531 |
/**************************************/ |
|
532 |
||
533 |
/* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
534 |
//SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
535 |
void *visit(program_configuration_c *symbol) { |
|
536 |
||
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
537 |
switch (current_declarationtype) { |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
538 |
case programs_dt: |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
539 |
print_var_number(); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
540 |
s4o.print(";"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
541 |
print_symbol_list(); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
542 |
symbol->program_name->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
543 |
s4o.print(";"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
544 |
symbol->program_type_name->accept(*this); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
545 |
s4o.print(";\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
546 |
break; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
547 |
case variables_dt: |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
548 |
/* 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
|
549 |
* current_var_init_symbol private variables... |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
550 |
*/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
551 |
update_var_type_symbol(symbol->program_type_name, true); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
552 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
553 |
declare_variable(symbol->program_name, "FB"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
554 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
555 |
/* 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
|
556 |
* 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
|
557 |
* in order to catch bugs as soon as possible... |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
558 |
*/ |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
559 |
reset_var_type_symbol(); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
560 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
561 |
break; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
562 |
default: |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
563 |
break; |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
564 |
} |
111 | 565 |
|
566 |
return NULL; |
|
567 |
} |
|
568 |
||
569 |
/* CONFIGURATION configuration_name |
|
570 |
* optional_global_var_declarations |
|
571 |
* (resource_declaration_list | single_resource_declaration) |
|
572 |
* optional_access_declarations |
|
573 |
* optional_instance_specific_initializations |
|
574 |
* END_CONFIGURATION |
|
575 |
*/ |
|
576 |
//SYM_REF5(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations) |
|
577 |
void *visit(configuration_declaration_c *symbol) { |
|
578 |
SYMBOL *current_name; |
|
579 |
current_name = new SYMBOL; |
|
580 |
current_name->symbol = symbol->configuration_name; |
|
581 |
current_symbol_list.push_back(*current_name); |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
582 |
configuration_defined = true; |
111 | 583 |
symbol->resource_declarations->accept(*this); |
584 |
current_symbol_list.pop_back(); |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
115
diff
changeset
|
585 |
configuration_defined = false; |
111 | 586 |
return NULL; |
587 |
} |
|
588 |
||
589 |
/* RESOURCE resource_name ON resource_type_name |
|
590 |
* optional_global_var_declarations |
|
591 |
* single_resource_declaration |
|
592 |
* END_RESOURCE |
|
593 |
*/ |
|
594 |
//SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
595 |
void *visit(resource_declaration_c *symbol) { |
|
596 |
SYMBOL *current_name; |
|
597 |
current_name = new SYMBOL; |
|
598 |
current_name->symbol = symbol->resource_name; |
|
599 |
current_symbol_list.push_back(*current_name); |
|
600 |
||
601 |
if (symbol->global_var_declarations != NULL) |
|
602 |
symbol->global_var_declarations->accept(*this); |
|
603 |
||
604 |
symbol->resource_declaration->accept(*this); |
|
605 |
||
606 |
current_symbol_list.pop_back(); |
|
607 |
return NULL; |
|
608 |
} |
|
609 |
||
610 |
/* task_configuration_list program_configuration_list */ |
|
611 |
//SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
612 |
void *visit(single_resource_declaration_c *symbol) { |
|
613 |
symbol->program_configuration_list->accept(*this); |
|
614 |
return NULL; |
|
615 |
} |
|
616 |
||
617 |
||
618 |
/*************************************/ |
|
619 |
/* B 2.1 - Instructions and operands */ |
|
620 |
/*************************************/ |
|
621 |
void *visit(instruction_list_c *symbol) { |
|
622 |
return NULL; |
|
623 |
} |
|
624 |
||
625 |
/************************/ |
|
626 |
/* B 3.2 - Statements */ |
|
627 |
/************************/ |
|
628 |
void *visit(statement_list_c *symbol) { |
|
629 |
return NULL; |
|
630 |
} |
|
631 |
||
632 |
}; |