author | lbessard |
Fri, 21 Nov 2008 13:43:49 +0100 | |
changeset 151 | 3b898fb11e73 |
parent 146 | eef5e62048c7 |
child 152 | efc510145ab2 |
permissions | -rwxr-xr-x |
70 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
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 |
/* |
|
27 |
* Conversion of variable declaration constructs. |
|
28 |
* |
|
29 |
* This is part of the 4th stage that generates |
|
30 |
* a c++ source program equivalent to the IL and ST |
|
31 |
* code. |
|
32 |
*/ |
|
33 |
||
34 |
||
35 |
||
36 |
||
37 |
//#include <stdio.h> /* required for NULL */ |
|
38 |
//#include <string> |
|
39 |
//#include <iostream> |
|
40 |
||
41 |
//#include "../../util/symtable.hh" |
|
42 |
||
43 |
||
44 |
||
45 |
||
98 | 46 |
class generate_c_array_initialization_c: public generate_c_typedecl_c { |
47 |
||
48 |
public: |
|
49 |
typedef enum { |
|
50 |
none_am, |
|
51 |
dimensioncount_am, |
|
52 |
initializationvalue_am, |
|
53 |
arrayassignment_am, |
|
54 |
varlistparse_am |
|
55 |
} arrayinitialization_mode_t; |
|
56 |
||
57 |
arrayinitialization_mode_t current_mode; |
|
58 |
||
59 |
symbol_c* array_default_value; |
|
60 |
||
61 |
private: |
|
62 |
int dimension_number, current_dimension, array_size; |
|
63 |
||
64 |
public: |
|
65 |
generate_c_array_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {} |
|
66 |
~generate_c_array_initialization_c(void) {} |
|
67 |
||
68 |
void init_array(symbol_c *var1_list, symbol_c *array_specification, symbol_c *array_initialization) { |
|
69 |
int i; |
|
70 |
||
71 |
dimension_number = 0; |
|
72 |
current_dimension = 0; |
|
73 |
array_size = 1; |
|
74 |
array_default_value = NULL; |
|
75 |
||
76 |
current_mode = dimensioncount_am; |
|
77 |
array_specification->accept(*this); |
|
78 |
||
79 |
current_mode = initializationvalue_am; |
|
80 |
s4o.print("\n"); |
|
81 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
82 |
s4o.indent_right(); |
|
83 |
s4o.print(s4o.indent_spaces + "int index["); |
|
84 |
print_integer(dimension_number); |
|
85 |
s4o.print("];\n"); |
|
86 |
s4o.print(s4o.indent_spaces); |
|
87 |
array_specification->accept(*this); |
|
88 |
s4o.print(" temp = "); |
|
89 |
array_initialization->accept(*this); |
|
90 |
s4o.print(";\n"); |
|
91 |
||
92 |
current_mode = arrayassignment_am; |
|
93 |
array_specification->accept(*this); |
|
94 |
||
95 |
current_mode = varlistparse_am; |
|
96 |
var1_list->accept(*this); |
|
97 |
||
98 |
current_mode = arrayassignment_am; |
|
99 |
for (i = 0; i < dimension_number; i++) { |
|
100 |
s4o.indent_left(); |
|
101 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
102 |
} |
|
103 |
s4o.indent_left(); |
|
104 |
s4o.print(s4o.indent_spaces + "}"); |
|
105 |
} |
|
106 |
||
107 |
void *visit(identifier_c *type_name) { |
|
108 |
symbol_c *type_decl; |
|
109 |
switch (current_mode) { |
|
110 |
case dimensioncount_am: |
|
111 |
case arrayassignment_am: |
|
112 |
/* look up the type declaration... */ |
|
113 |
type_decl = type_symtable.find_value(type_name); |
|
114 |
if (type_decl == type_symtable.end_value()) |
|
115 |
/* Type declaration not found!! */ |
|
116 |
ERROR; |
|
117 |
type_decl->accept(*this); |
|
118 |
break; |
|
119 |
default: |
|
120 |
print_token(type_name); |
|
121 |
break; |
|
122 |
} |
|
123 |
return NULL; |
|
124 |
} |
|
125 |
||
126 |
void *visit(var1_list_c *symbol) { |
|
127 |
int i, j; |
|
128 |
||
129 |
for (i = 0; i < symbol->n; i++) { |
|
130 |
s4o.print(s4o.indent_spaces); |
|
131 |
print_variable_prefix(); |
|
132 |
symbol->elements[i]->accept(*this); |
|
133 |
for (j = 0; j < dimension_number; j++) { |
|
134 |
s4o.print("[index["); |
|
135 |
print_integer(j); |
|
136 |
s4o.print("]]"); |
|
137 |
} |
|
138 |
s4o.print(" = temp"); |
|
139 |
for (j = 0; j < dimension_number; j++) { |
|
140 |
s4o.print("[index["); |
|
141 |
print_integer(j); |
|
142 |
s4o.print("]]"); |
|
143 |
} |
|
144 |
s4o.print(";\n"); |
|
145 |
} |
|
146 |
return NULL; |
|
147 |
} |
|
148 |
||
149 |
/********************************/ |
|
150 |
/* B 1.3.3 - Derived data types */ |
|
151 |
/********************************/ |
|
152 |
||
153 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
154 |
void *visit(array_specification_c *symbol) { |
|
155 |
switch (current_mode) { |
|
156 |
case dimensioncount_am: |
|
157 |
symbol->array_subrange_list->accept(*this); |
|
158 |
array_default_value = (symbol_c *)symbol->non_generic_type_name->accept(*type_initial_value_c::instance());; |
|
159 |
break; |
|
160 |
default: |
|
161 |
symbol->array_subrange_list->accept(*this); |
|
162 |
break; |
|
163 |
} |
|
164 |
return NULL; |
|
165 |
} |
|
166 |
||
167 |
/* signed_integer DOTDOT signed_integer */ |
|
168 |
//SYM_REF2(subrange_c, lower_limit, upper_limit) |
|
169 |
void *visit(subrange_c *symbol) { |
|
170 |
switch (current_mode) { |
|
171 |
case dimensioncount_am: |
|
172 |
dimension_number++; |
|
173 |
array_size *= extract_integer(symbol->upper_limit) - extract_integer(symbol->lower_limit) + 1; |
|
174 |
break; |
|
175 |
case arrayassignment_am: |
|
176 |
s4o.print(s4o.indent_spaces + "for (index["); |
|
177 |
print_integer(current_dimension); |
|
178 |
s4o.print("] = 0; index["); |
|
179 |
print_integer(current_dimension); |
|
180 |
s4o.print("] <= "); |
|
181 |
print_integer(extract_integer(symbol->upper_limit) - extract_integer(symbol->lower_limit)); |
|
182 |
s4o.print("; index["); |
|
183 |
print_integer(current_dimension); |
|
184 |
s4o.print("]++) {\n"); |
|
185 |
s4o.indent_right(); |
|
186 |
current_dimension++; |
|
187 |
break; |
|
188 |
default: |
|
189 |
break; |
|
190 |
} |
|
191 |
return NULL; |
|
192 |
} |
|
193 |
||
194 |
/* helper symbol for array_initialization */ |
|
195 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
196 |
void *visit(array_initial_elements_list_c *symbol) { |
|
197 |
switch (current_mode) { |
|
198 |
case initializationvalue_am: |
|
199 |
int i; |
|
200 |
||
201 |
s4o.print("{"); |
|
202 |
for (i = 0; i < symbol->n; i++) { |
|
203 |
if (i > 0) |
|
204 |
s4o.print(", "); |
|
205 |
symbol->elements[i]->accept(*this); |
|
206 |
array_size--; |
|
207 |
} |
|
208 |
if (array_size > 0) { |
|
209 |
if (symbol->n > 0) |
|
210 |
s4o.print(", "); |
|
211 |
for (i = 0; i < array_size; i++) { |
|
212 |
if (i > 0) |
|
213 |
s4o.print(", "); |
|
214 |
array_default_value->accept(*this); |
|
215 |
} |
|
216 |
} |
|
217 |
s4o.print("}"); |
|
218 |
break; |
|
219 |
default: |
|
220 |
break; |
|
221 |
} |
|
222 |
return NULL; |
|
223 |
} |
|
224 |
||
225 |
/* integer '(' [array_initial_element] ')' */ |
|
226 |
/* array_initial_element may be NULL ! */ |
|
227 |
void *visit(array_initial_elements_c *symbol) { |
|
228 |
int initial_element_number; |
|
229 |
||
230 |
switch (current_mode) { |
|
231 |
case initializationvalue_am: |
|
232 |
initial_element_number = extract_integer(symbol->integer); |
|
233 |
||
234 |
for (int i = 0; i < initial_element_number; i++) { |
|
235 |
if (i > 0) |
|
236 |
s4o.print(", "); |
|
237 |
if (symbol->array_initial_element != NULL) |
|
238 |
symbol->array_initial_element->accept(*this); |
|
239 |
else if (array_default_value != NULL) |
|
240 |
array_default_value->accept(*this); |
|
241 |
} |
|
242 |
if (initial_element_number > 1) |
|
243 |
array_size -= initial_element_number - 1; |
|
244 |
break; |
|
245 |
default: |
|
246 |
break; |
|
247 |
} |
|
248 |
return NULL; |
|
249 |
} |
|
250 |
||
251 |
}; |
|
70 | 252 |
|
253 |
/***********************************************************************/ |
|
254 |
/***********************************************************************/ |
|
255 |
/***********************************************************************/ |
|
256 |
/***********************************************************************/ |
|
257 |
/***********************************************************************/ |
|
258 |
/***********************************************************************/ |
|
259 |
/***********************************************************************/ |
|
260 |
/***********************************************************************/ |
|
261 |
||
262 |
||
263 |
||
264 |
||
265 |
class generate_c_vardecl_c: protected generate_c_typedecl_c { |
|
266 |
||
267 |
/* A Helper class to the main class... */ |
|
268 |
/* print a string, except the first time it is called */ |
|
269 |
/* used to print the separator "," before each variable |
|
270 |
* declaration, except the first... |
|
271 |
* |
|
272 |
* Needs to be done in a seperate class because this is called |
|
273 |
* from within various locations within the code. |
|
274 |
*/ |
|
275 |
class next_var_c { |
|
276 |
private: |
|
277 |
bool print_flag; |
|
278 |
std::string str1, str2; |
|
279 |
||
280 |
next_var_c *embedded_scope; |
|
281 |
||
282 |
public: |
|
283 |
next_var_c(std::string s1, std::string s2) { |
|
284 |
str1 = s1; |
|
285 |
str2 = s2; |
|
286 |
print_flag = false; |
|
287 |
embedded_scope = NULL; |
|
288 |
} |
|
289 |
||
290 |
std::string get(void) { |
|
291 |
if (NULL != embedded_scope) |
|
292 |
return embedded_scope->get(); |
|
293 |
||
294 |
bool old_print_flag = print_flag; |
|
295 |
print_flag = true; |
|
296 |
if (!old_print_flag) |
|
297 |
return str1; |
|
298 |
else |
|
299 |
return str2; |
|
300 |
} |
|
301 |
||
302 |
/* Create a new next_var_c for an embedded scope. |
|
303 |
* From now on, every call to get() will return the |
|
304 |
* inner-most scope...! |
|
305 |
*/ |
|
306 |
void push(std::string s1, std::string s2) { |
|
307 |
if (NULL != embedded_scope) |
|
308 |
return embedded_scope->push(s1, s2); |
|
309 |
||
310 |
embedded_scope = new next_var_c(s1, s2); |
|
311 |
if (NULL == embedded_scope) |
|
312 |
ERROR; |
|
313 |
return; |
|
314 |
} |
|
315 |
||
316 |
/* Remove the inner-most scope... */ |
|
317 |
void pop(void) { |
|
318 |
if (NULL != embedded_scope) |
|
319 |
return embedded_scope->pop(); |
|
320 |
||
321 |
delete embedded_scope; |
|
322 |
embedded_scope = NULL; |
|
323 |
} |
|
324 |
}; |
|
325 |
||
326 |
private: |
|
327 |
/* used to generate the ',' separating the parameters in a function call */ |
|
328 |
next_var_c *nv; |
|
329 |
||
330 |
||
331 |
public: |
|
332 |
/* the types of variables that need to be processed... */ |
|
333 |
static const unsigned int none_vt = 0x0000; |
|
334 |
static const unsigned int input_vt = 0x0001; // VAR_INPUT |
|
335 |
static const unsigned int output_vt = 0x0002; // VAR_OUTPUT |
|
336 |
static const unsigned int inoutput_vt = 0x0004; // VAR_IN_OUT |
|
337 |
static const unsigned int private_vt = 0x0008; // VAR |
|
338 |
static const unsigned int temp_vt = 0x0010; // VAR_TEMP |
|
339 |
static const unsigned int external_vt = 0x0020; // VAR_EXTERNAL |
|
340 |
static const unsigned int global_vt = 0x0040; // VAR_GLOBAL |
|
341 |
// Globals declared inside a resource will not be declared |
|
342 |
// unless global_vt is acompanied by resource_vt |
|
343 |
static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
|
344 |
static const unsigned int program_vt = 0x0100; // PROGRAM (inside a configuration!) |
|
345 |
// Programs declared inside a resource will not be declared |
|
346 |
// unless program_vt is acompanied by resource_vt |
|
347 |
||
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
348 |
static const unsigned int eneno_vt = 0x0200; // EN/ENO declaration |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
349 |
|
70 | 350 |
static const unsigned int resource_vt = 0x8000; // RESOURCE (inside a configuration!) |
351 |
// This, just of itself, will not print out any declarations!! |
|
352 |
// It must be acompanied by either program_vt and/or global_vt |
|
353 |
||
354 |
/* How variables should be declared: as local variables or |
|
355 |
* variables within a function call interface. |
|
356 |
* |
|
357 |
* This will define the format of the output generated |
|
358 |
* by this class. |
|
359 |
* |
|
360 |
* finterface_vf: function interface parameters |
|
361 |
* e.g. f( int a, long b, real c ); |
|
362 |
* --------------------- |
|
363 |
* This class/function will produce the |
|
364 |
* underlined code of the above examples, |
|
365 |
* and no more!! |
|
366 |
* |
|
367 |
* localinit_vf: local declaration. Will include variable |
|
368 |
* initialisation if it is not a located variable. |
|
369 |
* e.g. |
|
370 |
* int a = 9; |
|
371 |
* long b = 99; |
|
372 |
* real c = 99.9; |
|
373 |
* |
|
374 |
* local_vf: local declaration. Will NOT include variable |
|
375 |
* initialisation. |
|
376 |
* e.g. |
|
377 |
* int a; |
|
378 |
* long b; |
|
379 |
* real c; |
|
380 |
* |
|
381 |
* init_vf: local initialisation without declaration. |
|
382 |
* e.g. |
|
383 |
* a = 9; |
|
384 |
* b = 99; |
|
385 |
* c = 99.9; |
|
386 |
* |
|
387 |
* constructorinit_vf: initialising of member variables... |
|
388 |
* e.g. for a constructor... |
|
389 |
* class_name_c(void) |
|
390 |
* : a(9), b(99), c(99.9) { // code... } |
|
391 |
* -------------------- |
|
392 |
* This class/function will produce the |
|
393 |
* underlined code of the above examples, |
|
394 |
* and no more!! |
|
395 |
* |
|
396 |
* globalinit_vf: initialising of static c++ variables. These |
|
397 |
* variables may have been declared as static inside |
|
398 |
* a class, in which case the scope within which they were |
|
399 |
* previously delcared must be passed as the second parameter |
|
400 |
* to the print() function. |
|
401 |
* |
|
402 |
* e.g. |
|
403 |
* __plc_pt_c<INT, 8*sizeof(INT)> START_P::loc = __plc_pt_c<INT, 8*sizeof(INT)>("I2"); |
|
404 |
*/ |
|
405 |
typedef enum {finterface_vf, |
|
145 | 406 |
foutputassign_vf, |
407 |
local_vf, |
|
408 |
localinit_vf, |
|
409 |
init_vf, |
|
410 |
constructorinit_vf, |
|
411 |
globalinit_vf |
|
412 |
} varformat_t; |
|
70 | 413 |
|
414 |
||
415 |
private: |
|
98 | 416 |
generate_c_array_initialization_c *generate_c_array_initialization; |
417 |
||
70 | 418 |
/* variable used to store the types of variables that need to be processed... */ |
419 |
/* Only set in the constructor...! */ |
|
420 |
/* Will contain a set of values of generate_c_vardecl_c::XXXX_vt */ |
|
421 |
unsigned int wanted_vartype; |
|
422 |
/* variable used to store the type of variable currently being processed... */ |
|
423 |
/* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ |
|
424 |
unsigned int current_vartype; |
|
425 |
||
426 |
/* How variables should be declared: as local variables or |
|
427 |
* variables within a function interface... |
|
428 |
*/ |
|
429 |
/* Only set in the constructor...! */ |
|
430 |
varformat_t wanted_varformat; |
|
431 |
||
432 |
/* The number of variables already declared. */ |
|
433 |
/* Used to declare 'void' in case no variables are declared in a function interface... */ |
|
434 |
int finterface_var_count; |
|
435 |
||
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
436 |
/* Current parsed resource name, for resource |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
437 |
* specific global variable declaration (with #define...)*/ |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
438 |
symbol_c *resource_name; |
70 | 439 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
440 |
/* Store if En and ENO parameters have been defined by user */ |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
441 |
bool en_declared; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
442 |
bool eno_declared; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
443 |
|
70 | 444 |
/* Holds the references to the type and initial value |
445 |
* of the variables currently being declared. |
|
446 |
* Please read the comment under var1_init_decl_c for further |
|
447 |
* details... |
|
448 |
* |
|
449 |
* We make an effort to keep these pointers pointing to NULL |
|
450 |
* whenever we are outside the scope of variable declaration |
|
451 |
* (i.e. when we are traversing a part of the parse tree which |
|
452 |
* is not part of variable declaration) in order tio try to catch |
|
453 |
* any bugs as soon as possible. |
|
454 |
*/ |
|
455 |
symbol_c *current_var_type_symbol; |
|
456 |
symbol_c *current_var_init_symbol; |
|
457 |
void update_type_init(symbol_c *symbol /* a spec_init_c, subrange_spec_init_c, etc... */ ) { |
|
458 |
this->current_var_type_symbol = spec_init_sperator_c::get_spec(symbol); |
|
459 |
this->current_var_init_symbol = spec_init_sperator_c::get_init(symbol); |
|
460 |
if (NULL == this->current_var_type_symbol) |
|
461 |
ERROR; |
|
462 |
if (NULL == this->current_var_init_symbol) { |
|
463 |
/* We try to find the data type's default value... */ |
|
464 |
this->current_var_init_symbol = (symbol_c *)this->current_var_type_symbol->accept(*type_initial_value_c::instance()); |
|
465 |
/* Note that Function Block 'data types' do not have a default value, so we cannot abort if no default value is found! */ |
|
466 |
/* |
|
467 |
if (NULL == this->current_var_init_symbol) |
|
468 |
ERROR; |
|
469 |
*/ |
|
470 |
} |
|
471 |
} |
|
472 |
||
473 |
void void_type_init(void) { |
|
474 |
this->current_var_type_symbol = NULL; |
|
475 |
this->current_var_init_symbol = NULL; |
|
476 |
} |
|
477 |
||
478 |
/* Only used when wanted_varformat == globalinit_vf |
|
479 |
* Holds a pointer to an identifier_c, which in turns contains |
|
480 |
* the identifier of the scope within which the static member was |
|
481 |
* declared. |
|
482 |
*/ |
|
483 |
symbol_c *globalnamespace; |
|
484 |
||
485 |
/* Actually produce the output where variables are declared... */ |
|
486 |
/* Note that located variables are the exception, they |
|
487 |
* being declared in the located_var_decl_c visitor... |
|
488 |
*/ |
|
489 |
void *declare_variables(symbol_c *symbol, bool is_fb = false) { |
|
490 |
list_c *list = dynamic_cast<list_c *>(symbol); |
|
491 |
/* should NEVER EVER occur!! */ |
|
492 |
if (list == NULL) ERROR; |
|
493 |
||
494 |
/* now to produce the c equivalent... */ |
|
495 |
if ((wanted_varformat == local_vf) || |
|
496 |
(wanted_varformat == init_vf) || |
|
497 |
(wanted_varformat == localinit_vf)) { |
|
498 |
for(int i = 0; i < list->n; i++) { |
|
499 |
s4o.print(s4o.indent_spaces); |
|
500 |
if (wanted_varformat != init_vf) { |
|
501 |
this->current_var_type_symbol->accept(*this); |
|
502 |
s4o.print(" "); |
|
503 |
} |
|
504 |
print_variable_prefix(); |
|
505 |
list->elements[i]->accept(*this); |
|
506 |
if (wanted_varformat != local_vf) { |
|
507 |
if (this->current_var_init_symbol != NULL) { |
|
508 |
s4o.print(" = "); |
|
509 |
this->current_var_init_symbol->accept(*this); |
|
510 |
} |
|
511 |
} |
|
512 |
s4o.print(";\n"); |
|
513 |
} |
|
514 |
} |
|
515 |
||
516 |
if (wanted_varformat == finterface_vf) { |
|
517 |
for(int i = 0; i < list->n; i++) { |
|
518 |
finterface_var_count++; |
|
519 |
s4o.print(nv->get()); |
|
520 |
s4o.print("\n" + s4o.indent_spaces); |
|
521 |
this->current_var_type_symbol->accept(*this); |
|
522 |
if ((current_vartype & (output_vt | inoutput_vt)) != 0) |
|
145 | 523 |
s4o.print(" *__"); |
70 | 524 |
else |
525 |
s4o.print(" "); |
|
526 |
list->elements[i]->accept(*this); |
|
527 |
/* We do not print the initial value at function declaration! |
|
528 |
* It is up to the caller to pass the correct default value |
|
529 |
* if none is specified in the ST source code |
|
530 |
*/ |
|
531 |
/* if (this->current_var_init_symbol != NULL) { |
|
532 |
s4o.print(" = "); this->current_var_init_symbol->accept(*this);} |
|
533 |
*/ |
|
534 |
} |
|
535 |
} |
|
536 |
||
145 | 537 |
if (wanted_varformat == foutputassign_vf) { |
538 |
for(int i = 0; i < list->n; i++) { |
|
539 |
if ((current_vartype & (output_vt | inoutput_vt)) != 0) { |
|
540 |
s4o.print(s4o.indent_spaces + "if (__"); |
|
541 |
list->elements[i]->accept(*this); |
|
542 |
s4o.print(" != NULL) {\n"); |
|
543 |
s4o.indent_right(); |
|
544 |
s4o.print(s4o.indent_spaces + "*__"); |
|
545 |
list->elements[i]->accept(*this); |
|
546 |
s4o.print(" = "); |
|
547 |
list->elements[i]->accept(*this); |
|
548 |
s4o.print(";\n"); |
|
549 |
s4o.indent_left(); |
|
550 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
551 |
} |
|
552 |
} |
|
553 |
} |
|
554 |
||
70 | 555 |
if (wanted_varformat == constructorinit_vf) { |
556 |
for(int i = 0; i < list->n; i++) { |
|
557 |
if (is_fb) { |
|
558 |
s4o.print(nv->get()); |
|
559 |
this->current_var_type_symbol->accept(*this); |
|
560 |
s4o.print(FB_INIT_SUFFIX); |
|
561 |
s4o.print("(&"); |
|
562 |
this->print_variable_prefix(); |
|
563 |
list->elements[i]->accept(*this); |
|
564 |
s4o.print(");"); |
|
565 |
} |
|
566 |
else if (this->current_var_init_symbol != NULL) { |
|
567 |
s4o.print(nv->get()); |
|
568 |
this->print_variable_prefix(); |
|
569 |
list->elements[i]->accept(*this); |
|
570 |
s4o.print(" = "); |
|
571 |
this->current_var_init_symbol->accept(*this); |
|
572 |
s4o.print(";"); |
|
573 |
} |
|
574 |
} |
|
575 |
} |
|
576 |
||
577 |
return NULL; |
|
578 |
} |
|
579 |
||
580 |
||
581 |
||
582 |
||
583 |
public: |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
584 |
generate_c_vardecl_c(stage4out_c *s4o_ptr, varformat_t varformat, unsigned int vartype, symbol_c* res_name = NULL) |
70 | 585 |
: generate_c_typedecl_c(s4o_ptr) { |
98 | 586 |
generate_c_array_initialization = new generate_c_array_initialization_c(s4o_ptr); |
70 | 587 |
wanted_varformat = varformat; |
588 |
wanted_vartype = vartype; |
|
589 |
current_vartype = none_vt; |
|
590 |
current_var_type_symbol = NULL; |
|
591 |
current_var_init_symbol = NULL; |
|
592 |
globalnamespace = NULL; |
|
593 |
nv = NULL; |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
594 |
resource_name = res_name; |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
595 |
en_declared = false; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
596 |
eno_declared = false; |
70 | 597 |
} |
598 |
||
98 | 599 |
~generate_c_vardecl_c(void) { |
600 |
delete generate_c_array_initialization; |
|
601 |
} |
|
70 | 602 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
603 |
bool is_en_declared(void) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
604 |
return en_declared; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
605 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
606 |
|
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
607 |
bool is_eno_declared(void) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
608 |
return eno_declared; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
609 |
} |
70 | 610 |
|
611 |
void print(symbol_c *symbol, symbol_c *scope = NULL, const char *variable_prefix = NULL) { |
|
612 |
this->set_variable_prefix(variable_prefix); |
|
98 | 613 |
this->generate_c_array_initialization->set_variable_prefix(variable_prefix); |
70 | 614 |
if (globalinit_vf == wanted_varformat) |
615 |
globalnamespace = scope; |
|
616 |
||
617 |
finterface_var_count = 0; |
|
618 |
||
619 |
switch (wanted_varformat) { |
|
620 |
case constructorinit_vf: nv = new next_var_c("", "\n"+s4o.indent_spaces); break; |
|
621 |
case finterface_vf: /* fall through... */ |
|
622 |
case localinit_vf: /* fall through... */ |
|
623 |
case local_vf: nv = new next_var_c("", ", "); break; |
|
624 |
default: nv = NULL; |
|
625 |
} /* switch() */ |
|
626 |
||
627 |
symbol->accept(*this); |
|
628 |
||
629 |
/* special case... */ |
|
630 |
if (wanted_varformat == finterface_vf) |
|
631 |
if (finterface_var_count == 0) |
|
632 |
s4o.print("void"); |
|
633 |
||
634 |
delete nv; |
|
635 |
nv = NULL; |
|
636 |
globalnamespace = NULL; |
|
637 |
} |
|
638 |
||
639 |
||
640 |
protected: |
|
641 |
/***************************/ |
|
642 |
/* B 0 - Programming Model */ |
|
643 |
/***************************/ |
|
644 |
/* leave for derived classes... */ |
|
645 |
||
646 |
/*************************/ |
|
647 |
/* B.1 - Common elements */ |
|
648 |
/*************************/ |
|
649 |
/*******************************************/ |
|
650 |
/* B 1.1 - Letters, digits and identifiers */ |
|
651 |
/*******************************************/ |
|
652 |
/* done in base class(es) */ |
|
653 |
||
654 |
/*********************/ |
|
655 |
/* B 1.2 - Constants */ |
|
656 |
/*********************/ |
|
657 |
/* originally empty... */ |
|
658 |
||
659 |
/******************************/ |
|
660 |
/* B 1.2.1 - Numeric Literals */ |
|
661 |
/******************************/ |
|
662 |
/* done in base class(es) */ |
|
663 |
||
664 |
/*******************************/ |
|
665 |
/* B.1.2.2 Character Strings */ |
|
666 |
/*******************************/ |
|
667 |
/* done in base class(es) */ |
|
668 |
||
669 |
/***************************/ |
|
670 |
/* B 1.2.3 - Time Literals */ |
|
671 |
/***************************/ |
|
672 |
/************************/ |
|
673 |
/* B 1.2.3.1 - Duration */ |
|
674 |
/************************/ |
|
675 |
/* done in base class(es) */ |
|
676 |
||
677 |
/************************************/ |
|
678 |
/* B 1.2.3.2 - Time of day and Date */ |
|
679 |
/************************************/ |
|
680 |
/* done in base class(es) */ |
|
681 |
||
682 |
/**********************/ |
|
683 |
/* B.1.3 - Data types */ |
|
684 |
/**********************/ |
|
685 |
/***********************************/ |
|
686 |
/* B 1.3.1 - Elementary Data Types */ |
|
687 |
/***********************************/ |
|
688 |
/* done in base class(es) */ |
|
689 |
||
690 |
/********************************/ |
|
691 |
/* B.1.3.2 - Generic data types */ |
|
692 |
/********************************/ |
|
693 |
/* originally empty... */ |
|
694 |
||
695 |
/********************************/ |
|
696 |
/* B 1.3.3 - Derived data types */ |
|
697 |
/********************************/ |
|
698 |
/* done in base class(es) */ |
|
699 |
||
700 |
/*********************/ |
|
701 |
/* B 1.4 - Variables */ |
|
702 |
/*********************/ |
|
703 |
/* done in base class(es) */ |
|
704 |
||
705 |
/********************************************/ |
|
706 |
/* B.1.4.1 Directly Represented Variables */ |
|
707 |
/********************************************/ |
|
708 |
/* done in base class(es) */ |
|
709 |
||
710 |
/*************************************/ |
|
711 |
/* B.1.4.2 Multi-element Variables */ |
|
712 |
/*************************************/ |
|
713 |
/* done in base class(es) */ |
|
714 |
||
715 |
/******************************************/ |
|
716 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
717 |
/******************************************/ |
|
718 |
void *visit(constant_option_c *symbol) {s4o.print("CONSTANT"); return NULL;} |
|
719 |
void *visit(retain_option_c *symbol) {s4o.print("RETAIN"); return NULL;} |
|
720 |
void *visit(non_retain_option_c *symbol) {s4o.print("NON_RETAIN"); return NULL;} |
|
721 |
||
722 |
void *visit(input_declarations_c *symbol) { |
|
723 |
TRACE("input_declarations_c"); |
|
724 |
if ((wanted_vartype & input_vt) != 0) { |
|
725 |
/* |
|
726 |
// TO DO ... |
|
727 |
if (symbol->option != NULL) |
|
728 |
symbol->option->accept(*this); |
|
729 |
*/ |
|
730 |
//s4o.indent_right(); |
|
731 |
current_vartype = input_vt; |
|
732 |
symbol->input_declaration_list->accept(*this); |
|
733 |
current_vartype = none_vt; |
|
734 |
//s4o.indent_left(); |
|
735 |
} |
|
736 |
return NULL; |
|
737 |
} |
|
738 |
||
739 |
/* helper symbol for input_declarations */ |
|
740 |
void *visit(input_declaration_list_c *symbol) { |
|
741 |
TRACE("input_declaration_list_c"); |
|
742 |
print_list(symbol); |
|
743 |
return NULL; |
|
744 |
} |
|
745 |
||
746 |
void *visit(edge_declaration_c *symbol) { |
|
747 |
TRACE("edge_declaration_c"); |
|
748 |
// TO DO ... |
|
749 |
symbol->var1_list->accept(*this); |
|
750 |
s4o.print(" : BOOL "); |
|
751 |
symbol->edge->accept(*this); |
|
752 |
return NULL; |
|
753 |
} |
|
754 |
||
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
755 |
void *visit(en_param_declaration_c *symbol) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
756 |
TRACE("en_declaration_c"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
757 |
if (en_declared) ERROR; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
758 |
if (wanted_varformat == finterface_vf) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
759 |
finterface_var_count++; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
760 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
761 |
if ((current_vartype & eneno_vt) != 0) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
762 |
if (wanted_varformat == finterface_vf) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
763 |
s4o.print(nv->get()); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
764 |
s4o.print("\n" + s4o.indent_spaces + "BOOL EN"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
765 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
766 |
if (wanted_varformat == constructorinit_vf) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
767 |
s4o.print(nv->get()); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
768 |
this->print_variable_prefix(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
769 |
s4o.print("ENO = __BOOL_LITERAL(TRUE);"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
770 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
771 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
772 |
en_declared = true; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
773 |
return NULL; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
774 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
775 |
|
70 | 776 |
void *visit(raising_edge_option_c *symbol) { |
777 |
// TO DO ... |
|
778 |
s4o.print("R_EDGE"); |
|
779 |
return NULL; |
|
780 |
} |
|
781 |
||
98 | 782 |
/* var1_list ':' array_spec_init */ |
783 |
// SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
784 |
void *visit(array_var_init_decl_c *symbol) { |
|
785 |
TRACE("array_var_init_decl_c"); |
|
786 |
/* Please read the comments inside the var1_init_decl_c |
|
787 |
* visitor, as they apply here too. |
|
788 |
*/ |
|
789 |
||
790 |
/* Start off by setting the current_var_type_symbol and |
|
791 |
* current_var_init_symbol private variables... |
|
792 |
*/ |
|
793 |
update_type_init(symbol->array_spec_init); |
|
794 |
||
795 |
/* now to produce the c equivalent... */ |
|
796 |
if (wanted_varformat == constructorinit_vf) |
|
797 |
generate_c_array_initialization->init_array(symbol->var1_list, this->current_var_type_symbol, this->current_var_init_symbol); |
|
798 |
else |
|
799 |
symbol->var1_list->accept(*this); |
|
800 |
||
801 |
/* Values no longer in scope, and therefore no longer used. |
|
802 |
* Make an effort to keep them set to NULL when not in use |
|
803 |
* in order to catch bugs as soon as possible... |
|
804 |
*/ |
|
805 |
void_type_init(); |
|
806 |
||
807 |
return NULL; |
|
808 |
} |
|
70 | 809 |
|
810 |
/* var1_list ':' initialized_structure */ |
|
811 |
// SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
812 |
void *visit(structured_var_init_decl_c *symbol) { |
|
813 |
TRACE("structured_var_init_decl_c"); |
|
814 |
/* Please read the comments inside the var1_init_decl_c |
|
815 |
* visitor, as they apply here too. |
|
816 |
*/ |
|
817 |
||
818 |
/* Start off by setting the current_var_type_symbol and |
|
819 |
* current_var_init_symbol private variables... |
|
820 |
*/ |
|
821 |
update_type_init(symbol->initialized_structure); |
|
822 |
||
823 |
/* now to produce the c equivalent... */ |
|
824 |
symbol->var1_list->accept(*this); |
|
825 |
||
826 |
/* Values no longer in scope, and therefore no longer used. |
|
827 |
* Make an effort to keep them set to NULL when not in use |
|
828 |
* in order to catch bugs as soon as possible... |
|
829 |
*/ |
|
830 |
void_type_init(); |
|
831 |
||
832 |
return NULL; |
|
833 |
} |
|
834 |
||
835 |
/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
836 |
/* structure_initialization -> may be NULL ! */ |
|
837 |
void *visit(fb_name_decl_c *symbol) { |
|
838 |
TRACE("fb_name_decl_c"); |
|
839 |
/* Please read the comments inside the var1_init_decl_c |
|
840 |
* visitor, as they apply here too. |
|
841 |
*/ |
|
842 |
||
843 |
/* Start off by setting the current_var_type_symbol and |
|
844 |
* current_var_init_symbol private variables... |
|
845 |
*/ |
|
846 |
update_type_init(symbol); |
|
847 |
||
848 |
/* now to produce the c equivalent... */ |
|
849 |
symbol->fb_name_list->accept(*this); |
|
850 |
||
851 |
/* Values no longer in scope, and therefore no longer used. |
|
852 |
* Make an effort to keep them set to NULL when not in use |
|
853 |
* in order to catch bugs as soon as possible... |
|
854 |
*/ |
|
855 |
void_type_init(); |
|
856 |
||
857 |
return NULL; |
|
858 |
} |
|
859 |
||
860 |
/* fb_name_list ',' fb_name */ |
|
861 |
void *visit(fb_name_list_c *symbol) { |
|
862 |
TRACE("fb_name_list_c"); |
|
863 |
declare_variables(symbol, true); |
|
864 |
return NULL; |
|
865 |
} |
|
866 |
||
867 |
||
868 |
/* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
|
869 |
/* option -> may be NULL ! */ |
|
870 |
void *visit(output_declarations_c *symbol) { |
|
871 |
TRACE("output_declarations_c"); |
|
872 |
if ((wanted_vartype & output_vt) != 0) { |
|
873 |
/* |
|
874 |
// TO DO ... |
|
875 |
if (symbol->option != NULL) |
|
876 |
symbol->option->accept(*this); |
|
877 |
*/ |
|
878 |
//s4o.indent_right(); |
|
879 |
current_vartype = output_vt; |
|
880 |
symbol->var_init_decl_list->accept(*this); |
|
881 |
current_vartype = none_vt; |
|
882 |
//s4o.indent_left(); |
|
883 |
} |
|
884 |
return NULL; |
|
885 |
} |
|
886 |
||
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
887 |
void *visit(eno_param_declaration_c *symbol) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
888 |
TRACE("eno_declaration_c"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
889 |
if (eno_declared) ERROR; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
890 |
if (wanted_varformat == finterface_vf) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
891 |
finterface_var_count++; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
892 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
893 |
if ((current_vartype & eneno_vt) != 0) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
894 |
if (wanted_varformat == finterface_vf) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
895 |
s4o.print(nv->get()); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
896 |
s4o.print("\n" + s4o.indent_spaces + "BOOL *EN0"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
897 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
898 |
if (wanted_varformat == constructorinit_vf) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
899 |
s4o.print(nv->get()); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
900 |
this->print_variable_prefix(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
901 |
s4o.print("ENO = __BOOL_LITERAL(TRUE);"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
902 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
903 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
904 |
eno_declared = true; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
905 |
return NULL; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
906 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
907 |
|
70 | 908 |
/* VAR_IN_OUT var_declaration_list END_VAR */ |
909 |
void *visit(input_output_declarations_c *symbol) { |
|
910 |
TRACE("input_output_declarations_c"); |
|
911 |
if ((wanted_vartype & inoutput_vt) != 0) { |
|
912 |
//s4o.indent_right(); |
|
913 |
current_vartype = inoutput_vt; |
|
914 |
symbol->var_declaration_list->accept(*this); |
|
915 |
current_vartype = none_vt; |
|
916 |
//s4o.indent_left(); |
|
917 |
} |
|
918 |
return NULL; |
|
919 |
} |
|
920 |
||
921 |
/* helper symbol for input_output_declarations */ |
|
922 |
/* var_declaration_list var_declaration ';' */ |
|
923 |
void *visit(var_declaration_list_c *symbol) { |
|
924 |
TRACE("var_declaration_list_c"); |
|
925 |
print_list(symbol); |
|
926 |
return NULL; |
|
927 |
} |
|
928 |
||
929 |
#if 0 |
|
930 |
/* var1_list ':' array_specification */ |
|
931 |
SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
932 |
#endif |
|
933 |
||
98 | 934 |
void *visit(array_initial_elements_list_c *symbol) { |
935 |
s4o.print(";// array initialisation"); |
|
936 |
return NULL; |
|
937 |
} |
|
938 |
||
70 | 939 |
/* var1_list ':' structure_type_name */ |
940 |
//SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
941 |
void *visit(structured_var_declaration_c *symbol) { |
|
942 |
TRACE("structured_var_declaration_c"); |
|
943 |
/* Please read the comments inside the var1_init_decl_c |
|
944 |
* visitor, as they apply here too. |
|
945 |
*/ |
|
946 |
||
947 |
/* Start off by setting the current_var_type_symbol and |
|
948 |
* current_var_init_symbol private variables... |
|
949 |
*/ |
|
950 |
update_type_init(symbol->structure_type_name); |
|
951 |
||
952 |
/* now to produce the c equivalent... */ |
|
953 |
symbol->var1_list->accept(*this); |
|
954 |
||
955 |
/* Values no longer in scope, and therefore no longer used. |
|
956 |
* Make an effort to keep them set to NULL when not in use |
|
957 |
* in order to catch bugs as soon as possible... |
|
958 |
*/ |
|
959 |
void_type_init(); |
|
960 |
||
961 |
return NULL; |
|
962 |
} |
|
963 |
||
964 |
||
965 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
|
966 |
/* option -> may be NULL ! */ |
|
967 |
/* helper symbol for input_declarations */ |
|
968 |
void *visit(var_declarations_c *symbol) { |
|
969 |
TRACE("var_declarations_c"); |
|
970 |
if ((wanted_vartype & private_vt) != 0) { |
|
971 |
/* |
|
972 |
// TO DO ... |
|
973 |
if (symbol->option != NULL) |
|
974 |
symbol->option->accept(*this); |
|
975 |
*/ |
|
976 |
current_vartype = private_vt; |
|
977 |
symbol->var_init_decl_list->accept(*this); |
|
978 |
current_vartype = none_vt; |
|
979 |
} |
|
980 |
return NULL; |
|
981 |
} |
|
982 |
||
983 |
/* VAR RETAIN var_init_decl_list END_VAR */ |
|
984 |
void *visit(retentive_var_declarations_c *symbol) { |
|
985 |
TRACE("retentive_var_declarations_c"); |
|
986 |
if ((wanted_vartype & private_vt) != 0) { |
|
987 |
current_vartype = private_vt; |
|
988 |
symbol->var_init_decl_list->accept(*this); |
|
989 |
current_vartype = none_vt; |
|
990 |
} |
|
991 |
return NULL; |
|
992 |
} |
|
993 |
||
994 |
/* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ |
|
995 |
/* option -> may be NULL ! */ |
|
996 |
//SYM_REF2(located_var_declarations_c, option, located_var_decl_list) |
|
997 |
void *visit(located_var_declarations_c *symbol) { |
|
998 |
TRACE("located_var_declarations_c"); |
|
999 |
if ((wanted_vartype & located_vt) != 0) { |
|
1000 |
/* |
|
1001 |
// TO DO ... |
|
1002 |
if (symbol->option != NULL) |
|
1003 |
symbol->option->accept(*this); |
|
1004 |
*/ |
|
1005 |
current_vartype = located_vt; |
|
1006 |
symbol->located_var_decl_list->accept(*this); |
|
1007 |
current_vartype = none_vt; |
|
1008 |
} |
|
1009 |
return NULL; |
|
1010 |
} |
|
1011 |
||
1012 |
/* helper symbol for located_var_declarations */ |
|
1013 |
/* located_var_decl_list located_var_decl ';' */ |
|
1014 |
//SYM_LIST(located_var_decl_list_c) |
|
1015 |
void *visit(located_var_decl_list_c *symbol) { |
|
1016 |
TRACE("located_var_decl_list_c"); |
|
1017 |
print_list(symbol); |
|
1018 |
return NULL; |
|
1019 |
} |
|
1020 |
||
1021 |
||
1022 |
/* [variable_name] location ':' located_var_spec_init */ |
|
1023 |
/* variable_name -> may be NULL ! */ |
|
1024 |
//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
1025 |
void *visit(located_var_decl_c *symbol) { |
|
1026 |
TRACE("located_var_decl_c"); |
|
1027 |
/* Please read the comments inside the var1_init_decl_c |
|
1028 |
* visitor, as they apply here too. |
|
1029 |
*/ |
|
1030 |
||
1031 |
/* Start off by setting the current_var_type_symbol and |
|
1032 |
* current_var_init_symbol private variables... |
|
1033 |
*/ |
|
1034 |
update_type_init(symbol->located_var_spec_init); |
|
1035 |
||
1036 |
/* now to produce the c equivalent... */ |
|
1037 |
switch(wanted_varformat) { |
|
1038 |
case local_vf: |
|
1039 |
s4o.print(s4o.indent_spaces); |
|
1040 |
this->current_var_type_symbol->accept(*this); |
|
1041 |
s4o.print(" *"); |
|
1042 |
if (symbol->variable_name != NULL) |
|
1043 |
symbol->variable_name->accept(*this); |
|
1044 |
else |
|
1045 |
symbol->location->accept(*this); |
|
1046 |
s4o.print(";\n"); |
|
1047 |
break; |
|
1048 |
||
1049 |
case constructorinit_vf: |
|
1050 |
s4o.print(nv->get()); |
|
1051 |
s4o.print("{extern "); |
|
1052 |
this->current_var_type_symbol->accept(*this); |
|
122 | 1053 |
s4o.print("* "); |
70 | 1054 |
symbol->location->accept(*this); |
1055 |
s4o.print("; "); |
|
1056 |
print_variable_prefix(); |
|
1057 |
if (symbol->variable_name != NULL) |
|
1058 |
symbol->variable_name->accept(*this); |
|
1059 |
else |
|
1060 |
symbol->location->accept(*this); |
|
122 | 1061 |
s4o.print(" = "); |
70 | 1062 |
symbol->location->accept(*this); |
1063 |
s4o.print(";}"); |
|
1064 |
break; |
|
1065 |
||
1066 |
case globalinit_vf: |
|
1067 |
s4o.print(s4o.indent_spaces + "__plc_pt_c<"); |
|
1068 |
this->current_var_type_symbol->accept(*this); |
|
1069 |
s4o.print(", 8*sizeof("); |
|
1070 |
this->current_var_type_symbol->accept(*this); |
|
1071 |
s4o.print(")> "); |
|
1072 |
if (this->globalnamespace != NULL) { |
|
1073 |
this->globalnamespace->accept(*this); |
|
1074 |
s4o.print("::"); |
|
1075 |
} |
|
1076 |
if (symbol->variable_name != NULL) |
|
1077 |
symbol->variable_name->accept(*this); |
|
1078 |
else |
|
1079 |
symbol->location->accept(*this); |
|
1080 |
||
1081 |
s4o.print(" = "); |
|
1082 |
||
1083 |
s4o.print(s4o.indent_spaces + "__plc_pt_c<"); |
|
1084 |
this->current_var_type_symbol->accept(*this); |
|
1085 |
s4o.print(", 8*sizeof("); |
|
1086 |
this->current_var_type_symbol->accept(*this); |
|
1087 |
s4o.print(")>(\""); |
|
1088 |
symbol->location->accept(*this); |
|
1089 |
s4o.print("\""); |
|
1090 |
if (this->current_var_init_symbol != NULL) { |
|
1091 |
s4o.print(", "); |
|
1092 |
this->current_var_init_symbol->accept(*this); |
|
1093 |
} |
|
1094 |
s4o.print(");\n"); |
|
1095 |
break; |
|
1096 |
||
1097 |
default: |
|
1098 |
ERROR; |
|
1099 |
} /* switch() */ |
|
1100 |
||
1101 |
/* Values no longer in scope, and therefore no longer used. |
|
1102 |
* Make an effort to keep them set to NULL when not in use |
|
1103 |
* in order to catch bugs as soon as possible... |
|
1104 |
*/ |
|
1105 |
void_type_init(); |
|
1106 |
||
1107 |
return NULL; |
|
1108 |
} |
|
1109 |
||
1110 |
||
1111 |
||
1112 |
||
1113 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
1114 |
/* option -> may be NULL ! */ |
|
1115 |
//SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
1116 |
void *visit(external_var_declarations_c *symbol) { |
|
1117 |
TRACE("external_var_declarations_c"); |
|
1118 |
if ((wanted_vartype & external_vt) != 0) { |
|
1119 |
/* |
|
1120 |
// TODO ... |
|
1121 |
if (symbol->option != NULL) |
|
1122 |
symbol->option->accept(*this); |
|
1123 |
*/ |
|
1124 |
//s4o.indent_right(); |
|
1125 |
current_vartype = external_vt; |
|
1126 |
symbol->external_declaration_list->accept(*this); |
|
1127 |
current_vartype = none_vt; |
|
1128 |
//s4o.indent_left(); |
|
1129 |
} |
|
1130 |
return NULL; |
|
1131 |
} |
|
1132 |
||
1133 |
/* helper symbol for external_var_declarations */ |
|
1134 |
/*| external_declaration_list external_declaration';' */ |
|
1135 |
//SYM_LIST(external_declaration_list_c) |
|
1136 |
/* helper symbol for input_declarations */ |
|
1137 |
void *visit(external_declaration_list_c *symbol) { |
|
1138 |
TRACE("external_declaration_list_c"); |
|
1139 |
print_list(symbol); |
|
1140 |
return NULL; |
|
1141 |
} |
|
1142 |
||
1143 |
||
1144 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
1145 |
//SYM_REF2(external_declaration_c, global_var_name, specification) |
|
1146 |
void *visit(external_declaration_c *symbol) { |
|
1147 |
TRACE("external_declaration_c"); |
|
1148 |
/* Please read the comments inside the var1_init_decl_c |
|
1149 |
* visitor, as they apply here too. |
|
1150 |
*/ |
|
1151 |
||
1152 |
/* Start off by setting the current_var_type_symbol and |
|
1153 |
* current_var_init_symbol private variables... |
|
1154 |
*/ |
|
1155 |
this->current_var_type_symbol = symbol->specification; |
|
1156 |
this->current_var_init_symbol = NULL; |
|
1157 |
||
1158 |
/* now to produce the c equivalent... */ |
|
1159 |
switch (wanted_varformat) { |
|
1160 |
case local_vf: |
|
1161 |
case localinit_vf: |
|
1162 |
s4o.print(s4o.indent_spaces); |
|
1163 |
this->current_var_type_symbol->accept(*this); |
|
1164 |
s4o.print(" *"); |
|
1165 |
symbol->global_var_name->accept(*this); |
|
1166 |
if ((wanted_varformat == localinit_vf) && |
|
1167 |
(this->current_var_init_symbol != NULL)) { |
|
1168 |
s4o.print(" = "); |
|
1169 |
this->current_var_init_symbol->accept(*this); |
|
1170 |
} |
|
1171 |
s4o.print(";\n"); |
|
1172 |
break; |
|
1173 |
||
1174 |
case constructorinit_vf: |
|
1175 |
s4o.print(nv->get()); |
|
1176 |
s4o.print("{extern "); |
|
1177 |
this->current_var_type_symbol->accept(*this); |
|
1178 |
s4o.print(" *"); |
|
1179 |
symbol->global_var_name->accept(*this); |
|
1180 |
s4o.print("; "); |
|
1181 |
print_variable_prefix(); |
|
1182 |
symbol->global_var_name->accept(*this); |
|
1183 |
s4o.print(" = "); |
|
1184 |
symbol->global_var_name->accept(*this); |
|
1185 |
s4o.print(";}"); |
|
1186 |
break; |
|
1187 |
||
1188 |
case finterface_vf: |
|
1189 |
finterface_var_count++; |
|
1190 |
s4o.print(nv->get()); |
|
1191 |
this->current_var_type_symbol->accept(*this); |
|
1192 |
s4o.print(" *"); |
|
1193 |
symbol->global_var_name->accept(*this); |
|
1194 |
break; |
|
1195 |
||
1196 |
default: |
|
1197 |
ERROR; |
|
1198 |
} |
|
1199 |
||
1200 |
/* Values no longer in scope, and therefore no longer used. |
|
1201 |
* Make an effort to keep them set to NULL when not in use |
|
1202 |
* in order to catch bugs as soon as possible... |
|
1203 |
*/ |
|
1204 |
void_type_init(); |
|
1205 |
||
1206 |
return NULL; |
|
1207 |
} |
|
1208 |
||
1209 |
||
1210 |
||
1211 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
1212 |
/* option -> may be NULL ! */ |
|
1213 |
// SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
1214 |
void *visit(global_var_declarations_c *symbol) { |
|
1215 |
TRACE("global_var_declarations_c"); |
|
1216 |
if ((wanted_vartype & global_vt) != 0) { |
|
1217 |
/* |
|
1218 |
// TODO ... |
|
1219 |
if (symbol->option != NULL) |
|
1220 |
symbol->option->accept(*this); |
|
1221 |
*/ |
|
1222 |
//s4o.indent_right(); |
|
1223 |
unsigned int previous_vartype = current_vartype; |
|
1224 |
// previous_vartype will be either none_vt, or resource_vt |
|
1225 |
current_vartype = global_vt; |
|
1226 |
symbol->global_var_decl_list->accept(*this); |
|
1227 |
current_vartype = previous_vartype; |
|
1228 |
//s4o.indent_left(); |
|
1229 |
} |
|
1230 |
return NULL; |
|
1231 |
} |
|
1232 |
||
1233 |
/* helper symbol for global_var_declarations */ |
|
1234 |
/*| global_var_decl_list global_var_decl ';' */ |
|
1235 |
//SYM_LIST(global_var_decl_list_c) |
|
1236 |
void *visit(global_var_decl_list_c *symbol) { |
|
1237 |
TRACE("global_var_decl_list_c"); |
|
1238 |
print_list(symbol); |
|
1239 |
return NULL; |
|
1240 |
} |
|
1241 |
||
1242 |
||
1243 |
||
1244 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
1245 |
/* type_specification ->may be NULL ! */ |
|
1246 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
1247 |
void *visit(global_var_decl_c *symbol) { |
|
1248 |
TRACE("global_var_decl_c"); |
|
1249 |
/* Please read the comments inside the var1_init_decl_c |
|
1250 |
* visitor, as they apply here too. |
|
1251 |
*/ |
|
1252 |
||
1253 |
/* Start off by setting the current_var_type_symbol and |
|
1254 |
* current_var_init_symbol private variables... |
|
1255 |
*/ |
|
1256 |
update_type_init(symbol->type_specification); |
|
1257 |
||
1258 |
/* now to produce the c equivalent... */ |
|
1259 |
symbol->global_var_spec->accept(*this); |
|
1260 |
||
1261 |
/* Values no longer in scope, and therefore no longer used. |
|
1262 |
* Make an effort to keep them set to NULL when not in use |
|
1263 |
* in order to catch bugs as soon as possible... |
|
1264 |
*/ |
|
1265 |
void_type_init(); |
|
1266 |
||
1267 |
return NULL; |
|
1268 |
} |
|
1269 |
||
1270 |
||
1271 |
/*| global_var_name location */ |
|
1272 |
// SYM_REF2(global_var_spec_c, global_var_name, location) |
|
1273 |
void *visit(global_var_spec_c *symbol) { |
|
1274 |
TRACE("global_var_spec_c"); |
|
1275 |
||
1276 |
/* now to produce the c equivalent... */ |
|
1277 |
switch(wanted_varformat) { |
|
1278 |
case local_vf: |
|
1279 |
s4o.print(s4o.indent_spaces); |
|
1280 |
if (symbol->global_var_name != NULL) { |
|
1281 |
s4o.print("extern "); |
|
1282 |
this->current_var_type_symbol->accept(*this); |
|
122 | 1283 |
s4o.print("* "); |
70 | 1284 |
symbol->location->accept(*this); |
1285 |
s4o.print(";\n"); |
|
1286 |
this->current_var_type_symbol->accept(*this); |
|
1287 |
s4o.print(" *"); |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1288 |
if (this->resource_name != NULL) { |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1289 |
this->resource_name->accept(*this); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1290 |
s4o.print("__"); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1291 |
} |
70 | 1292 |
symbol->global_var_name->accept(*this); |
1293 |
s4o.print(";\n"); |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1294 |
if (this->resource_name != NULL) { |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1295 |
s4o.print("#define "); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1296 |
symbol->global_var_name->accept(*this); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1297 |
s4o.print(" "); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1298 |
this->resource_name->accept(*this); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1299 |
s4o.print("__"); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1300 |
symbol->global_var_name->accept(*this); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1301 |
s4o.print("\n"); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1302 |
} |
70 | 1303 |
} |
1304 |
break; |
|
1305 |
||
1306 |
case constructorinit_vf: |
|
1307 |
s4o.print(nv->get()); |
|
1308 |
||
1309 |
if (symbol->global_var_name != NULL) { |
|
128
fd5760f30682
Changed located global variable declaration and init to reflec recent change on located vars (pointers)
etisserant
parents:
122
diff
changeset
|
1310 |
symbol->global_var_name->accept(*this); |
fd5760f30682
Changed located global variable declaration and init to reflec recent change on located vars (pointers)
etisserant
parents:
122
diff
changeset
|
1311 |
s4o.print(" = "); |
fd5760f30682
Changed located global variable declaration and init to reflec recent change on located vars (pointers)
etisserant
parents:
122
diff
changeset
|
1312 |
symbol->location->accept(*this); |
fd5760f30682
Changed located global variable declaration and init to reflec recent change on located vars (pointers)
etisserant
parents:
122
diff
changeset
|
1313 |
s4o.print(";"); |
fd5760f30682
Changed located global variable declaration and init to reflec recent change on located vars (pointers)
etisserant
parents:
122
diff
changeset
|
1314 |
s4o.print(nv->get()); |
fd5760f30682
Changed located global variable declaration and init to reflec recent change on located vars (pointers)
etisserant
parents:
122
diff
changeset
|
1315 |
s4o.print("*"); |
70 | 1316 |
symbol->global_var_name->accept(*this); |
1317 |
} |
|
1318 |
else |
|
1319 |
symbol->location->accept(*this); |
|
1320 |
s4o.print(" = "); |
|
1321 |
if (this->current_var_init_symbol != NULL) { |
|
1322 |
this->current_var_init_symbol->accept(*this); |
|
1323 |
} |
|
1324 |
s4o.print(";"); |
|
1325 |
break; |
|
1326 |
||
1327 |
default: |
|
1328 |
ERROR; |
|
1329 |
} /* switch() */ |
|
1330 |
||
1331 |
return NULL; |
|
1332 |
} |
|
1333 |
||
1334 |
||
1335 |
||
1336 |
/* AT direct_variable */ |
|
1337 |
// SYM_REF2(location_c, direct_variable, unused) |
|
1338 |
void *visit(location_c *symbol) { |
|
1339 |
TRACE("location_c"); |
|
1340 |
return symbol->direct_variable->accept(*this); |
|
1341 |
} |
|
1342 |
||
1343 |
||
1344 |
/*| global_var_list ',' global_var_name */ |
|
1345 |
//SYM_LIST(global_var_list_c) |
|
1346 |
void *visit(global_var_list_c *symbol) { |
|
1347 |
TRACE("global_var_list_c"); |
|
1348 |
list_c *list = dynamic_cast<list_c *>(symbol); |
|
1349 |
/* should NEVER EVER occur!! */ |
|
1350 |
if (list == NULL) ERROR; |
|
1351 |
||
1352 |
/* now to produce the c equivalent... */ |
|
1353 |
switch (wanted_varformat) { |
|
1354 |
case local_vf: |
|
1355 |
case localinit_vf: |
|
1356 |
for(int i = 0; i < list->n; i++) { |
|
1357 |
s4o.print(s4o.indent_spaces); |
|
1358 |
this->current_var_type_symbol->accept(*this); |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1359 |
s4o.print(" "); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1360 |
if(this->resource_name != NULL) |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1361 |
this->resource_name->accept(*this); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1362 |
s4o.print("__"); |
70 | 1363 |
list->elements[i]->accept(*this); |
1364 |
s4o.print(";\n"); |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1365 |
if(this->resource_name != NULL) |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1366 |
s4o.print("static "); |
70 | 1367 |
this->current_var_type_symbol->accept(*this); |
1368 |
s4o.print(" *"); |
|
1369 |
list->elements[i]->accept(*this); |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1370 |
s4o.print(" = &"); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1371 |
if(this->resource_name != NULL) |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1372 |
this->resource_name->accept(*this); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1373 |
s4o.print("__"); |
70 | 1374 |
list->elements[i]->accept(*this); |
1375 |
#if 0 |
|
1376 |
if (wanted_varformat == localinit_vf) { |
|
1377 |
if (this->current_var_init_symbol != NULL) { |
|
1378 |
s4o.print(" = "); |
|
1379 |
this->current_var_init_symbol->accept(*this); |
|
1380 |
} |
|
1381 |
} |
|
1382 |
#endif |
|
1383 |
s4o.print(";\n"); |
|
1384 |
} |
|
1385 |
break; |
|
1386 |
||
1387 |
case constructorinit_vf: |
|
1388 |
if (this->current_var_init_symbol != NULL) { |
|
1389 |
for(int i = 0; i < list->n; i++) { |
|
1390 |
s4o.print(nv->get()); |
|
1391 |
||
1392 |
s4o.print("*"); |
|
1393 |
list->elements[i]->accept(*this); |
|
1394 |
s4o.print(" = "); |
|
1395 |
this->current_var_init_symbol->accept(*this); |
|
1396 |
s4o.print(";"); |
|
1397 |
#if 0 |
|
1398 |
/* The following code would be for globalinit_vf !! |
|
1399 |
* But it is not currently required... |
|
1400 |
*/ |
|
1401 |
s4o.print(s4o.indent_spaces + "__ext_element_c<"); |
|
1402 |
this->current_var_type_symbol->accept(*this); |
|
1403 |
s4o.print("> "); |
|
1404 |
if (this->globalnamespace != NULL) { |
|
1405 |
this->globalnamespace->accept(*this); |
|
1406 |
s4o.print("::"); |
|
1407 |
} |
|
1408 |
list->elements[i]->accept(*this); |
|
1409 |
||
1410 |
if (this->current_var_init_symbol != NULL) { |
|
1411 |
s4o.print(" = "); |
|
1412 |
s4o.print("__ext_element_c<"); |
|
1413 |
this->current_var_type_symbol->accept(*this); |
|
1414 |
s4o.print(">("); |
|
1415 |
this->current_var_init_symbol->accept(*this); |
|
1416 |
s4o.print(")"); |
|
1417 |
} |
|
1418 |
s4o.print(";\n"); |
|
1419 |
#endif |
|
1420 |
} |
|
1421 |
} |
|
1422 |
break; |
|
1423 |
||
1424 |
default: |
|
1425 |
ERROR; /* not supported, and not needed either... */ |
|
1426 |
} |
|
1427 |
||
1428 |
return NULL; |
|
1429 |
} |
|
1430 |
||
1431 |
||
1432 |
#if 0 |
|
1433 |
/* var1_list ':' single_byte_string_spec */ |
|
1434 |
SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
1435 |
||
1436 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
1437 |
/* integer ->may be NULL ! */ |
|
1438 |
/* single_byte_character_string ->may be NULL ! */ |
|
1439 |
SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
1440 |
||
1441 |
/* var1_list ':' double_byte_string_spec */ |
|
1442 |
SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
1443 |
||
1444 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
1445 |
/* integer ->may be NULL ! */ |
|
1446 |
/* double_byte_character_string ->may be NULL ! */ |
|
1447 |
SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
1448 |
||
1449 |
/*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ |
|
1450 |
/* option ->may be NULL ! */ |
|
1451 |
SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list) |
|
1452 |
||
1453 |
/* helper symbol for incompl_located_var_declarations */ |
|
1454 |
/*| incompl_located_var_decl_list incompl_located_var_decl ';' */ |
|
1455 |
SYM_LIST(incompl_located_var_decl_list_c) |
|
1456 |
||
1457 |
/* variable_name incompl_location ':' var_spec */ |
|
1458 |
SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
1459 |
||
1460 |
/* AT incompl_location_token */ |
|
1461 |
SYM_TOKEN(incompl_location_c) |
|
1462 |
#endif |
|
1463 |
||
1464 |
||
1465 |
void *visit(falling_edge_option_c *symbol) { |
|
1466 |
// TO DO ... |
|
1467 |
s4o.print("F_EDGE"); |
|
1468 |
return NULL; |
|
1469 |
} |
|
1470 |
||
1471 |
||
1472 |
void *visit(var1_init_decl_c *symbol) { |
|
1473 |
TRACE("var1_init_decl_c"); |
|
1474 |
/* We have several implementation alternatives here... |
|
1475 |
* |
|
1476 |
* The issue is that generation of c code |
|
1477 |
* based on the abstract syntax tree requires the reversal |
|
1478 |
* of the symbol order compared to st. For e.g.: |
|
1479 |
* (ST) a, b, c: INT := 98; |
|
1480 |
* (C ) int a=98, b=98, c=98; |
|
1481 |
* The spec_init contains the references to 'INT' and '98'. |
|
1482 |
* The var1_list contains the references to 'a', 'b', and 'c'. |
|
1483 |
* The var1_init_decl_c contains the references to spec_init and var1_list. |
|
1484 |
* |
|
1485 |
* For c code generation, the var1_init_decl_c visitor |
|
1486 |
* would need to access the internals of other classes |
|
1487 |
* (e.g. the simple_spec_init_c). |
|
1488 |
* |
|
1489 |
* We can do this using one of three methods: |
|
1490 |
* 1) Create the abstract syntax tree differently; |
|
1491 |
* 2) Access other classes from within the var1_init_decl_c; |
|
1492 |
* 3) Pass info between the visitors using global variables |
|
1493 |
* only acessible by this class (private vars) |
|
1494 |
* |
|
1495 |
* In 1), the abstract syntax tree would be built so that |
|
1496 |
* var1_init_decl_c would contain direct references to |
|
1497 |
* var1_list_c, to the var type 'INT' and to the initialiser '98' |
|
1498 |
* (as per the example above). |
|
1499 |
* |
|
1500 |
* 2) would have several sub-options to obtain the references |
|
1501 |
* to 'INT' and '98' from within var1_init_decl_c. |
|
1502 |
* In 2a), the var1_init_decl_c would use dynamic casts to determine |
|
1503 |
* the class of spec_init (simple_spec_init_c, subrange_spec_init_c or |
|
1504 |
* enumerated_spec_init_c), and from there obtain the 'INT' and '98' |
|
1505 |
* In 2b) var1_init_decl_c would have one reference for each |
|
1506 |
* simple_spec_init_c, subrange_spec_init_c and enumerated_spec_init_c, |
|
1507 |
* the apropriate one being initialised by the var1_init_decl_c constructor. |
|
1508 |
* Note that the constructor would use dynamic casts. In essence, we |
|
1509 |
* would merely be changing the location of the code with the |
|
1510 |
* dynamic casts. |
|
1511 |
* In 2c) we would use three overloaded constructors for var1_init_decl_c |
|
1512 |
* one each for simple_spec_init_c, etc... This implies |
|
1513 |
* use type specific pointers to each symbol in the bison |
|
1514 |
* parser, instead of simply using a symbol_c * for all symbols; |
|
1515 |
* |
|
1516 |
* In 3), we use two global but private variables with references to |
|
1517 |
* 'INT' and '98', that would be initiliased by the visitors to |
|
1518 |
* simple_spec_init_c, subrange_spec_init_c and enumerated_spec_init_c. |
|
1519 |
* The visitor to var1_list_c would then use the references in the global |
|
1520 |
* variables. |
|
1521 |
* |
|
1522 |
* I (Mario) have chosen to use 3). |
|
1523 |
*/ |
|
1524 |
||
1525 |
/* Start off by setting the current_var_type_symbol and |
|
1526 |
* current_var_init_symbol private variables... |
|
1527 |
*/ |
|
1528 |
update_type_init(symbol->spec_init); |
|
1529 |
||
1530 |
/* now to produce the c equivalent... */ |
|
1531 |
symbol->var1_list->accept(*this); |
|
1532 |
||
1533 |
/* Values no longer in scope, and therefore no longer used. |
|
1534 |
* Make an effort to keep them set to NULL when not in use |
|
1535 |
* in order to catch bugs as soon as possible... |
|
1536 |
*/ |
|
1537 |
void_type_init(); |
|
1538 |
||
1539 |
return NULL; |
|
1540 |
} |
|
1541 |
||
1542 |
||
1543 |
||
1544 |
void *visit(var1_list_c *symbol) { |
|
1545 |
TRACE("var1_list_c"); |
|
1546 |
declare_variables(symbol); |
|
1547 |
return NULL; |
|
1548 |
} |
|
1549 |
||
1550 |
||
1551 |
||
1552 |
||
1553 |
/* intermediate helper symbol for: |
|
1554 |
* - non_retentive_var_decls |
|
1555 |
* - output_declarations |
|
1556 |
*/ |
|
1557 |
void *visit(var_init_decl_list_c *symbol) { |
|
1558 |
TRACE("var_init_decl_list_c"); |
|
1559 |
return print_list(symbol); |
|
1560 |
return NULL; |
|
1561 |
} |
|
1562 |
||
1563 |
||
1564 |
/**************************************/ |
|
1565 |
/* B.1.5 - Program organization units */ |
|
1566 |
/**************************************/ |
|
1567 |
/***********************/ |
|
1568 |
/* B 1.5.1 - Functions */ |
|
1569 |
/***********************/ |
|
1570 |
/* The missing function_declaration_c |
|
1571 |
* is handled in derived classes |
|
1572 |
*/ |
|
1573 |
||
1574 |
||
1575 |
||
1576 |
/* intermediate helper symbol for function_declaration */ |
|
1577 |
void *visit(var_declarations_list_c *symbol) { |
|
1578 |
TRACE("var_declarations_list_c"); |
|
1579 |
return print_list(symbol); |
|
1580 |
} |
|
1581 |
||
1582 |
||
1583 |
void *visit(function_var_decls_c *symbol) { |
|
1584 |
TRACE("function_var_decls_c"); |
|
1585 |
||
1586 |
if ((wanted_vartype & private_vt) != 0) { |
|
1587 |
/* |
|
1588 |
// TO DO ... |
|
1589 |
if (symbol->option != NULL) |
|
1590 |
symbol->option->accept(*this); |
|
1591 |
*/ |
|
1592 |
current_vartype = private_vt; |
|
1593 |
symbol->decl_list->accept(*this); |
|
1594 |
current_vartype = none_vt; |
|
1595 |
} |
|
1596 |
return NULL; |
|
1597 |
} |
|
1598 |
||
1599 |
||
1600 |
/* intermediate helper symbol for function_var_decls */ |
|
1601 |
void *visit(var2_init_decl_list_c *symbol) { |
|
1602 |
TRACE("var2_init_decl_list_c"); |
|
1603 |
print_list(symbol); |
|
1604 |
return NULL; |
|
1605 |
} |
|
1606 |
||
1607 |
||
1608 |
/*****************************/ |
|
1609 |
/* B 1.5.2 - Function Blocks */ |
|
1610 |
/*****************************/ |
|
1611 |
||
1612 |
/* The missing function_block_declaration_c |
|
1613 |
* is handled in derived classes |
|
1614 |
*/ |
|
1615 |
||
1616 |
||
1617 |
/* VAR_TEMP temp_var_decl_list END_VAR */ |
|
1618 |
void *visit(temp_var_decls_c *symbol) { |
|
1619 |
TRACE("temp_var_decls_c"); |
|
1620 |
if ((wanted_vartype & temp_vt) != 0) { |
|
1621 |
current_vartype = temp_vt; |
|
1622 |
symbol->var_decl_list->accept(*this); |
|
1623 |
current_vartype = none_vt; |
|
1624 |
} |
|
1625 |
return NULL; |
|
1626 |
} |
|
1627 |
||
1628 |
/* intermediate helper symbol for temp_var_decls */ |
|
1629 |
void *visit(temp_var_decls_list_c *symbol) { |
|
1630 |
TRACE("temp_var_decls_list_c"); |
|
1631 |
return print_list(symbol); |
|
1632 |
} |
|
1633 |
||
1634 |
/* VAR NON_RETAIN var_init_decl_list END_VAR */ |
|
1635 |
void *visit(non_retentive_var_decls_c *symbol) { |
|
1636 |
TRACE("non_retentive_var_decls_c"); |
|
1637 |
// TODO ... guarantee the non-retain semantics! |
|
1638 |
if ((wanted_vartype & private_vt) != 0) { |
|
1639 |
current_vartype = private_vt; |
|
1640 |
symbol->var_decl_list->accept(*this); |
|
1641 |
current_vartype = none_vt; |
|
1642 |
} |
|
1643 |
return NULL; |
|
1644 |
} |
|
1645 |
||
1646 |
||
1647 |
||
1648 |
/**********************/ |
|
1649 |
/* B 1.5.3 - Programs */ |
|
1650 |
/**********************/ |
|
1651 |
/* leave for derived classes... */ |
|
1652 |
||
1653 |
/*********************************************/ |
|
1654 |
/* B.1.6 Sequential function chart elements */ |
|
1655 |
/*********************************************/ |
|
1656 |
||
1657 |
/********************************/ |
|
1658 |
/* B 1.7 Configuration elements */ |
|
1659 |
/********************************/ |
|
1660 |
/* Programs instantiated inside configurations are declared as variables!! */ |
|
1661 |
||
1662 |
/* |
|
1663 |
CONFIGURATION configuration_name |
|
1664 |
optional_global_var_declarations |
|
1665 |
(resource_declaration_list | single_resource_declaration) |
|
1666 |
optional_access_declarations |
|
1667 |
optional_instance_specific_initializations |
|
1668 |
END_CONFIGURATION |
|
1669 |
*/ |
|
1670 |
/* |
|
1671 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
1672 |
*/ |
|
1673 |
void *visit(configuration_declaration_c *symbol) { |
|
1674 |
TRACE("configuration_declaration_c"); |
|
1675 |
||
1676 |
if(symbol->global_var_declarations) |
|
1677 |
symbol->global_var_declarations->accept(*this); // will contain VAR_GLOBAL declarations!! |
|
1678 |
symbol->resource_declarations->accept(*this); // will contain PROGRAM declarations!! |
|
1679 |
return NULL; |
|
1680 |
} |
|
1681 |
||
1682 |
||
1683 |
/* helper symbol for configuration_declaration */ |
|
1684 |
// SYM_LIST(resource_declaration_list_c) |
|
1685 |
void *visit(resource_declaration_list_c *symbol) { |
|
1686 |
TRACE("resource_declaration_list_c"); |
|
1687 |
||
1688 |
return print_list(symbol); |
|
1689 |
} |
|
1690 |
||
1691 |
/* |
|
1692 |
RESOURCE resource_name ON resource_type_name |
|
1693 |
optional_global_var_declarations |
|
1694 |
single_resource_declaration |
|
1695 |
END_RESOURCE |
|
1696 |
*/ |
|
1697 |
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
1698 |
void *visit(resource_declaration_c *symbol) { |
|
1699 |
TRACE("resource_declaration_c"); |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1700 |
//// Not used anymore. Even resource list are processed as single resource |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1701 |
// if ((wanted_vartype & resource_vt) != 0) { |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1702 |
// s4o.print(s4o.indent_spaces + "struct {\n"); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1703 |
// s4o.indent_right(); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1704 |
// |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1705 |
// current_vartype = resource_vt; |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1706 |
// if (NULL != symbol->global_var_declarations) |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1707 |
// symbol->global_var_declarations->accept(*this); // will contain VAR_GLOBAL declarations!! |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1708 |
// if (NULL != symbol->resource_declaration) |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1709 |
// symbol->resource_declaration->accept(*this); // will contain PROGRAM declarations!! |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1710 |
// current_vartype = none_vt; |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1711 |
// |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1712 |
// s4o.indent_left(); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1713 |
// s4o.print(s4o.indent_spaces + "} "); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1714 |
// symbol->resource_name->accept(*this); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1715 |
// s4o.print(";\n"); |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
1716 |
// } |
70 | 1717 |
return NULL; |
1718 |
} |
|
1719 |
||
1720 |
/* task_configuration_list program_configuration_list */ |
|
1721 |
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
1722 |
void *visit(single_resource_declaration_c *symbol) { |
|
1723 |
TRACE("single_resource_declaration_c"); |
|
1724 |
||
1725 |
if ((wanted_vartype & program_vt) != 0) { |
|
1726 |
unsigned int previous_vartype = current_vartype; |
|
1727 |
// previous_vartype will be resource_vt |
|
1728 |
current_vartype = program_vt; |
|
1729 |
symbol->program_configuration_list->accept(*this); |
|
1730 |
current_vartype = previous_vartype; |
|
1731 |
} |
|
1732 |
return NULL; |
|
1733 |
} |
|
1734 |
||
1735 |
||
1736 |
/* helper symbol for single_resource_declaration */ |
|
1737 |
// SYM_LIST(task_configuration_list_c) |
|
1738 |
||
1739 |
||
1740 |
/* helper symbol for single_resource_declaration */ |
|
1741 |
/* | program_configuration_list program_configuration ';' */ |
|
1742 |
// SYM_LIST(program_configuration_list_c) |
|
1743 |
void *visit(program_configuration_list_c *symbol) { |
|
1744 |
TRACE("program_configuration_list_c"); |
|
1745 |
||
1746 |
return print_list(symbol); |
|
1747 |
} |
|
1748 |
||
1749 |
/* helper symbol for |
|
1750 |
* - access_path |
|
1751 |
* - instance_specific_init |
|
1752 |
*/ |
|
1753 |
// SYM_LIST(any_fb_name_list_c) |
|
1754 |
||
1755 |
/* [resource_name '.'] global_var_name ['.' structure_element_name] */ |
|
1756 |
// SYM_REF4(global_var_reference_c, resource_name, global_var_name, structure_element_name, unused) |
|
1757 |
||
1758 |
/* prev_declared_program_name '.' symbolic_variable */ |
|
1759 |
// SYM_REF2(program_output_reference_c, program_name, symbolic_variable) |
|
1760 |
||
1761 |
/* TASK task_name task_initialization */ |
|
1762 |
// SYM_REF2(task_configuration_c, task_name, task_initialization) |
|
1763 |
||
1764 |
/* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */ |
|
1765 |
// SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused) |
|
1766 |
||
1767 |
/* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
1768 |
// SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
1769 |
private: |
|
1770 |
/* a helper function to the program_configuration_c visitor... */ |
|
1771 |
void program_constructor_call(program_configuration_c *symbol) { |
|
1772 |
program_declaration_c *p_decl = program_type_symtable.find_value(symbol->program_type_name); |
|
1773 |
||
1774 |
if (p_decl == program_type_symtable.end_value()) |
|
1775 |
/* should never occur. The program being called MUST be in the symtable... */ |
|
1776 |
ERROR; |
|
1777 |
||
1778 |
symbol->program_name->accept(*this); |
|
1779 |
s4o.print("("); |
|
1780 |
||
1781 |
/* loop through each function parameter, find the value we should pass |
|
1782 |
* to it, and then output the c equivalent... |
|
1783 |
*/ |
|
1784 |
function_param_iterator_c fp_iterator(p_decl); |
|
1785 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
1786 |
identifier_c *param_name; |
|
1787 |
nv->push("", ", "); |
|
1788 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
1789 |
||
1790 |
symbol_c *param_type = fp_iterator.param_type(); |
|
1791 |
if (param_type == NULL) ERROR; |
|
1792 |
||
1793 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
1794 |
||
1795 |
#if 0 |
|
1796 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
1797 |
symbol_c *param_value = function_call_param_iterator.search(param_name); |
|
1798 |
#endif |
|
1799 |
||
1800 |
switch (param_direction) { |
|
1801 |
case function_param_iterator_c::direction_in: |
|
1802 |
case function_param_iterator_c::direction_out: |
|
1803 |
case function_param_iterator_c::direction_inout: |
|
1804 |
/* ignore them all!! */ |
|
1805 |
break; |
|
1806 |
||
1807 |
case function_param_iterator_c::direction_extref: |
|
1808 |
#if 0 |
|
1809 |
if (param_value == NULL) |
|
1810 |
/* This is illegal in ST and IL languages. |
|
1811 |
* All variables declared in a VAR_EXTERNAL __must__ |
|
1812 |
* be initialised to reference a specific VAR_GLOBAL variable!! |
|
1813 |
* |
|
1814 |
* The semantic checker should have caught this, we check again just the |
|
1815 |
* same (especially since the semantic checker has not yet been written!). |
|
1816 |
*/ |
|
1817 |
ERROR; |
|
1818 |
s4o.print(nv->get()); |
|
1819 |
s4o.print("&"); |
|
1820 |
param_value->accept(*this); |
|
1821 |
#endif |
|
1822 |
break; |
|
1823 |
#if 0 |
|
1824 |
if (param_value == NULL) { |
|
1825 |
/* no parameter value given, so we pass a previously declared temporary variable. */ |
|
1826 |
std::string *temp_var_name = temp_var_name_factory.new_name(); |
|
1827 |
s4o.print(*temp_var_name); |
|
1828 |
delete temp_var_name; |
|
1829 |
} else { |
|
1830 |
param_value->accept(*this); |
|
1831 |
} |
|
1832 |
#endif |
|
1833 |
break; |
|
1834 |
} /* switch */ |
|
1835 |
} /* for(...) */ |
|
1836 |
||
1837 |
// symbol->parameter_assignment->accept(*this); |
|
1838 |
s4o.print(")"); |
|
1839 |
nv->pop(); |
|
1840 |
return; |
|
1841 |
} |
|
1842 |
||
1843 |
||
1844 |
public: |
|
1845 |
void *visit(program_configuration_c *symbol) { |
|
1846 |
TRACE("program_configuration_c"); |
|
1847 |
||
1848 |
/* now to produce the c equivalent... */ |
|
1849 |
switch (wanted_varformat) { |
|
1850 |
case local_vf: |
|
1851 |
case localinit_vf: |
|
1852 |
s4o.print(s4o.indent_spaces); |
|
1853 |
symbol->program_type_name->accept(*this); |
|
1854 |
s4o.print(" "); |
|
1855 |
symbol->program_name->accept(*this); |
|
1856 |
if (wanted_varformat == localinit_vf) { |
|
1857 |
// TODO... |
|
1858 |
// program_call(symbol); |
|
1859 |
} |
|
1860 |
s4o.print(";\n"); |
|
1861 |
break; |
|
1862 |
||
1863 |
case constructorinit_vf: |
|
1864 |
s4o.print(nv->get()); |
|
1865 |
program_constructor_call(symbol); |
|
1866 |
/* |
|
1867 |
symbol->program_name->accept(*this); |
|
1868 |
s4o.print("("); |
|
1869 |
symbol->prog_conf_elements->accept(*this); |
|
1870 |
nv->pop(); |
|
1871 |
s4o.print(")"); |
|
1872 |
*/ |
|
1873 |
break; |
|
1874 |
||
1875 |
default: |
|
1876 |
ERROR; /* not supported, and not needed either... */ |
|
1877 |
} |
|
1878 |
||
1879 |
return NULL; |
|
1880 |
} |
|
1881 |
||
1882 |
||
1883 |
||
1884 |
/* prog_conf_elements ',' prog_conf_element */ |
|
1885 |
//SYM_LIST(prog_conf_elements_c) |
|
1886 |
void *visit(prog_conf_elements_c *symbol) { |
|
1887 |
TRACE("prog_conf_elements_c"); |
|
1888 |
||
1889 |
return print_list(symbol); |
|
1890 |
} |
|
1891 |
||
1892 |
/* fb_name WITH task_name */ |
|
1893 |
//SYM_REF2(fb_task_c, fb_name, task_name) |
|
1894 |
void *visit(fb_task_c *symbol) { |
|
1895 |
TRACE("fb_task_c"); |
|
1896 |
||
1897 |
/* TODO... |
|
1898 |
* |
|
1899 |
* NOTE: Not yet supported... |
|
1900 |
* We do not support allocating specific function blocks declared |
|
1901 |
* inside a program to be executed by a different task from the one |
|
1902 |
* already executing the program itself. |
|
1903 |
* This is mostly because I (Mario) simply do not understand the |
|
1904 |
* semantics the standard expects us to implement in this case. It is all |
|
1905 |
* very confusing, and very poorly defined in the standard! |
|
1906 |
*/ |
|
1907 |
ERROR; |
|
1908 |
return NULL; |
|
1909 |
} |
|
1910 |
||
1911 |
||
1912 |
||
1913 |
||
1914 |
||
1915 |
||
1916 |
||
1917 |
||
1918 |
||
1919 |
||
1920 |
||
1921 |
||
1922 |
||
1923 |
||
1924 |
||
1925 |
||
1926 |
||
1927 |
||
1928 |
||
1929 |
||
1930 |
||
1931 |
||
1932 |
||
1933 |
||
1934 |
||
1935 |
||
1936 |
||
1937 |
/* any_symbolic_variable ASSIGN prog_data_source */ |
|
1938 |
// SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source) |
|
1939 |
void *visit(prog_cnxn_assign_c *symbol) { |
|
1940 |
TRACE("prog_cnxn_assign_c"); |
|
1941 |
||
1942 |
/* TODO... */ |
|
1943 |
return NULL; |
|
1944 |
} |
|
1945 |
||
1946 |
/* any_symbolic_variable SENDTO data_sink */ |
|
1947 |
// SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, prog_data_source) |
|
1948 |
void *visit(prog_cnxn_sendto_c *symbol) { |
|
1949 |
TRACE("prog_cnxn_sendto_c"); |
|
1950 |
||
1951 |
/* TODO... */ |
|
1952 |
return NULL; |
|
1953 |
} |
|
1954 |
||
1955 |
#if 0 |
|
1956 |
/* VAR_CONFIG instance_specific_init_list END_VAR_BOGUS */ |
|
1957 |
SYM_REF2(instance_specific_initializations_c, instance_specific_init_list, unused) |
|
1958 |
||
1959 |
/* helper symbol for instance_specific_initializations */ |
|
1960 |
SYM_LIST(instance_specific_init_list_c) |
|
1961 |
||
1962 |
/* resource_name '.' program_name '.' {fb_name '.'} |
|
1963 |
((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization)) |
|
1964 |
*/ |
|
1965 |
SYM_REF6(instance_specific_init_c, resource_name, program_name, any_fb_name_list, variable_name, location, initialization) |
|
1966 |
||
1967 |
/* helper symbol for instance_specific_init */ |
|
1968 |
/* function_block_type_name ':=' structure_initialization */ |
|
1969 |
SYM_REF2(fb_initialization_c, function_block_type_name, structure_initialization) |
|
1970 |
||
1971 |
#endif |
|
1972 |
||
1973 |
||
1974 |
||
1975 |
||
1976 |
/****************************************/ |
|
1977 |
/* B.2 - Language IL (Instruction List) */ |
|
1978 |
/****************************************/ |
|
1979 |
/***********************************/ |
|
1980 |
/* B 2.1 Instructions and Operands */ |
|
1981 |
/***********************************/ |
|
1982 |
/* leave for derived classes... */ |
|
1983 |
||
1984 |
/*******************/ |
|
1985 |
/* B 2.2 Operators */ |
|
1986 |
/*******************/ |
|
1987 |
/* leave for derived classes... */ |
|
1988 |
||
1989 |
||
1990 |
/***************************************/ |
|
1991 |
/* B.3 - Language ST (Structured Text) */ |
|
1992 |
/***************************************/ |
|
1993 |
/***********************/ |
|
1994 |
/* B 3.1 - Expressions */ |
|
1995 |
/***********************/ |
|
1996 |
/* leave for derived classes... */ |
|
1997 |
||
1998 |
/********************/ |
|
1999 |
/* B 3.2 Statements */ |
|
2000 |
/********************/ |
|
2001 |
/* leave for derived classes... */ |
|
2002 |
||
2003 |
/*********************************/ |
|
2004 |
/* B 3.2.1 Assignment Statements */ |
|
2005 |
/*********************************/ |
|
2006 |
/* leave for derived classes... */ |
|
2007 |
||
2008 |
/*****************************************/ |
|
2009 |
/* B 3.2.2 Subprogram Control Statements */ |
|
2010 |
/*****************************************/ |
|
2011 |
/* leave for derived classes... */ |
|
2012 |
||
2013 |
/********************************/ |
|
2014 |
/* B 3.2.3 Selection Statements */ |
|
2015 |
/********************************/ |
|
2016 |
/* leave for derived classes... */ |
|
2017 |
||
2018 |
/********************************/ |
|
2019 |
/* B 3.2.4 Iteration Statements */ |
|
2020 |
/********************************/ |
|
2021 |
/* leave for derived classes... */ |
|
2022 |
||
2023 |
||
2024 |
||
2025 |
}; /* generate_c_vardecl_c */ |
|
2026 |
||
2027 |
||
2028 |