author | laurent |
Wed, 02 Dec 2009 16:11:01 +0100 | |
changeset 221 | c6aed7e5f070 |
parent 217 | f5dfadf5de54 |
child 226 | 29f8ffc203c1 |
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 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
43 |
class initialization_analyzer_c: public null_visitor_c { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
44 |
public: |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
45 |
typedef enum { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
46 |
simple_it, |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
47 |
array_it, |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
48 |
struct_it |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
49 |
} initialization_type_t; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
50 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
51 |
private: |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
52 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
53 |
initialization_type_t current_type; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
54 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
55 |
public: |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
56 |
initialization_analyzer_c(symbol_c* symbol) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
57 |
current_type = simple_it; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
58 |
symbol->accept(*this); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
59 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
60 |
~initialization_analyzer_c(void) {} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
61 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
62 |
initialization_type_t get_initialization_type(void) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
63 |
return current_type; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
64 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
65 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
66 |
void *visit(array_initial_elements_list_c *symbol) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
67 |
current_type = array_it; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
68 |
return NULL; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
69 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
70 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
71 |
void *visit(structure_element_initialization_list_c *symbol) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
72 |
current_type = struct_it; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
73 |
return NULL; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
74 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
75 |
}; |
70 | 76 |
|
98 | 77 |
class generate_c_array_initialization_c: public generate_c_typedecl_c { |
78 |
||
79 |
public: |
|
80 |
typedef enum { |
|
81 |
none_am, |
|
82 |
dimensioncount_am, |
|
83 |
initializationvalue_am, |
|
84 |
arrayassignment_am, |
|
85 |
varlistparse_am |
|
86 |
} arrayinitialization_mode_t; |
|
87 |
||
88 |
arrayinitialization_mode_t current_mode; |
|
89 |
||
160 | 90 |
symbol_c* array_base_type; |
98 | 91 |
symbol_c* array_default_value; |
160 | 92 |
symbol_c* array_default_initialization; |
98 | 93 |
|
94 |
private: |
|
160 | 95 |
int dimension_number; |
96 |
int current_dimension; |
|
97 |
int array_size; |
|
98 |
int defined_values_count; |
|
99 |
int current_initialization_count; |
|
98 | 100 |
|
101 |
public: |
|
102 |
generate_c_array_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {} |
|
103 |
~generate_c_array_initialization_c(void) {} |
|
104 |
||
160 | 105 |
void init_array_dimensions(symbol_c *array_specification) { |
106 |
dimension_number = 0; |
|
107 |
current_dimension = 0; |
|
108 |
array_size = 1; |
|
109 |
defined_values_count = 0; |
|
110 |
current_initialization_count = 0; |
|
111 |
array_base_type = array_default_value = array_default_initialization = NULL; |
|
112 |
||
113 |
current_mode = dimensioncount_am; |
|
114 |
array_specification->accept(*this); |
|
115 |
} |
|
116 |
||
98 | 117 |
void init_array(symbol_c *var1_list, symbol_c *array_specification, symbol_c *array_initialization) { |
118 |
int i; |
|
119 |
||
160 | 120 |
init_array_dimensions(array_specification); |
98 | 121 |
|
122 |
current_mode = initializationvalue_am; |
|
123 |
s4o.print("\n"); |
|
124 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
125 |
s4o.indent_right(); |
|
126 |
s4o.print(s4o.indent_spaces + "int index["); |
|
127 |
print_integer(dimension_number); |
|
128 |
s4o.print("];\n"); |
|
129 |
s4o.print(s4o.indent_spaces); |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
130 |
s4o.print("static const "); |
98 | 131 |
array_specification->accept(*this); |
132 |
s4o.print(" temp = "); |
|
160 | 133 |
init_array_values(array_initialization); |
98 | 134 |
s4o.print(";\n"); |
135 |
||
136 |
current_mode = arrayassignment_am; |
|
137 |
array_specification->accept(*this); |
|
138 |
||
139 |
current_mode = varlistparse_am; |
|
140 |
var1_list->accept(*this); |
|
141 |
||
142 |
current_mode = arrayassignment_am; |
|
143 |
for (i = 0; i < dimension_number; i++) { |
|
144 |
s4o.indent_left(); |
|
145 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
146 |
} |
|
147 |
s4o.indent_left(); |
|
148 |
s4o.print(s4o.indent_spaces + "}"); |
|
149 |
} |
|
160 | 150 |
|
151 |
void init_array_values(symbol_c *array_initialization) { |
|
152 |
s4o.print("{"); |
|
153 |
array_initialization->accept(*this); |
|
154 |
if (array_default_initialization != NULL && defined_values_count < array_size) |
|
155 |
array_default_initialization->accept(*this); |
|
156 |
if (defined_values_count < array_size) { |
|
157 |
for (int i = defined_values_count; i < array_size; i++) { |
|
158 |
if (defined_values_count > 0) |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
159 |
s4o.print(","); |
160 | 160 |
array_default_value->accept(*this); |
161 |
defined_values_count++; |
|
162 |
} |
|
163 |
} |
|
164 |
s4o.print("}"); |
|
165 |
} |
|
166 |
||
98 | 167 |
void *visit(identifier_c *type_name) { |
168 |
symbol_c *type_decl; |
|
169 |
switch (current_mode) { |
|
170 |
case dimensioncount_am: |
|
171 |
case arrayassignment_am: |
|
172 |
/* look up the type declaration... */ |
|
173 |
type_decl = type_symtable.find_value(type_name); |
|
174 |
if (type_decl == type_symtable.end_value()) |
|
175 |
/* Type declaration not found!! */ |
|
176 |
ERROR; |
|
177 |
type_decl->accept(*this); |
|
178 |
break; |
|
179 |
default: |
|
180 |
print_token(type_name); |
|
181 |
break; |
|
182 |
} |
|
183 |
return NULL; |
|
184 |
} |
|
185 |
||
186 |
void *visit(var1_list_c *symbol) { |
|
187 |
int i, j; |
|
188 |
||
189 |
for (i = 0; i < symbol->n; i++) { |
|
190 |
s4o.print(s4o.indent_spaces); |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
191 |
s4o.print(SET_VAR); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
192 |
s4o.print("("); |
98 | 193 |
print_variable_prefix(); |
194 |
symbol->elements[i]->accept(*this); |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
195 |
s4o.print(",temp"); |
98 | 196 |
for (j = 0; j < dimension_number; j++) { |
197 |
s4o.print("[index["); |
|
198 |
print_integer(j); |
|
199 |
s4o.print("]]"); |
|
200 |
} |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
201 |
s4o.print(","); |
98 | 202 |
for (j = 0; j < dimension_number; j++) { |
203 |
s4o.print("[index["); |
|
204 |
print_integer(j); |
|
205 |
s4o.print("]]"); |
|
206 |
} |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
207 |
s4o.print(");\n"); |
98 | 208 |
} |
209 |
return NULL; |
|
210 |
} |
|
211 |
||
212 |
/********************************/ |
|
213 |
/* B 1.3.3 - Derived data types */ |
|
214 |
/********************************/ |
|
215 |
||
160 | 216 |
/* array_specification [ASSIGN array_initialization] */ |
217 |
/* array_initialization may be NULL ! */ |
|
218 |
void *visit(array_spec_init_c *symbol) { |
|
219 |
switch (current_mode) { |
|
220 |
case dimensioncount_am: |
|
221 |
array_default_initialization = symbol->array_initialization; |
|
222 |
break; |
|
223 |
default: |
|
224 |
break; |
|
225 |
} |
|
226 |
symbol->array_specification->accept(*this); |
|
227 |
return NULL; |
|
228 |
} |
|
229 |
||
98 | 230 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
231 |
void *visit(array_specification_c *symbol) { |
|
160 | 232 |
symbol->array_subrange_list->accept(*this); |
98 | 233 |
switch (current_mode) { |
234 |
case dimensioncount_am: |
|
160 | 235 |
array_base_type = symbol->non_generic_type_name; |
98 | 236 |
array_default_value = (symbol_c *)symbol->non_generic_type_name->accept(*type_initial_value_c::instance());; |
160 | 237 |
if (array_default_value == NULL) ERROR; |
98 | 238 |
break; |
239 |
default: |
|
240 |
break; |
|
241 |
} |
|
242 |
return NULL; |
|
243 |
} |
|
244 |
||
245 |
/* signed_integer DOTDOT signed_integer */ |
|
246 |
//SYM_REF2(subrange_c, lower_limit, upper_limit) |
|
247 |
void *visit(subrange_c *symbol) { |
|
248 |
switch (current_mode) { |
|
249 |
case dimensioncount_am: |
|
250 |
dimension_number++; |
|
251 |
array_size *= extract_integer(symbol->upper_limit) - extract_integer(symbol->lower_limit) + 1; |
|
252 |
break; |
|
253 |
case arrayassignment_am: |
|
254 |
s4o.print(s4o.indent_spaces + "for (index["); |
|
255 |
print_integer(current_dimension); |
|
256 |
s4o.print("] = 0; index["); |
|
257 |
print_integer(current_dimension); |
|
258 |
s4o.print("] <= "); |
|
259 |
print_integer(extract_integer(symbol->upper_limit) - extract_integer(symbol->lower_limit)); |
|
260 |
s4o.print("; index["); |
|
261 |
print_integer(current_dimension); |
|
262 |
s4o.print("]++) {\n"); |
|
263 |
s4o.indent_right(); |
|
264 |
current_dimension++; |
|
265 |
break; |
|
266 |
default: |
|
267 |
break; |
|
268 |
} |
|
269 |
return NULL; |
|
270 |
} |
|
271 |
||
272 |
/* helper symbol for array_initialization */ |
|
273 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
274 |
void *visit(array_initial_elements_list_c *symbol) { |
|
275 |
switch (current_mode) { |
|
276 |
case initializationvalue_am: |
|
160 | 277 |
current_initialization_count = 0; |
278 |
for (int i = 0; i < symbol->n; i++) { |
|
279 |
if (current_initialization_count >= defined_values_count) { |
|
280 |
if (defined_values_count >= array_size) |
|
281 |
ERROR; |
|
282 |
if (defined_values_count > 0) |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
283 |
s4o.print(","); |
160 | 284 |
symbol->elements[i]->accept(*this); |
285 |
defined_values_count++; |
|
286 |
} |
|
287 |
else { |
|
288 |
array_initial_elements_c *array_initial_element = dynamic_cast<array_initial_elements_c *>(symbol->elements[i]); |
|
289 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
290 |
if (array_initial_element != NULL) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
291 |
symbol->elements[i]->accept(*this); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
292 |
} |
160 | 293 |
} |
294 |
current_initialization_count++; |
|
98 | 295 |
} |
296 |
break; |
|
297 |
default: |
|
298 |
break; |
|
299 |
} |
|
300 |
return NULL; |
|
301 |
} |
|
302 |
||
303 |
/* integer '(' [array_initial_element] ')' */ |
|
304 |
/* array_initial_element may be NULL ! */ |
|
305 |
void *visit(array_initial_elements_c *symbol) { |
|
306 |
int initial_element_number; |
|
307 |
||
308 |
switch (current_mode) { |
|
309 |
case initializationvalue_am: |
|
310 |
initial_element_number = extract_integer(symbol->integer); |
|
160 | 311 |
if (current_initialization_count < defined_values_count) { |
312 |
int temp_element_number = 0; |
|
313 |
int diff = defined_values_count - current_initialization_count; |
|
314 |
if (diff <= initial_element_number) |
|
315 |
temp_element_number = initial_element_number - diff; |
|
316 |
current_initialization_count += initial_element_number - 1; |
|
317 |
initial_element_number = temp_element_number; |
|
318 |
if (initial_element_number > 0) { |
|
319 |
defined_values_count++; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
320 |
s4o.print(","); |
160 | 321 |
} |
322 |
} |
|
323 |
else |
|
324 |
current_initialization_count += initial_element_number - 1; |
|
325 |
if (defined_values_count + initial_element_number > array_size) |
|
326 |
ERROR; |
|
98 | 327 |
for (int i = 0; i < initial_element_number; i++) { |
328 |
if (i > 0) |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
329 |
s4o.print(","); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
330 |
if (symbol->array_initial_element != NULL) { |
98 | 331 |
symbol->array_initial_element->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
332 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
333 |
else { |
98 | 334 |
array_default_value->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
335 |
} |
98 | 336 |
} |
337 |
if (initial_element_number > 1) |
|
160 | 338 |
defined_values_count += initial_element_number - 1; |
98 | 339 |
break; |
340 |
default: |
|
341 |
break; |
|
342 |
} |
|
343 |
return NULL; |
|
344 |
} |
|
345 |
||
160 | 346 |
void *visit(structure_element_initialization_list_c *symbol); |
98 | 347 |
}; |
70 | 348 |
|
349 |
/***********************************************************************/ |
|
350 |
/***********************************************************************/ |
|
351 |
/***********************************************************************/ |
|
352 |
/***********************************************************************/ |
|
353 |
/***********************************************************************/ |
|
354 |
/***********************************************************************/ |
|
355 |
/***********************************************************************/ |
|
356 |
/***********************************************************************/ |
|
357 |
||
160 | 358 |
/* given a structure_element_declaration_list_c, iterate |
359 |
* through each element, returning the name |
|
360 |
* of each element...structure_element_iterator_c |
|
361 |
*/ |
|
362 |
class structure_element_iterator_c : public null_visitor_c { |
|
363 |
||
364 |
private: |
|
365 |
/* a pointer to the structure_element_declaration_list_c |
|
366 |
* currently being analysed. |
|
367 |
*/ |
|
368 |
symbol_c *type_decl; |
|
369 |
int next_element, element_count; |
|
370 |
identifier_c *current_element_name; |
|
371 |
symbol_c *current_element_type; |
|
372 |
symbol_c *current_element_default_value; |
|
373 |
||
374 |
||
375 |
public: |
|
376 |
/* start off at the first parameter once again... */ |
|
377 |
void reset(void) { |
|
378 |
next_element = element_count = 0; |
|
379 |
current_element_name = NULL; |
|
380 |
current_element_type = current_element_default_value = NULL; |
|
381 |
} |
|
382 |
||
383 |
/* initialise the iterator object. |
|
384 |
* We must be given a reference to the function declaration |
|
385 |
* that will be analysed... |
|
386 |
*/ |
|
387 |
structure_element_iterator_c(symbol_c *type_decl) { |
|
388 |
this->type_decl = type_decl; |
|
389 |
reset(); |
|
390 |
} |
|
391 |
||
392 |
/* Skip to the next element. After object creation, |
|
393 |
* the object references on |
|
394 |
* element _before_ the first, so |
|
395 |
* this function must be called once to get the object to |
|
396 |
* reference the first element... |
|
397 |
* |
|
398 |
* Returns the element's name! |
|
399 |
*/ |
|
400 |
identifier_c *next(void) { |
|
401 |
void *res; |
|
402 |
identifier_c *identifier; |
|
403 |
element_count = 0; |
|
404 |
next_element++; |
|
405 |
res = type_decl->accept(*this); |
|
406 |
if (res != NULL) { |
|
407 |
symbol_c *sym = (symbol_c *)res; |
|
408 |
identifier = dynamic_cast<identifier_c *>(sym); |
|
409 |
if (identifier == NULL) |
|
410 |
ERROR; |
|
411 |
} |
|
412 |
else |
|
413 |
return NULL; |
|
414 |
||
415 |
current_element_name = identifier; |
|
416 |
return current_element_name; |
|
417 |
} |
|
418 |
||
419 |
/* Returns the currently referenced element's default value, |
|
420 |
* or NULL if none is specified in the structure declaration itself. |
|
421 |
*/ |
|
422 |
symbol_c *default_value(void) { |
|
423 |
return current_element_default_value; |
|
424 |
} |
|
425 |
||
426 |
/* Returns the currently referenced element's type name. */ |
|
427 |
symbol_c *element_type(void) { |
|
428 |
return current_element_type; |
|
429 |
} |
|
430 |
||
431 |
/********************************/ |
|
432 |
/* B 1.3.3 - Derived data types */ |
|
433 |
/********************************/ |
|
434 |
||
435 |
/* helper symbol for structure_declaration */ |
|
436 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
437 |
void *visit(structure_element_declaration_list_c *symbol) { |
|
438 |
void *res; |
|
439 |
for (int i = 0; i < symbol->n; i++) { |
|
440 |
res = symbol->elements[i]->accept(*this); |
|
441 |
if (res != NULL) |
|
442 |
return res; |
|
443 |
} |
|
444 |
return NULL; |
|
445 |
} |
|
446 |
||
447 |
/* structure_element_name ':' *_spec_init */ |
|
448 |
void *visit(structure_element_declaration_c *symbol) { |
|
449 |
element_count++; |
|
450 |
if (next_element == element_count) { |
|
451 |
current_element_default_value = spec_init_sperator_c::get_init(symbol->spec_init); |
|
452 |
current_element_type = spec_init_sperator_c::get_spec(symbol->spec_init); |
|
453 |
return symbol->structure_element_name; |
|
454 |
} |
|
455 |
/* not yet the desired element... */ |
|
456 |
return NULL; |
|
457 |
} |
|
458 |
||
459 |
}; |
|
460 |
||
461 |
/* |
|
462 |
* Structure init element iterator. |
|
463 |
* It will search through the elements of a structure initialization |
|
464 |
*/ |
|
465 |
class structure_init_element_iterator_c : public null_visitor_c { |
|
466 |
private: |
|
467 |
/* a pointer to the structure initialization |
|
468 |
* currently being analysed. |
|
469 |
*/ |
|
470 |
symbol_c *structure_initialization; |
|
471 |
identifier_c *search_element_name; |
|
472 |
||
473 |
public: |
|
474 |
/* initialise the iterator object. |
|
475 |
* We must be given a reference to the structure initialization |
|
476 |
* that will be analysed... |
|
477 |
*/ |
|
478 |
structure_init_element_iterator_c(symbol_c *structure_initialization) { |
|
479 |
this->structure_initialization = structure_initialization; |
|
480 |
search_element_name = NULL; |
|
481 |
} |
|
482 |
||
483 |
/* Search for the value passed to the element named <element_name>... */ |
|
484 |
symbol_c *search(symbol_c *element_name) { |
|
485 |
if (NULL == element_name) ERROR; |
|
486 |
search_element_name = dynamic_cast<identifier_c *>(element_name); |
|
487 |
if (NULL == search_element_name) ERROR; |
|
488 |
void *res = structure_initialization->accept(*this); |
|
489 |
return (symbol_c *)res; |
|
490 |
} |
|
491 |
||
492 |
/* helper symbol for structure_initialization */ |
|
493 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
494 |
void *visit(structure_element_initialization_list_c *symbol) { |
|
495 |
void *res; |
|
496 |
for (int i = 0; i < symbol->n; i++) { |
|
497 |
res = symbol->elements[i]->accept(*this); |
|
498 |
if (res != NULL) |
|
499 |
return res; |
|
500 |
} |
|
501 |
return NULL; |
|
502 |
} |
|
503 |
||
504 |
/* structure_element_name ASSIGN value */ |
|
505 |
void *visit(structure_element_initialization_c *symbol) { |
|
506 |
identifier_c *element_name = dynamic_cast<identifier_c *>(symbol->structure_element_name); |
|
507 |
||
508 |
if (element_name == NULL) ERROR; |
|
509 |
||
510 |
if (strcasecmp(search_element_name->value, element_name->value) == 0) |
|
511 |
/* FOUND! This is the same element!! */ |
|
512 |
return (void *)symbol->value; |
|
513 |
return NULL; |
|
514 |
} |
|
515 |
}; |
|
516 |
||
517 |
class generate_c_structure_initialization_c: public generate_c_typedecl_c { |
|
518 |
||
519 |
public: |
|
520 |
typedef enum { |
|
521 |
none_sm, |
|
522 |
typedecl_sm, |
|
523 |
initializationvalue_sm, |
|
524 |
varlistparse_sm |
|
525 |
} structureinitialization_mode_t; |
|
526 |
||
527 |
structureinitialization_mode_t current_mode; |
|
528 |
||
529 |
private: |
|
530 |
symbol_c* structure_type_decl; |
|
531 |
symbol_c* current_element_type; |
|
532 |
||
533 |
public: |
|
534 |
generate_c_structure_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {} |
|
535 |
~generate_c_structure_initialization_c(void) {} |
|
536 |
||
537 |
void init_structure_default(symbol_c *structure_type_name) { |
|
538 |
structure_type_decl = NULL; |
|
539 |
current_element_type = NULL; |
|
540 |
||
541 |
current_mode = typedecl_sm; |
|
542 |
structure_type_name->accept(*this); |
|
543 |
} |
|
544 |
||
545 |
void init_structure(symbol_c *var1_list, symbol_c *structure_type_name, symbol_c *structure_initialization) { |
|
546 |
int i; |
|
547 |
||
548 |
init_structure_default(structure_type_name); |
|
549 |
||
550 |
current_mode = initializationvalue_sm; |
|
551 |
s4o.print("\n"); |
|
552 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
553 |
s4o.indent_right(); |
|
554 |
s4o.print(s4o.indent_spaces); |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
555 |
s4o.print("static const "); |
160 | 556 |
structure_type_name->accept(*this); |
557 |
s4o.print(" temp = "); |
|
558 |
structure_initialization->accept(*this); |
|
559 |
s4o.print(";\n"); |
|
560 |
||
561 |
current_mode = varlistparse_sm; |
|
562 |
var1_list->accept(*this); |
|
563 |
||
564 |
s4o.indent_left(); |
|
565 |
s4o.print(s4o.indent_spaces + "}"); |
|
566 |
} |
|
567 |
||
568 |
void *visit(identifier_c *type_name) { |
|
569 |
symbol_c *type_decl; |
|
570 |
switch (current_mode) { |
|
571 |
case typedecl_sm: |
|
572 |
/* look up the type declaration... */ |
|
573 |
type_decl = type_symtable.find_value(type_name); |
|
574 |
if (type_decl == type_symtable.end_value()) |
|
575 |
/* Type declaration not found!! */ |
|
576 |
ERROR; |
|
577 |
type_decl->accept(*this); |
|
578 |
break; |
|
579 |
default: |
|
580 |
print_token(type_name); |
|
581 |
break; |
|
582 |
} |
|
583 |
return NULL; |
|
584 |
} |
|
585 |
||
586 |
void *visit(var1_list_c *symbol) { |
|
587 |
int i, j; |
|
588 |
||
589 |
for (i = 0; i < symbol->n; i++) { |
|
590 |
s4o.print(s4o.indent_spaces); |
|
591 |
print_variable_prefix(); |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
592 |
s4o.print(SET_VAR); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
593 |
s4o.print("("); |
160 | 594 |
symbol->elements[i]->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
595 |
s4o.print(",temp);\n"); |
160 | 596 |
} |
597 |
return NULL; |
|
598 |
} |
|
599 |
||
600 |
/********************************/ |
|
601 |
/* B 1.3.3 - Derived data types */ |
|
602 |
/********************************/ |
|
603 |
||
604 |
/* helper symbol for structure_declaration */ |
|
605 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
606 |
void *visit(structure_element_declaration_list_c *symbol) { |
|
607 |
switch (current_mode) { |
|
608 |
case typedecl_sm: |
|
609 |
structure_type_decl = (symbol_c *)symbol; |
|
610 |
break; |
|
611 |
default: |
|
612 |
break; |
|
613 |
} |
|
614 |
return NULL; |
|
615 |
} |
|
616 |
||
617 |
/* helper symbol for structure_initialization */ |
|
618 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
619 |
void *visit(structure_element_initialization_list_c *symbol) { |
|
620 |
s4o.print("{"); |
|
621 |
structure_element_iterator_c structure_iterator(structure_type_decl); |
|
622 |
||
623 |
identifier_c *element_name; |
|
624 |
structure_init_element_iterator_c structure_init_element_iterator(symbol); |
|
625 |
for(int i = 1; (element_name = structure_iterator.next()) != NULL; i++) { |
|
626 |
if (i > 1) |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
627 |
s4o.print(","); |
160 | 628 |
|
629 |
/* Get the value from an initialization */ |
|
630 |
symbol_c *element_value = structure_init_element_iterator.search(element_name); |
|
631 |
||
632 |
if (element_value == NULL) { |
|
633 |
/* No value given for parameter, so we must use the default... */ |
|
634 |
/* First check whether default value specified in function declaration...*/ |
|
635 |
element_value = structure_iterator.default_value(); |
|
636 |
current_element_type = structure_iterator.element_type(); |
|
637 |
} |
|
638 |
||
639 |
if (element_value == NULL) { |
|
640 |
if (current_element_type == NULL) ERROR; |
|
641 |
||
642 |
/* If not, get the default value of this variable's type */ |
|
643 |
element_value = (symbol_c *)current_element_type->accept(*type_initial_value_c::instance()); |
|
644 |
} |
|
645 |
||
646 |
if (element_value == NULL) ERROR; |
|
647 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
648 |
initialization_analyzer_c initialization_analyzer(element_value); |
164 | 649 |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
650 |
if (initialization_analyzer.get_initialization_type() == initialization_analyzer_c::struct_it) { |
164 | 651 |
generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
652 |
structure_initialization->set_variable_prefix(get_variable_prefix()); |
|
653 |
structure_initialization->init_structure_default(current_element_type); |
|
654 |
structure_initialization->current_mode = generate_c_structure_initialization_c::initializationvalue_sm; |
|
655 |
element_value->accept(*structure_initialization); |
|
656 |
delete structure_initialization; |
|
657 |
} |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
658 |
else { |
164 | 659 |
element_value->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
660 |
} |
160 | 661 |
} |
662 |
s4o.print("}"); |
|
663 |
return NULL; |
|
664 |
} |
|
164 | 665 |
|
160 | 666 |
/* helper symbol for array_initialization */ |
667 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
668 |
void *visit(array_initial_elements_list_c *symbol) { |
|
669 |
generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
|
670 |
array_initialization->set_variable_prefix(get_variable_prefix()); |
|
671 |
array_initialization->init_array_dimensions(current_element_type); |
|
672 |
array_initialization->current_mode = generate_c_array_initialization_c::initializationvalue_am; |
|
673 |
array_initialization->init_array_values(symbol); |
|
674 |
delete array_initialization; |
|
675 |
return NULL; |
|
676 |
} |
|
677 |
||
678 |
}; |
|
679 |
||
680 |
||
681 |
/* helper symbol for array_initialization */ |
|
682 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
683 |
void *generate_c_array_initialization_c::visit(structure_element_initialization_list_c *symbol) { |
|
684 |
generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
685 |
structure_initialization->set_variable_prefix(get_variable_prefix()); |
|
686 |
structure_initialization->init_structure_default(array_base_type); |
|
687 |
structure_initialization->current_mode = generate_c_structure_initialization_c::initializationvalue_sm; |
|
688 |
symbol->accept(*structure_initialization); |
|
689 |
delete structure_initialization; |
|
690 |
return NULL; |
|
691 |
} |
|
692 |
||
693 |
/***********************************************************************/ |
|
694 |
/***********************************************************************/ |
|
695 |
/***********************************************************************/ |
|
696 |
/***********************************************************************/ |
|
697 |
/***********************************************************************/ |
|
698 |
/***********************************************************************/ |
|
699 |
/***********************************************************************/ |
|
700 |
/***********************************************************************/ |
|
70 | 701 |
|
702 |
||
703 |
||
704 |
class generate_c_vardecl_c: protected generate_c_typedecl_c { |
|
705 |
||
706 |
/* A Helper class to the main class... */ |
|
707 |
/* print a string, except the first time it is called */ |
|
708 |
/* used to print the separator "," before each variable |
|
709 |
* declaration, except the first... |
|
710 |
* |
|
711 |
* Needs to be done in a seperate class because this is called |
|
712 |
* from within various locations within the code. |
|
713 |
*/ |
|
714 |
class next_var_c { |
|
715 |
private: |
|
716 |
bool print_flag; |
|
717 |
std::string str1, str2; |
|
718 |
||
719 |
next_var_c *embedded_scope; |
|
720 |
||
721 |
public: |
|
722 |
next_var_c(std::string s1, std::string s2) { |
|
723 |
str1 = s1; |
|
724 |
str2 = s2; |
|
725 |
print_flag = false; |
|
726 |
embedded_scope = NULL; |
|
727 |
} |
|
728 |
||
729 |
std::string get(void) { |
|
730 |
if (NULL != embedded_scope) |
|
731 |
return embedded_scope->get(); |
|
732 |
||
733 |
bool old_print_flag = print_flag; |
|
734 |
print_flag = true; |
|
735 |
if (!old_print_flag) |
|
736 |
return str1; |
|
737 |
else |
|
738 |
return str2; |
|
739 |
} |
|
740 |
||
741 |
/* Create a new next_var_c for an embedded scope. |
|
742 |
* From now on, every call to get() will return the |
|
743 |
* inner-most scope...! |
|
744 |
*/ |
|
745 |
void push(std::string s1, std::string s2) { |
|
746 |
if (NULL != embedded_scope) |
|
747 |
return embedded_scope->push(s1, s2); |
|
748 |
||
749 |
embedded_scope = new next_var_c(s1, s2); |
|
750 |
if (NULL == embedded_scope) |
|
751 |
ERROR; |
|
752 |
return; |
|
753 |
} |
|
754 |
||
755 |
/* Remove the inner-most scope... */ |
|
756 |
void pop(void) { |
|
757 |
if (NULL != embedded_scope) |
|
758 |
return embedded_scope->pop(); |
|
759 |
||
760 |
delete embedded_scope; |
|
761 |
embedded_scope = NULL; |
|
762 |
} |
|
763 |
}; |
|
764 |
||
765 |
private: |
|
766 |
/* used to generate the ',' separating the parameters in a function call */ |
|
767 |
next_var_c *nv; |
|
768 |
||
769 |
||
770 |
public: |
|
771 |
/* the types of variables that need to be processed... */ |
|
772 |
static const unsigned int none_vt = 0x0000; |
|
773 |
static const unsigned int input_vt = 0x0001; // VAR_INPUT |
|
774 |
static const unsigned int output_vt = 0x0002; // VAR_OUTPUT |
|
775 |
static const unsigned int inoutput_vt = 0x0004; // VAR_IN_OUT |
|
776 |
static const unsigned int private_vt = 0x0008; // VAR |
|
777 |
static const unsigned int temp_vt = 0x0010; // VAR_TEMP |
|
778 |
static const unsigned int external_vt = 0x0020; // VAR_EXTERNAL |
|
779 |
static const unsigned int global_vt = 0x0040; // VAR_GLOBAL |
|
780 |
// Globals declared inside a resource will not be declared |
|
781 |
// unless global_vt is acompanied by resource_vt |
|
782 |
static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
|
783 |
static const unsigned int program_vt = 0x0100; // PROGRAM (inside a configuration!) |
|
784 |
// Programs declared inside a resource will not be declared |
|
785 |
// unless program_vt is acompanied by resource_vt |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
786 |
static const unsigned int en_vt = 0x0200; // EN declaration |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
787 |
static const unsigned int eno_vt = 0x0400; // ENO declaration |
70 | 788 |
static const unsigned int resource_vt = 0x8000; // RESOURCE (inside a configuration!) |
789 |
// This, just of itself, will not print out any declarations!! |
|
790 |
// It must be acompanied by either program_vt and/or global_vt |
|
791 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
792 |
/* the qualifier of variables that need to be processed... */ |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
793 |
static const unsigned int none_vq = 0x0000; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
794 |
static const unsigned int constant_vq = 0x0001; // CONSTANT |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
795 |
static const unsigned int retain_vq = 0x0002; // RETAIN |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
796 |
static const unsigned int non_retain_vq = 0x0004; // NON_RETAIN |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
797 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
798 |
|
70 | 799 |
/* How variables should be declared: as local variables or |
800 |
* variables within a function call interface. |
|
801 |
* |
|
802 |
* This will define the format of the output generated |
|
803 |
* by this class. |
|
804 |
* |
|
805 |
* finterface_vf: function interface parameters |
|
806 |
* e.g. f( int a, long b, real c ); |
|
807 |
* --------------------- |
|
808 |
* This class/function will produce the |
|
809 |
* underlined code of the above examples, |
|
810 |
* and no more!! |
|
811 |
* |
|
812 |
* localinit_vf: local declaration. Will include variable |
|
813 |
* initialisation if it is not a located variable. |
|
814 |
* e.g. |
|
815 |
* int a = 9; |
|
816 |
* long b = 99; |
|
817 |
* real c = 99.9; |
|
818 |
* |
|
819 |
* local_vf: local declaration. Will NOT include variable |
|
820 |
* initialisation. |
|
821 |
* e.g. |
|
822 |
* int a; |
|
823 |
* long b; |
|
824 |
* real c; |
|
825 |
* |
|
826 |
* init_vf: local initialisation without declaration. |
|
827 |
* e.g. |
|
828 |
* a = 9; |
|
829 |
* b = 99; |
|
830 |
* c = 99.9; |
|
831 |
* |
|
832 |
* constructorinit_vf: initialising of member variables... |
|
833 |
* e.g. for a constructor... |
|
834 |
* class_name_c(void) |
|
835 |
* : a(9), b(99), c(99.9) { // code... } |
|
836 |
* -------------------- |
|
837 |
* This class/function will produce the |
|
838 |
* underlined code of the above examples, |
|
839 |
* and no more!! |
|
840 |
* |
|
841 |
* globalinit_vf: initialising of static c++ variables. These |
|
842 |
* variables may have been declared as static inside |
|
843 |
* a class, in which case the scope within which they were |
|
844 |
* previously delcared must be passed as the second parameter |
|
845 |
* to the print() function. |
|
846 |
* |
|
847 |
* e.g. |
|
848 |
* __plc_pt_c<INT, 8*sizeof(INT)> START_P::loc = __plc_pt_c<INT, 8*sizeof(INT)>("I2"); |
|
849 |
*/ |
|
850 |
typedef enum {finterface_vf, |
|
145 | 851 |
foutputassign_vf, |
852 |
local_vf, |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
853 |
localinit_vf, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
854 |
init_vf, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
855 |
constructorinit_vf, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
856 |
globalinit_vf |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
857 |
} varformat_t; |
70 | 858 |
|
859 |
||
860 |
private: |
|
861 |
/* variable used to store the types of variables that need to be processed... */ |
|
862 |
/* Only set in the constructor...! */ |
|
863 |
/* Will contain a set of values of generate_c_vardecl_c::XXXX_vt */ |
|
864 |
unsigned int wanted_vartype; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
865 |
|
70 | 866 |
/* variable used to store the type of variable currently being processed... */ |
867 |
/* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ |
|
868 |
unsigned int current_vartype; |
|
869 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
870 |
/* variable used to store the qualifier of variable currently being processed... */ |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
871 |
/* Will contain a single value of generate_c_vardecl_c::XXXX_vq */ |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
872 |
unsigned int current_varqualifier; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
873 |
|
70 | 874 |
/* How variables should be declared: as local variables or |
875 |
* variables within a function interface... |
|
876 |
*/ |
|
877 |
/* Only set in the constructor...! */ |
|
878 |
varformat_t wanted_varformat; |
|
879 |
||
880 |
/* The number of variables already declared. */ |
|
881 |
/* Used to declare 'void' in case no variables are declared in a function interface... */ |
|
882 |
int finterface_var_count; |
|
883 |
||
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
884 |
/* 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
|
885 |
* 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
|
886 |
symbol_c *resource_name; |
70 | 887 |
|
888 |
/* Holds the references to the type and initial value |
|
889 |
* of the variables currently being declared. |
|
890 |
* Please read the comment under var1_init_decl_c for further |
|
891 |
* details... |
|
892 |
* |
|
893 |
* We make an effort to keep these pointers pointing to NULL |
|
894 |
* whenever we are outside the scope of variable declaration |
|
895 |
* (i.e. when we are traversing a part of the parse tree which |
|
896 |
* is not part of variable declaration) in order tio try to catch |
|
897 |
* any bugs as soon as possible. |
|
898 |
*/ |
|
899 |
symbol_c *current_var_type_symbol; |
|
900 |
symbol_c *current_var_init_symbol; |
|
901 |
void update_type_init(symbol_c *symbol /* a spec_init_c, subrange_spec_init_c, etc... */ ) { |
|
902 |
this->current_var_type_symbol = spec_init_sperator_c::get_spec(symbol); |
|
903 |
this->current_var_init_symbol = spec_init_sperator_c::get_init(symbol); |
|
904 |
if (NULL == this->current_var_type_symbol) |
|
905 |
ERROR; |
|
906 |
if (NULL == this->current_var_init_symbol) { |
|
907 |
/* We try to find the data type's default value... */ |
|
908 |
this->current_var_init_symbol = (symbol_c *)this->current_var_type_symbol->accept(*type_initial_value_c::instance()); |
|
909 |
/* Note that Function Block 'data types' do not have a default value, so we cannot abort if no default value is found! */ |
|
910 |
/* |
|
911 |
if (NULL == this->current_var_init_symbol) |
|
912 |
ERROR; |
|
913 |
*/ |
|
914 |
} |
|
915 |
} |
|
916 |
||
917 |
void void_type_init(void) { |
|
918 |
this->current_var_type_symbol = NULL; |
|
919 |
this->current_var_init_symbol = NULL; |
|
920 |
} |
|
921 |
||
922 |
/* Only used when wanted_varformat == globalinit_vf |
|
923 |
* Holds a pointer to an identifier_c, which in turns contains |
|
924 |
* the identifier of the scope within which the static member was |
|
925 |
* declared. |
|
926 |
*/ |
|
927 |
symbol_c *globalnamespace; |
|
928 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
929 |
void *print_retain(void) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
930 |
s4o.print(","); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
931 |
switch (current_varqualifier) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
932 |
case retain_vq: |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
933 |
s4o.print("1"); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
934 |
break; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
935 |
case non_retain_vq: |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
936 |
s4o.print("0"); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
937 |
break; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
938 |
default: |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
939 |
s4o.print("retain"); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
940 |
break; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
941 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
942 |
return NULL; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
943 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
944 |
|
70 | 945 |
/* Actually produce the output where variables are declared... */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
946 |
/* Note that located variables and EN/ENO are the exception, they |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
947 |
* being declared in the located_var_decl_c, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
948 |
* en_param_declaration_c and eno_param_declaration_c visitors... |
70 | 949 |
*/ |
950 |
void *declare_variables(symbol_c *symbol, bool is_fb = false) { |
|
951 |
list_c *list = dynamic_cast<list_c *>(symbol); |
|
952 |
/* should NEVER EVER occur!! */ |
|
953 |
if (list == NULL) ERROR; |
|
954 |
||
955 |
/* now to produce the c equivalent... */ |
|
956 |
if ((wanted_varformat == local_vf) || |
|
957 |
(wanted_varformat == init_vf) || |
|
958 |
(wanted_varformat == localinit_vf)) { |
|
959 |
for(int i = 0; i < list->n; i++) { |
|
960 |
s4o.print(s4o.indent_spaces); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
961 |
if (wanted_varformat == local_vf) { |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
962 |
if (!is_fb) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
963 |
s4o.print(DECLARE_VAR); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
964 |
s4o.print("("); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
965 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
966 |
this->current_var_type_symbol->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
967 |
if (is_fb) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
968 |
s4o.print(" "); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
969 |
else |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
970 |
s4o.print(","); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
971 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
972 |
else if (wanted_varformat == localinit_vf) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
973 |
this->current_var_type_symbol->accept(*this); |
70 | 974 |
s4o.print(" "); |
975 |
} |
|
976 |
print_variable_prefix(); |
|
977 |
list->elements[i]->accept(*this); |
|
978 |
if (wanted_varformat != local_vf) { |
|
979 |
if (this->current_var_init_symbol != NULL) { |
|
980 |
s4o.print(" = "); |
|
981 |
this->current_var_init_symbol->accept(*this); |
|
982 |
} |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
983 |
s4o.print(";\n"); |
70 | 984 |
} |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
985 |
else if (is_fb) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
986 |
s4o.print(";\n"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
987 |
else |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
988 |
s4o.print(")\n"); |
70 | 989 |
} |
990 |
} |
|
991 |
||
992 |
if (wanted_varformat == finterface_vf) { |
|
993 |
for(int i = 0; i < list->n; i++) { |
|
994 |
finterface_var_count++; |
|
995 |
s4o.print(nv->get()); |
|
996 |
s4o.print("\n" + s4o.indent_spaces); |
|
997 |
this->current_var_type_symbol->accept(*this); |
|
998 |
if ((current_vartype & (output_vt | inoutput_vt)) != 0) |
|
145 | 999 |
s4o.print(" *__"); |
70 | 1000 |
else |
1001 |
s4o.print(" "); |
|
1002 |
list->elements[i]->accept(*this); |
|
1003 |
/* We do not print the initial value at function declaration! |
|
1004 |
* It is up to the caller to pass the correct default value |
|
1005 |
* if none is specified in the ST source code |
|
1006 |
*/ |
|
1007 |
/* if (this->current_var_init_symbol != NULL) { |
|
1008 |
s4o.print(" = "); this->current_var_init_symbol->accept(*this);} |
|
1009 |
*/ |
|
1010 |
} |
|
1011 |
} |
|
1012 |
||
145 | 1013 |
if (wanted_varformat == foutputassign_vf) { |
1014 |
for(int i = 0; i < list->n; i++) { |
|
1015 |
if ((current_vartype & (output_vt | inoutput_vt)) != 0) { |
|
1016 |
s4o.print(s4o.indent_spaces + "if (__"); |
|
1017 |
list->elements[i]->accept(*this); |
|
1018 |
s4o.print(" != NULL) {\n"); |
|
1019 |
s4o.indent_right(); |
|
1020 |
s4o.print(s4o.indent_spaces + "*__"); |
|
1021 |
list->elements[i]->accept(*this); |
|
1022 |
s4o.print(" = "); |
|
1023 |
list->elements[i]->accept(*this); |
|
1024 |
s4o.print(";\n"); |
|
1025 |
s4o.indent_left(); |
|
1026 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
1027 |
} |
|
1028 |
} |
|
1029 |
} |
|
1030 |
||
70 | 1031 |
if (wanted_varformat == constructorinit_vf) { |
1032 |
for(int i = 0; i < list->n; i++) { |
|
1033 |
if (is_fb) { |
|
1034 |
s4o.print(nv->get()); |
|
1035 |
this->current_var_type_symbol->accept(*this); |
|
1036 |
s4o.print(FB_INIT_SUFFIX); |
|
1037 |
s4o.print("(&"); |
|
1038 |
this->print_variable_prefix(); |
|
1039 |
list->elements[i]->accept(*this); |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1040 |
print_retain(); |
70 | 1041 |
s4o.print(");"); |
1042 |
} |
|
1043 |
else if (this->current_var_init_symbol != NULL) { |
|
1044 |
s4o.print(nv->get()); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1045 |
s4o.print(INIT_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1046 |
s4o.print("("); |
70 | 1047 |
this->print_variable_prefix(); |
1048 |
list->elements[i]->accept(*this); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1049 |
s4o.print(","); |
70 | 1050 |
this->current_var_init_symbol->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1051 |
print_retain(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1052 |
s4o.print(")"); |
70 | 1053 |
} |
1054 |
} |
|
1055 |
} |
|
1056 |
||
1057 |
return NULL; |
|
1058 |
} |
|
1059 |
||
1060 |
||
1061 |
||
1062 |
||
1063 |
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
|
1064 |
generate_c_vardecl_c(stage4out_c *s4o_ptr, varformat_t varformat, unsigned int vartype, symbol_c* res_name = NULL) |
70 | 1065 |
: generate_c_typedecl_c(s4o_ptr) { |
1066 |
wanted_varformat = varformat; |
|
1067 |
wanted_vartype = vartype; |
|
1068 |
current_vartype = none_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1069 |
current_varqualifier = none_vq; |
70 | 1070 |
current_var_type_symbol = NULL; |
1071 |
current_var_init_symbol = NULL; |
|
1072 |
globalnamespace = NULL; |
|
1073 |
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
|
1074 |
resource_name = res_name; |
70 | 1075 |
} |
1076 |
||
160 | 1077 |
~generate_c_vardecl_c(void) {} |
70 | 1078 |
|
1079 |
void print(symbol_c *symbol, symbol_c *scope = NULL, const char *variable_prefix = NULL) { |
|
1080 |
this->set_variable_prefix(variable_prefix); |
|
1081 |
if (globalinit_vf == wanted_varformat) |
|
1082 |
globalnamespace = scope; |
|
1083 |
||
1084 |
finterface_var_count = 0; |
|
1085 |
||
1086 |
switch (wanted_varformat) { |
|
1087 |
case constructorinit_vf: nv = new next_var_c("", "\n"+s4o.indent_spaces); break; |
|
1088 |
case finterface_vf: /* fall through... */ |
|
1089 |
case localinit_vf: /* fall through... */ |
|
1090 |
case local_vf: nv = new next_var_c("", ", "); break; |
|
1091 |
default: nv = NULL; |
|
1092 |
} /* switch() */ |
|
1093 |
||
1094 |
symbol->accept(*this); |
|
189 | 1095 |
|
70 | 1096 |
delete nv; |
1097 |
nv = NULL; |
|
1098 |
globalnamespace = NULL; |
|
1099 |
} |
|
1100 |
||
1101 |
protected: |
|
1102 |
/***************************/ |
|
1103 |
/* B 0 - Programming Model */ |
|
1104 |
/***************************/ |
|
1105 |
/* leave for derived classes... */ |
|
1106 |
||
1107 |
/*************************/ |
|
1108 |
/* B.1 - Common elements */ |
|
1109 |
/*************************/ |
|
1110 |
/*******************************************/ |
|
1111 |
/* B 1.1 - Letters, digits and identifiers */ |
|
1112 |
/*******************************************/ |
|
1113 |
/* done in base class(es) */ |
|
1114 |
||
1115 |
/*********************/ |
|
1116 |
/* B 1.2 - Constants */ |
|
1117 |
/*********************/ |
|
1118 |
/* originally empty... */ |
|
1119 |
||
1120 |
/******************************/ |
|
1121 |
/* B 1.2.1 - Numeric Literals */ |
|
1122 |
/******************************/ |
|
1123 |
/* done in base class(es) */ |
|
1124 |
||
1125 |
/*******************************/ |
|
1126 |
/* B.1.2.2 Character Strings */ |
|
1127 |
/*******************************/ |
|
1128 |
/* done in base class(es) */ |
|
1129 |
||
1130 |
/***************************/ |
|
1131 |
/* B 1.2.3 - Time Literals */ |
|
1132 |
/***************************/ |
|
1133 |
/************************/ |
|
1134 |
/* B 1.2.3.1 - Duration */ |
|
1135 |
/************************/ |
|
1136 |
/* done in base class(es) */ |
|
1137 |
||
1138 |
/************************************/ |
|
1139 |
/* B 1.2.3.2 - Time of day and Date */ |
|
1140 |
/************************************/ |
|
1141 |
/* done in base class(es) */ |
|
1142 |
||
1143 |
/**********************/ |
|
1144 |
/* B.1.3 - Data types */ |
|
1145 |
/**********************/ |
|
1146 |
/***********************************/ |
|
1147 |
/* B 1.3.1 - Elementary Data Types */ |
|
1148 |
/***********************************/ |
|
1149 |
/* done in base class(es) */ |
|
1150 |
||
1151 |
/********************************/ |
|
1152 |
/* B.1.3.2 - Generic data types */ |
|
1153 |
/********************************/ |
|
1154 |
/* originally empty... */ |
|
1155 |
||
1156 |
/********************************/ |
|
1157 |
/* B 1.3.3 - Derived data types */ |
|
1158 |
/********************************/ |
|
1159 |
/* done in base class(es) */ |
|
1160 |
||
1161 |
/*********************/ |
|
1162 |
/* B 1.4 - Variables */ |
|
1163 |
/*********************/ |
|
1164 |
/* done in base class(es) */ |
|
1165 |
||
1166 |
/********************************************/ |
|
1167 |
/* B.1.4.1 Directly Represented Variables */ |
|
1168 |
/********************************************/ |
|
1169 |
/* done in base class(es) */ |
|
1170 |
||
1171 |
/*************************************/ |
|
1172 |
/* B.1.4.2 Multi-element Variables */ |
|
1173 |
/*************************************/ |
|
1174 |
/* done in base class(es) */ |
|
1175 |
||
1176 |
/******************************************/ |
|
1177 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
1178 |
/******************************************/ |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1179 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1180 |
void *visit(constant_option_c *symbol) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1181 |
current_varqualifier = constant_vq; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1182 |
return NULL; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1183 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1184 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1185 |
void *visit(retain_option_c *symbol) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1186 |
current_varqualifier = retain_vq; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1187 |
return NULL; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1188 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1189 |
|
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1190 |
void *visit(non_retain_option_c *symbol) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1191 |
current_varqualifier = non_retain_vq; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1192 |
return NULL; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1193 |
} |
70 | 1194 |
|
1195 |
void *visit(input_declarations_c *symbol) { |
|
1196 |
TRACE("input_declarations_c"); |
|
1197 |
if ((wanted_vartype & input_vt) != 0) { |
|
1198 |
/* |
|
1199 |
// TO DO ... |
|
1200 |
if (symbol->option != NULL) |
|
1201 |
symbol->option->accept(*this); |
|
1202 |
*/ |
|
1203 |
//s4o.indent_right(); |
|
1204 |
current_vartype = input_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1205 |
if (symbol->option != NULL) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1206 |
symbol->option->accept(*this); |
70 | 1207 |
symbol->input_declaration_list->accept(*this); |
1208 |
current_vartype = none_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1209 |
current_varqualifier = none_vt; |
70 | 1210 |
//s4o.indent_left(); |
1211 |
} |
|
1212 |
return NULL; |
|
1213 |
} |
|
1214 |
||
1215 |
/* helper symbol for input_declarations */ |
|
1216 |
void *visit(input_declaration_list_c *symbol) { |
|
1217 |
TRACE("input_declaration_list_c"); |
|
1218 |
print_list(symbol); |
|
1219 |
return NULL; |
|
1220 |
} |
|
1221 |
||
1222 |
void *visit(edge_declaration_c *symbol) { |
|
1223 |
TRACE("edge_declaration_c"); |
|
1224 |
// TO DO ... |
|
1225 |
symbol->var1_list->accept(*this); |
|
1226 |
s4o.print(" : BOOL "); |
|
1227 |
symbol->edge->accept(*this); |
|
1228 |
return NULL; |
|
1229 |
} |
|
1230 |
||
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1231 |
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
|
1232 |
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
|
1233 |
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
|
1234 |
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
|
1235 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1236 |
if ((wanted_vartype & en_vt) != 0) { |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1237 |
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
|
1238 |
s4o.print(nv->get()); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1239 |
s4o.print("\n" + s4o.indent_spaces); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1240 |
symbol->type->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1241 |
s4o.print(" "); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1242 |
symbol->name->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1243 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1244 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1245 |
if ((wanted_varformat == local_vf) || |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1246 |
(wanted_varformat == init_vf) || |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1247 |
(wanted_varformat == localinit_vf)) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1248 |
s4o.print(s4o.indent_spaces); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1249 |
if (wanted_varformat == local_vf) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1250 |
s4o.print(DECLARE_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1251 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1252 |
symbol->type->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1253 |
s4o.print(","); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1254 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1255 |
else if (wanted_varformat == localinit_vf) { |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1256 |
symbol->type->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1257 |
s4o.print(" "); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1258 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1259 |
print_variable_prefix(); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1260 |
symbol->name->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1261 |
if (wanted_varformat == local_vf) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1262 |
s4o.print(")\n"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1263 |
else { |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1264 |
s4o.print(" = "); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1265 |
symbol->value->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1266 |
s4o.print(";\n"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1267 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1268 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1269 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1270 |
if (wanted_varformat == constructorinit_vf) { |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1271 |
/* NOTE: I (Mario) think this is dead code - never gets executed. Must confirm it before deleting it... */ |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1272 |
s4o.print(nv->get()); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1273 |
s4o.print(INIT_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1274 |
s4o.print("("); |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1275 |
this->print_variable_prefix(); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1276 |
// s4o.print("EN = __BOOL_LITERAL(TRUE);"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1277 |
symbol->name->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1278 |
s4o.print(","); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1279 |
symbol->value->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1280 |
print_retain(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1281 |
s4o.print(")"); |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1282 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1283 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1284 |
return NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1285 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1286 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1287 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1288 |
void *visit(eno_param_declaration_c *symbol) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1289 |
TRACE("eno_declaration_c"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1290 |
if (wanted_varformat == finterface_vf) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1291 |
finterface_var_count++; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1292 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1293 |
if ((wanted_vartype & eno_vt) != 0) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1294 |
if (wanted_varformat == finterface_vf) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1295 |
s4o.print(nv->get()); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1296 |
// s4o.print("\n" + s4o.indent_spaces + "BOOL *ENO"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1297 |
s4o.print("\n" + s4o.indent_spaces); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1298 |
symbol->type->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1299 |
s4o.print(" *__"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1300 |
symbol->name->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1301 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1302 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1303 |
if ((wanted_varformat == local_vf) || |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1304 |
(wanted_varformat == init_vf) || |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1305 |
(wanted_varformat == localinit_vf)) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1306 |
s4o.print(s4o.indent_spaces); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1307 |
if (wanted_varformat == local_vf) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1308 |
s4o.print(DECLARE_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1309 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1310 |
symbol->type->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1311 |
s4o.print(","); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1312 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1313 |
else if (wanted_varformat == localinit_vf) { |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1314 |
symbol->type->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1315 |
s4o.print(" "); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1316 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1317 |
print_variable_prefix(); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1318 |
symbol->name->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1319 |
if (wanted_varformat == local_vf) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1320 |
s4o.print(")\n"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1321 |
else |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1322 |
s4o.print(" = __BOOL_LITERAL(TRUE);\n"); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1323 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1324 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1325 |
if (wanted_varformat == foutputassign_vf) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1326 |
s4o.print(s4o.indent_spaces + "if (__"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1327 |
symbol->name->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1328 |
s4o.print(" != NULL) {\n"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1329 |
s4o.indent_right(); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1330 |
s4o.print(s4o.indent_spaces + "*__"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1331 |
symbol->name->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1332 |
s4o.print(" = "); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1333 |
symbol->name->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1334 |
s4o.print(";\n"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1335 |
s4o.indent_left(); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1336 |
s4o.print(s4o.indent_spaces + "}\n"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1337 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1338 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1339 |
if (wanted_varformat == constructorinit_vf) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1340 |
/* NOTE: I (Mario) think this is dead code - never gets executed. Must confirm it before deleting it... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1341 |
s4o.print(nv->get()); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1342 |
s4o.print(INIT_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1343 |
s4o.print("("); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1344 |
this->print_variable_prefix(); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1345 |
// s4o.print("ENO = __BOOL_LITERAL(TRUE);"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1346 |
symbol->name->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1347 |
s4o.print(",__BOOL_LITERAL(TRUE)"); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1348 |
print_retain(); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1349 |
s4o.print(")"); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1350 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1351 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1352 |
return NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1353 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
1354 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1355 |
|
70 | 1356 |
void *visit(raising_edge_option_c *symbol) { |
1357 |
// TO DO ... |
|
1358 |
s4o.print("R_EDGE"); |
|
1359 |
return NULL; |
|
1360 |
} |
|
1361 |
||
98 | 1362 |
/* var1_list ':' array_spec_init */ |
1363 |
// SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
1364 |
void *visit(array_var_init_decl_c *symbol) { |
|
1365 |
TRACE("array_var_init_decl_c"); |
|
1366 |
/* Please read the comments inside the var1_init_decl_c |
|
1367 |
* visitor, as they apply here too. |
|
1368 |
*/ |
|
1369 |
||
1370 |
/* Start off by setting the current_var_type_symbol and |
|
1371 |
* current_var_init_symbol private variables... |
|
1372 |
*/ |
|
1373 |
update_type_init(symbol->array_spec_init); |
|
1374 |
||
1375 |
/* now to produce the c equivalent... */ |
|
160 | 1376 |
if (wanted_varformat == constructorinit_vf) { |
1377 |
generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
|
1378 |
array_initialization->set_variable_prefix(get_variable_prefix()); |
|
1379 |
array_initialization->init_array(symbol->var1_list, this->current_var_type_symbol, this->current_var_init_symbol); |
|
1380 |
delete array_initialization; |
|
1381 |
} |
|
98 | 1382 |
else |
1383 |
symbol->var1_list->accept(*this); |
|
1384 |
||
1385 |
/* Values no longer in scope, and therefore no longer used. |
|
1386 |
* Make an effort to keep them set to NULL when not in use |
|
1387 |
* in order to catch bugs as soon as possible... |
|
1388 |
*/ |
|
1389 |
void_type_init(); |
|
1390 |
||
1391 |
return NULL; |
|
1392 |
} |
|
70 | 1393 |
|
1394 |
/* var1_list ':' initialized_structure */ |
|
1395 |
// SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
1396 |
void *visit(structured_var_init_decl_c *symbol) { |
|
1397 |
TRACE("structured_var_init_decl_c"); |
|
1398 |
/* Please read the comments inside the var1_init_decl_c |
|
1399 |
* visitor, as they apply here too. |
|
1400 |
*/ |
|
1401 |
||
1402 |
/* Start off by setting the current_var_type_symbol and |
|
1403 |
* current_var_init_symbol private variables... |
|
1404 |
*/ |
|
1405 |
update_type_init(symbol->initialized_structure); |
|
1406 |
||
1407 |
/* now to produce the c equivalent... */ |
|
160 | 1408 |
if (wanted_varformat == constructorinit_vf) { |
1409 |
generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
1410 |
structure_initialization->set_variable_prefix(get_variable_prefix()); |
|
1411 |
structure_initialization->init_structure(symbol->var1_list, this->current_var_type_symbol, this->current_var_init_symbol); |
|
1412 |
delete structure_initialization; |
|
1413 |
} |
|
1414 |
else |
|
1415 |
symbol->var1_list->accept(*this); |
|
70 | 1416 |
|
1417 |
/* Values no longer in scope, and therefore no longer used. |
|
1418 |
* Make an effort to keep them set to NULL when not in use |
|
1419 |
* in order to catch bugs as soon as possible... |
|
1420 |
*/ |
|
1421 |
void_type_init(); |
|
1422 |
||
1423 |
return NULL; |
|
1424 |
} |
|
1425 |
||
1426 |
/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
1427 |
/* structure_initialization -> may be NULL ! */ |
|
1428 |
void *visit(fb_name_decl_c *symbol) { |
|
1429 |
TRACE("fb_name_decl_c"); |
|
1430 |
/* Please read the comments inside the var1_init_decl_c |
|
1431 |
* visitor, as they apply here too. |
|
1432 |
*/ |
|
1433 |
||
1434 |
/* Start off by setting the current_var_type_symbol and |
|
1435 |
* current_var_init_symbol private variables... |
|
1436 |
*/ |
|
1437 |
update_type_init(symbol); |
|
1438 |
||
1439 |
/* now to produce the c equivalent... */ |
|
1440 |
symbol->fb_name_list->accept(*this); |
|
1441 |
||
1442 |
/* Values no longer in scope, and therefore no longer used. |
|
1443 |
* Make an effort to keep them set to NULL when not in use |
|
1444 |
* in order to catch bugs as soon as possible... |
|
1445 |
*/ |
|
1446 |
void_type_init(); |
|
1447 |
||
1448 |
return NULL; |
|
1449 |
} |
|
1450 |
||
1451 |
/* fb_name_list ',' fb_name */ |
|
1452 |
void *visit(fb_name_list_c *symbol) { |
|
1453 |
TRACE("fb_name_list_c"); |
|
1454 |
declare_variables(symbol, true); |
|
1455 |
return NULL; |
|
1456 |
} |
|
1457 |
||
1458 |
||
1459 |
/* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
|
1460 |
/* option -> may be NULL ! */ |
|
1461 |
void *visit(output_declarations_c *symbol) { |
|
1462 |
TRACE("output_declarations_c"); |
|
1463 |
if ((wanted_vartype & output_vt) != 0) { |
|
1464 |
/* |
|
1465 |
// TO DO ... |
|
1466 |
if (symbol->option != NULL) |
|
1467 |
symbol->option->accept(*this); |
|
1468 |
*/ |
|
1469 |
//s4o.indent_right(); |
|
1470 |
current_vartype = output_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1471 |
if (symbol->option != NULL) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1472 |
symbol->option->accept(*this); |
70 | 1473 |
symbol->var_init_decl_list->accept(*this); |
1474 |
current_vartype = none_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1475 |
current_varqualifier = none_vq; |
70 | 1476 |
//s4o.indent_left(); |
1477 |
} |
|
1478 |
return NULL; |
|
1479 |
} |
|
1480 |
||
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
1481 |
|
70 | 1482 |
/* VAR_IN_OUT var_declaration_list END_VAR */ |
1483 |
void *visit(input_output_declarations_c *symbol) { |
|
1484 |
TRACE("input_output_declarations_c"); |
|
1485 |
if ((wanted_vartype & inoutput_vt) != 0) { |
|
1486 |
//s4o.indent_right(); |
|
1487 |
current_vartype = inoutput_vt; |
|
1488 |
symbol->var_declaration_list->accept(*this); |
|
1489 |
current_vartype = none_vt; |
|
1490 |
//s4o.indent_left(); |
|
1491 |
} |
|
1492 |
return NULL; |
|
1493 |
} |
|
1494 |
||
1495 |
/* helper symbol for input_output_declarations */ |
|
1496 |
/* var_declaration_list var_declaration ';' */ |
|
1497 |
void *visit(var_declaration_list_c *symbol) { |
|
1498 |
TRACE("var_declaration_list_c"); |
|
1499 |
print_list(symbol); |
|
1500 |
return NULL; |
|
1501 |
} |
|
1502 |
||
1503 |
#if 0 |
|
1504 |
/* var1_list ':' array_specification */ |
|
1505 |
SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
1506 |
#endif |
|
1507 |
||
98 | 1508 |
void *visit(array_initial_elements_list_c *symbol) { |
1509 |
s4o.print(";// array initialisation"); |
|
1510 |
return NULL; |
|
1511 |
} |
|
1512 |
||
70 | 1513 |
/* var1_list ':' structure_type_name */ |
1514 |
//SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
1515 |
void *visit(structured_var_declaration_c *symbol) { |
|
1516 |
TRACE("structured_var_declaration_c"); |
|
1517 |
/* Please read the comments inside the var1_init_decl_c |
|
1518 |
* visitor, as they apply here too. |
|
1519 |
*/ |
|
1520 |
||
1521 |
/* Start off by setting the current_var_type_symbol and |
|
1522 |
* current_var_init_symbol private variables... |
|
1523 |
*/ |
|
1524 |
update_type_init(symbol->structure_type_name); |
|
1525 |
||
160 | 1526 |
if (wanted_varformat == constructorinit_vf) { |
1527 |
generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
1528 |
structure_initialization->set_variable_prefix(get_variable_prefix()); |
|
1529 |
structure_initialization->init_structure(symbol->var1_list, this->current_var_type_symbol, this->current_var_init_symbol); |
|
1530 |
delete structure_initialization; |
|
1531 |
} |
|
1532 |
else |
|
1533 |
/* now to produce the c equivalent... */ |
|
1534 |
symbol->var1_list->accept(*this); |
|
70 | 1535 |
|
1536 |
/* Values no longer in scope, and therefore no longer used. |
|
1537 |
* Make an effort to keep them set to NULL when not in use |
|
1538 |
* in order to catch bugs as soon as possible... |
|
1539 |
*/ |
|
1540 |
void_type_init(); |
|
1541 |
||
1542 |
return NULL; |
|
1543 |
} |
|
1544 |
||
1545 |
||
1546 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
|
1547 |
/* option -> may be NULL ! */ |
|
1548 |
/* helper symbol for input_declarations */ |
|
1549 |
void *visit(var_declarations_c *symbol) { |
|
1550 |
TRACE("var_declarations_c"); |
|
1551 |
if ((wanted_vartype & private_vt) != 0) { |
|
1552 |
/* |
|
1553 |
// TO DO ... |
|
1554 |
if (symbol->option != NULL) |
|
1555 |
symbol->option->accept(*this); |
|
1556 |
*/ |
|
1557 |
current_vartype = private_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1558 |
if (symbol->option != NULL) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1559 |
symbol->option->accept(*this); |
70 | 1560 |
symbol->var_init_decl_list->accept(*this); |
1561 |
current_vartype = none_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1562 |
current_varqualifier = none_vq; |
70 | 1563 |
} |
1564 |
return NULL; |
|
1565 |
} |
|
1566 |
||
1567 |
/* VAR RETAIN var_init_decl_list END_VAR */ |
|
1568 |
void *visit(retentive_var_declarations_c *symbol) { |
|
1569 |
TRACE("retentive_var_declarations_c"); |
|
1570 |
if ((wanted_vartype & private_vt) != 0) { |
|
1571 |
current_vartype = private_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1572 |
current_varqualifier = retain_vq; |
70 | 1573 |
symbol->var_init_decl_list->accept(*this); |
1574 |
current_vartype = none_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1575 |
current_varqualifier = none_vq; |
70 | 1576 |
} |
1577 |
return NULL; |
|
1578 |
} |
|
1579 |
||
1580 |
/* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ |
|
1581 |
/* option -> may be NULL ! */ |
|
1582 |
//SYM_REF2(located_var_declarations_c, option, located_var_decl_list) |
|
1583 |
void *visit(located_var_declarations_c *symbol) { |
|
1584 |
TRACE("located_var_declarations_c"); |
|
1585 |
if ((wanted_vartype & located_vt) != 0) { |
|
1586 |
/* |
|
1587 |
// TO DO ... |
|
1588 |
if (symbol->option != NULL) |
|
1589 |
symbol->option->accept(*this); |
|
1590 |
*/ |
|
1591 |
current_vartype = located_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1592 |
if (symbol->option != NULL) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1593 |
symbol->option->accept(*this); |
70 | 1594 |
symbol->located_var_decl_list->accept(*this); |
1595 |
current_vartype = none_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1596 |
current_varqualifier = none_vq; |
70 | 1597 |
} |
1598 |
return NULL; |
|
1599 |
} |
|
1600 |
||
1601 |
/* helper symbol for located_var_declarations */ |
|
1602 |
/* located_var_decl_list located_var_decl ';' */ |
|
1603 |
//SYM_LIST(located_var_decl_list_c) |
|
1604 |
void *visit(located_var_decl_list_c *symbol) { |
|
1605 |
TRACE("located_var_decl_list_c"); |
|
1606 |
print_list(symbol); |
|
1607 |
return NULL; |
|
1608 |
} |
|
1609 |
||
1610 |
||
1611 |
/* [variable_name] location ':' located_var_spec_init */ |
|
1612 |
/* variable_name -> may be NULL ! */ |
|
1613 |
//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
1614 |
void *visit(located_var_decl_c *symbol) { |
|
1615 |
TRACE("located_var_decl_c"); |
|
1616 |
/* Please read the comments inside the var1_init_decl_c |
|
1617 |
* visitor, as they apply here too. |
|
1618 |
*/ |
|
1619 |
||
1620 |
/* Start off by setting the current_var_type_symbol and |
|
1621 |
* current_var_init_symbol private variables... |
|
1622 |
*/ |
|
1623 |
update_type_init(symbol->located_var_spec_init); |
|
1624 |
||
1625 |
/* now to produce the c equivalent... */ |
|
1626 |
switch(wanted_varformat) { |
|
1627 |
case local_vf: |
|
1628 |
s4o.print(s4o.indent_spaces); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1629 |
s4o.print(DECLARE_LOCATED); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1630 |
s4o.print("("); |
70 | 1631 |
this->current_var_type_symbol->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1632 |
s4o.print(","); |
70 | 1633 |
if (symbol->variable_name != NULL) |
1634 |
symbol->variable_name->accept(*this); |
|
1635 |
else |
|
1636 |
symbol->location->accept(*this); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1637 |
s4o.print(")\n"); |
70 | 1638 |
break; |
1639 |
||
1640 |
case constructorinit_vf: |
|
1641 |
s4o.print(nv->get()); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1642 |
s4o.print(INIT_LOCATED); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1643 |
s4o.print("("); |
70 | 1644 |
this->current_var_type_symbol->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1645 |
s4o.print(","); |
70 | 1646 |
symbol->location->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1647 |
s4o.print(","); |
70 | 1648 |
if (symbol->variable_name != NULL) |
1649 |
symbol->variable_name->accept(*this); |
|
1650 |
else |
|
1651 |
symbol->location->accept(*this); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1652 |
s4o.print(","); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1653 |
print_variable_prefix(); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1654 |
print_retain(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1655 |
s4o.print(")\n"); |
152 | 1656 |
if (this->current_var_init_symbol != NULL) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1657 |
s4o.print(INIT_LOCATED_VALUE); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1658 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1659 |
if (symbol->variable_name != NULL) |
152 | 1660 |
symbol->variable_name->accept(*this); |
1661 |
else |
|
1662 |
symbol->location->accept(*this); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1663 |
s4o.print(","); |
152 | 1664 |
this->current_var_init_symbol->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1665 |
s4o.print(")\n"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1666 |
} |
70 | 1667 |
break; |
1668 |
||
1669 |
case globalinit_vf: |
|
1670 |
s4o.print(s4o.indent_spaces + "__plc_pt_c<"); |
|
1671 |
this->current_var_type_symbol->accept(*this); |
|
1672 |
s4o.print(", 8*sizeof("); |
|
1673 |
this->current_var_type_symbol->accept(*this); |
|
1674 |
s4o.print(")> "); |
|
1675 |
if (this->globalnamespace != NULL) { |
|
1676 |
this->globalnamespace->accept(*this); |
|
1677 |
s4o.print("::"); |
|
1678 |
} |
|
1679 |
if (symbol->variable_name != NULL) |
|
1680 |
symbol->variable_name->accept(*this); |
|
1681 |
else |
|
1682 |
symbol->location->accept(*this); |
|
1683 |
||
1684 |
s4o.print(" = "); |
|
1685 |
||
1686 |
s4o.print(s4o.indent_spaces + "__plc_pt_c<"); |
|
1687 |
this->current_var_type_symbol->accept(*this); |
|
1688 |
s4o.print(", 8*sizeof("); |
|
1689 |
this->current_var_type_symbol->accept(*this); |
|
1690 |
s4o.print(")>(\""); |
|
1691 |
symbol->location->accept(*this); |
|
1692 |
s4o.print("\""); |
|
1693 |
if (this->current_var_init_symbol != NULL) { |
|
1694 |
s4o.print(", "); |
|
1695 |
this->current_var_init_symbol->accept(*this); |
|
1696 |
} |
|
1697 |
s4o.print(");\n"); |
|
1698 |
break; |
|
1699 |
||
1700 |
default: |
|
1701 |
ERROR; |
|
1702 |
} /* switch() */ |
|
1703 |
||
1704 |
/* Values no longer in scope, and therefore no longer used. |
|
1705 |
* Make an effort to keep them set to NULL when not in use |
|
1706 |
* in order to catch bugs as soon as possible... |
|
1707 |
*/ |
|
1708 |
void_type_init(); |
|
1709 |
||
1710 |
return NULL; |
|
1711 |
} |
|
1712 |
||
1713 |
||
1714 |
||
1715 |
||
1716 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
1717 |
/* option -> may be NULL ! */ |
|
1718 |
//SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
1719 |
void *visit(external_var_declarations_c *symbol) { |
|
1720 |
TRACE("external_var_declarations_c"); |
|
1721 |
if ((wanted_vartype & external_vt) != 0) { |
|
1722 |
/* |
|
1723 |
// TODO ... |
|
1724 |
if (symbol->option != NULL) |
|
1725 |
symbol->option->accept(*this); |
|
1726 |
*/ |
|
1727 |
//s4o.indent_right(); |
|
1728 |
current_vartype = external_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1729 |
if (symbol->option != NULL) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1730 |
symbol->option->accept(*this); |
70 | 1731 |
symbol->external_declaration_list->accept(*this); |
1732 |
current_vartype = none_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1733 |
current_varqualifier = none_vq; |
70 | 1734 |
//s4o.indent_left(); |
1735 |
} |
|
1736 |
return NULL; |
|
1737 |
} |
|
1738 |
||
1739 |
/* helper symbol for external_var_declarations */ |
|
1740 |
/*| external_declaration_list external_declaration';' */ |
|
1741 |
//SYM_LIST(external_declaration_list_c) |
|
1742 |
/* helper symbol for input_declarations */ |
|
1743 |
void *visit(external_declaration_list_c *symbol) { |
|
1744 |
TRACE("external_declaration_list_c"); |
|
1745 |
print_list(symbol); |
|
1746 |
return NULL; |
|
1747 |
} |
|
1748 |
||
1749 |
||
1750 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
1751 |
//SYM_REF2(external_declaration_c, global_var_name, specification) |
|
1752 |
void *visit(external_declaration_c *symbol) { |
|
1753 |
TRACE("external_declaration_c"); |
|
1754 |
/* Please read the comments inside the var1_init_decl_c |
|
1755 |
* visitor, as they apply here too. |
|
1756 |
*/ |
|
1757 |
||
1758 |
/* Start off by setting the current_var_type_symbol and |
|
1759 |
* current_var_init_symbol private variables... |
|
1760 |
*/ |
|
1761 |
this->current_var_type_symbol = symbol->specification; |
|
1762 |
this->current_var_init_symbol = NULL; |
|
1763 |
||
1764 |
/* now to produce the c equivalent... */ |
|
1765 |
switch (wanted_varformat) { |
|
1766 |
case local_vf: |
|
1767 |
case localinit_vf: |
|
1768 |
s4o.print(s4o.indent_spaces); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1769 |
s4o.print(DECLARE_EXTERNAL); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1770 |
s4o.print("("); |
70 | 1771 |
this->current_var_type_symbol->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1772 |
s4o.print(","); |
70 | 1773 |
symbol->global_var_name->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1774 |
s4o.print(")\n"); |
70 | 1775 |
break; |
1776 |
||
1777 |
case constructorinit_vf: |
|
1778 |
s4o.print(nv->get()); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1779 |
s4o.print(INIT_EXTERNAL); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1780 |
s4o.print("("); |
70 | 1781 |
this->current_var_type_symbol->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1782 |
s4o.print(","); |
70 | 1783 |
symbol->global_var_name->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1784 |
s4o.print(","); |
70 | 1785 |
print_variable_prefix(); |
1786 |
symbol->global_var_name->accept(*this); |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1787 |
print_retain(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1788 |
s4o.print(")"); |
70 | 1789 |
break; |
1790 |
||
1791 |
case finterface_vf: |
|
1792 |
finterface_var_count++; |
|
1793 |
s4o.print(nv->get()); |
|
1794 |
this->current_var_type_symbol->accept(*this); |
|
1795 |
s4o.print(" *"); |
|
1796 |
symbol->global_var_name->accept(*this); |
|
1797 |
break; |
|
1798 |
||
1799 |
default: |
|
1800 |
ERROR; |
|
1801 |
} |
|
1802 |
||
1803 |
/* Values no longer in scope, and therefore no longer used. |
|
1804 |
* Make an effort to keep them set to NULL when not in use |
|
1805 |
* in order to catch bugs as soon as possible... |
|
1806 |
*/ |
|
1807 |
void_type_init(); |
|
1808 |
||
1809 |
return NULL; |
|
1810 |
} |
|
1811 |
||
1812 |
||
1813 |
||
1814 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
1815 |
/* option -> may be NULL ! */ |
|
1816 |
// SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
1817 |
void *visit(global_var_declarations_c *symbol) { |
|
1818 |
TRACE("global_var_declarations_c"); |
|
1819 |
if ((wanted_vartype & global_vt) != 0) { |
|
1820 |
/* |
|
1821 |
// TODO ... |
|
1822 |
if (symbol->option != NULL) |
|
1823 |
symbol->option->accept(*this); |
|
1824 |
*/ |
|
1825 |
//s4o.indent_right(); |
|
1826 |
unsigned int previous_vartype = current_vartype; |
|
1827 |
// previous_vartype will be either none_vt, or resource_vt |
|
1828 |
current_vartype = global_vt; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1829 |
if (symbol->option != NULL) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1830 |
symbol->option->accept(*this); |
70 | 1831 |
symbol->global_var_decl_list->accept(*this); |
1832 |
current_vartype = previous_vartype; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1833 |
current_varqualifier = none_vq; |
70 | 1834 |
//s4o.indent_left(); |
1835 |
} |
|
1836 |
return NULL; |
|
1837 |
} |
|
1838 |
||
1839 |
/* helper symbol for global_var_declarations */ |
|
1840 |
/*| global_var_decl_list global_var_decl ';' */ |
|
1841 |
//SYM_LIST(global_var_decl_list_c) |
|
1842 |
void *visit(global_var_decl_list_c *symbol) { |
|
1843 |
TRACE("global_var_decl_list_c"); |
|
1844 |
print_list(symbol); |
|
1845 |
return NULL; |
|
1846 |
} |
|
1847 |
||
1848 |
||
1849 |
||
1850 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
1851 |
/* type_specification ->may be NULL ! */ |
|
1852 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
1853 |
void *visit(global_var_decl_c *symbol) { |
|
1854 |
TRACE("global_var_decl_c"); |
|
1855 |
/* Please read the comments inside the var1_init_decl_c |
|
1856 |
* visitor, as they apply here too. |
|
1857 |
*/ |
|
1858 |
||
1859 |
/* Start off by setting the current_var_type_symbol and |
|
1860 |
* current_var_init_symbol private variables... |
|
1861 |
*/ |
|
1862 |
update_type_init(symbol->type_specification); |
|
1863 |
||
1864 |
/* now to produce the c equivalent... */ |
|
1865 |
symbol->global_var_spec->accept(*this); |
|
1866 |
||
1867 |
/* Values no longer in scope, and therefore no longer used. |
|
1868 |
* Make an effort to keep them set to NULL when not in use |
|
1869 |
* in order to catch bugs as soon as possible... |
|
1870 |
*/ |
|
1871 |
void_type_init(); |
|
1872 |
||
1873 |
return NULL; |
|
1874 |
} |
|
1875 |
||
1876 |
||
1877 |
/*| global_var_name location */ |
|
1878 |
// SYM_REF2(global_var_spec_c, global_var_name, location) |
|
1879 |
void *visit(global_var_spec_c *symbol) { |
|
1880 |
TRACE("global_var_spec_c"); |
|
1881 |
/* now to produce the c equivalent... */ |
|
1882 |
switch(wanted_varformat) { |
|
1883 |
case local_vf: |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1884 |
s4o.print(s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1885 |
s4o.print(DECLARE_GLOBAL_LOCATION); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1886 |
s4o.print("("); |
195
66d501d7b67d
Fix segmentation fault when define global with location but no name (reported by brendan)
lbessard
parents:
189
diff
changeset
|
1887 |
this->current_var_type_symbol->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1888 |
s4o.print(","); |
195
66d501d7b67d
Fix segmentation fault when define global with location but no name (reported by brendan)
lbessard
parents:
189
diff
changeset
|
1889 |
symbol->location->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1890 |
s4o.print(")\n"); |
70 | 1891 |
if (symbol->global_var_name != NULL) { |
195
66d501d7b67d
Fix segmentation fault when define global with location but no name (reported by brendan)
lbessard
parents:
189
diff
changeset
|
1892 |
s4o.print(s4o.indent_spaces); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1893 |
s4o.print(DECLARE_GLOBAL_LOCATED); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1894 |
s4o.print("("); |
70 | 1895 |
this->current_var_type_symbol->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1896 |
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
|
1897 |
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
|
1898 |
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
|
1899 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1900 |
s4o.print(","); |
70 | 1901 |
symbol->global_var_name->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1902 |
s4o.print(")\n"); |
70 | 1903 |
} |
1904 |
break; |
|
1905 |
||
1906 |
case constructorinit_vf: |
|
1907 |
if (symbol->global_var_name != NULL) { |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1908 |
s4o.print(nv->get()); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1909 |
s4o.print(s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1910 |
s4o.print(INIT_GLOBAL_LOCATED); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1911 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1912 |
if (this->resource_name != NULL) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1913 |
this->resource_name->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1914 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1915 |
s4o.print(","); |
128
fd5760f30682
Changed located global variable declaration and init to reflec recent change on located vars (pointers)
etisserant
parents:
122
diff
changeset
|
1916 |
symbol->global_var_name->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1917 |
s4o.print(","); |
128
fd5760f30682
Changed located global variable declaration and init to reflec recent change on located vars (pointers)
etisserant
parents:
122
diff
changeset
|
1918 |
symbol->location->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1919 |
print_retain(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1920 |
s4o.print(")"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1921 |
} |
70 | 1922 |
if (this->current_var_init_symbol != NULL) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1923 |
s4o.print(nv->get()); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1924 |
s4o.print(s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1925 |
s4o.print(INIT_GLOBAL); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1926 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1927 |
if (symbol->global_var_name != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1928 |
symbol->global_var_name->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1929 |
else |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1930 |
symbol->location->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1931 |
s4o.print(","); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1932 |
this->current_var_init_symbol->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1933 |
print_retain(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1934 |
s4o.print(")"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1935 |
} |
70 | 1936 |
break; |
1937 |
||
1938 |
default: |
|
1939 |
ERROR; |
|
1940 |
} /* switch() */ |
|
1941 |
||
1942 |
return NULL; |
|
1943 |
} |
|
1944 |
||
1945 |
||
1946 |
||
1947 |
/* AT direct_variable */ |
|
1948 |
// SYM_REF2(location_c, direct_variable, unused) |
|
1949 |
void *visit(location_c *symbol) { |
|
1950 |
TRACE("location_c"); |
|
1951 |
return symbol->direct_variable->accept(*this); |
|
1952 |
} |
|
1953 |
||
1954 |
||
1955 |
/*| global_var_list ',' global_var_name */ |
|
1956 |
//SYM_LIST(global_var_list_c) |
|
1957 |
void *visit(global_var_list_c *symbol) { |
|
1958 |
TRACE("global_var_list_c"); |
|
1959 |
list_c *list = dynamic_cast<list_c *>(symbol); |
|
1960 |
/* should NEVER EVER occur!! */ |
|
1961 |
if (list == NULL) ERROR; |
|
1962 |
||
1963 |
/* now to produce the c equivalent... */ |
|
1964 |
switch (wanted_varformat) { |
|
1965 |
case local_vf: |
|
1966 |
case localinit_vf: |
|
1967 |
for(int i = 0; i < list->n; i++) { |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1968 |
s4o.print(s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1969 |
s4o.print(DECLARE_GLOBAL); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1970 |
s4o.print("("); |
70 | 1971 |
this->current_var_type_symbol->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1972 |
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
|
1973 |
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
|
1974 |
this->resource_name->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1975 |
s4o.print(","); |
70 | 1976 |
list->elements[i]->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1977 |
s4o.print(")\n"); |
70 | 1978 |
} |
1979 |
break; |
|
1980 |
||
1981 |
case constructorinit_vf: |
|
1982 |
if (this->current_var_init_symbol != NULL) { |
|
1983 |
for(int i = 0; i < list->n; i++) { |
|
1984 |
s4o.print(nv->get()); |
|
1985 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1986 |
s4o.print(INIT_GLOBAL); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1987 |
s4o.print("("); |
70 | 1988 |
list->elements[i]->accept(*this); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1989 |
s4o.print(","); |
70 | 1990 |
this->current_var_init_symbol->accept(*this); |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
217
diff
changeset
|
1991 |
print_retain(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
1992 |
s4o.print(")"); |
70 | 1993 |
#if 0 |
1994 |
/* The following code would be for globalinit_vf !! |
|
1995 |
* But it is not currently required... |
|
1996 |
*/ |
|
1997 |
s4o.print(s4o.indent_spaces + "__ext_element_c<"); |
|
1998 |
this->current_var_type_symbol->accept(*this); |
|
1999 |
s4o.print("> "); |
|
2000 |
if (this->globalnamespace != NULL) { |
|
2001 |
this->globalnamespace->accept(*this); |
|
2002 |
s4o.print("::"); |
|
2003 |
} |
|
2004 |
list->elements[i]->accept(*this); |
|
2005 |
||
2006 |
if (this->current_var_init_symbol != NULL) { |
|
2007 |
s4o.print(" = "); |
|
2008 |
s4o.print("__ext_element_c<"); |
|
2009 |
this->current_var_type_symbol->accept(*this); |
|
2010 |
s4o.print(">("); |
|
2011 |
this->current_var_init_symbol->accept(*this); |
|
2012 |
s4o.print(")"); |
|
2013 |
} |
|
2014 |
s4o.print(";\n"); |
|
2015 |
#endif |
|
2016 |
} |
|
2017 |
} |
|
2018 |
break; |
|
2019 |
||
2020 |
default: |
|
2021 |
ERROR; /* not supported, and not needed either... */ |
|
2022 |
} |
|
2023 |
||
2024 |
return NULL; |
|
2025 |
} |
|
2026 |
||
2027 |
||
2028 |
#if 0 |
|
2029 |
/* var1_list ':' single_byte_string_spec */ |
|
2030 |
SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
2031 |
||
2032 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
2033 |
/* integer ->may be NULL ! */ |
|
2034 |
/* single_byte_character_string ->may be NULL ! */ |
|
2035 |
SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
2036 |
||
2037 |
/* var1_list ':' double_byte_string_spec */ |
|
2038 |
SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
2039 |
||
2040 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
2041 |
/* integer ->may be NULL ! */ |
|
2042 |
/* double_byte_character_string ->may be NULL ! */ |
|
2043 |
SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
2044 |
||
2045 |
/*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ |
|
2046 |
/* option ->may be NULL ! */ |
|
2047 |
SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list) |
|
2048 |
||
2049 |
/* helper symbol for incompl_located_var_declarations */ |
|
2050 |
/*| incompl_located_var_decl_list incompl_located_var_decl ';' */ |
|
2051 |
SYM_LIST(incompl_located_var_decl_list_c) |
|
2052 |
||
2053 |
/* variable_name incompl_location ':' var_spec */ |
|
2054 |
SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
2055 |
||
2056 |
/* AT incompl_location_token */ |
|
2057 |
SYM_TOKEN(incompl_location_c) |
|
2058 |
#endif |
|
2059 |
||
2060 |
||
2061 |
void *visit(falling_edge_option_c *symbol) { |
|
2062 |
// TO DO ... |
|
2063 |
s4o.print("F_EDGE"); |
|
2064 |
return NULL; |
|
2065 |
} |
|
2066 |
||
2067 |
||
2068 |
void *visit(var1_init_decl_c *symbol) { |
|
2069 |
TRACE("var1_init_decl_c"); |
|
2070 |
/* We have several implementation alternatives here... |
|
2071 |
* |
|
2072 |
* The issue is that generation of c code |
|
2073 |
* based on the abstract syntax tree requires the reversal |
|
2074 |
* of the symbol order compared to st. For e.g.: |
|
2075 |
* (ST) a, b, c: INT := 98; |
|
2076 |
* (C ) int a=98, b=98, c=98; |
|
2077 |
* The spec_init contains the references to 'INT' and '98'. |
|
2078 |
* The var1_list contains the references to 'a', 'b', and 'c'. |
|
2079 |
* The var1_init_decl_c contains the references to spec_init and var1_list. |
|
2080 |
* |
|
2081 |
* For c code generation, the var1_init_decl_c visitor |
|
2082 |
* would need to access the internals of other classes |
|
2083 |
* (e.g. the simple_spec_init_c). |
|
2084 |
* |
|
2085 |
* We can do this using one of three methods: |
|
2086 |
* 1) Create the abstract syntax tree differently; |
|
2087 |
* 2) Access other classes from within the var1_init_decl_c; |
|
2088 |
* 3) Pass info between the visitors using global variables |
|
2089 |
* only acessible by this class (private vars) |
|
2090 |
* |
|
2091 |
* In 1), the abstract syntax tree would be built so that |
|
2092 |
* var1_init_decl_c would contain direct references to |
|
2093 |
* var1_list_c, to the var type 'INT' and to the initialiser '98' |
|
2094 |
* (as per the example above). |
|
2095 |
* |
|
2096 |
* 2) would have several sub-options to obtain the references |
|
2097 |
* to 'INT' and '98' from within var1_init_decl_c. |
|
2098 |
* In 2a), the var1_init_decl_c would use dynamic casts to determine |
|
2099 |
* the class of spec_init (simple_spec_init_c, subrange_spec_init_c or |
|
2100 |
* enumerated_spec_init_c), and from there obtain the 'INT' and '98' |
|
2101 |
* In 2b) var1_init_decl_c would have one reference for each |
|
2102 |
* simple_spec_init_c, subrange_spec_init_c and enumerated_spec_init_c, |
|
2103 |
* the apropriate one being initialised by the var1_init_decl_c constructor. |
|
2104 |
* Note that the constructor would use dynamic casts. In essence, we |
|
2105 |
* would merely be changing the location of the code with the |
|
2106 |
* dynamic casts. |
|
2107 |
* In 2c) we would use three overloaded constructors for var1_init_decl_c |
|
2108 |
* one each for simple_spec_init_c, etc... This implies |
|
2109 |
* use type specific pointers to each symbol in the bison |
|
2110 |
* parser, instead of simply using a symbol_c * for all symbols; |
|
2111 |
* |
|
2112 |
* In 3), we use two global but private variables with references to |
|
2113 |
* 'INT' and '98', that would be initiliased by the visitors to |
|
2114 |
* simple_spec_init_c, subrange_spec_init_c and enumerated_spec_init_c. |
|
2115 |
* The visitor to var1_list_c would then use the references in the global |
|
2116 |
* variables. |
|
2117 |
* |
|
2118 |
* I (Mario) have chosen to use 3). |
|
2119 |
*/ |
|
2120 |
||
2121 |
/* Start off by setting the current_var_type_symbol and |
|
2122 |
* current_var_init_symbol private variables... |
|
2123 |
*/ |
|
2124 |
update_type_init(symbol->spec_init); |
|
2125 |
||
2126 |
/* now to produce the c equivalent... */ |
|
2127 |
symbol->var1_list->accept(*this); |
|
2128 |
||
2129 |
/* Values no longer in scope, and therefore no longer used. |
|
2130 |
* Make an effort to keep them set to NULL when not in use |
|
2131 |
* in order to catch bugs as soon as possible... |
|
2132 |
*/ |
|
2133 |
void_type_init(); |
|
2134 |
||
2135 |
return NULL; |
|
2136 |
} |
|
2137 |
||
2138 |
||
2139 |
||
2140 |
void *visit(var1_list_c *symbol) { |
|
2141 |
TRACE("var1_list_c"); |
|
2142 |
declare_variables(symbol); |
|
2143 |
return NULL; |
|
2144 |
} |
|
2145 |
||
2146 |
||
2147 |
||
2148 |
||
2149 |
/* intermediate helper symbol for: |
|
2150 |
* - non_retentive_var_decls |
|
2151 |
* - output_declarations |
|
2152 |
*/ |
|
2153 |
void *visit(var_init_decl_list_c *symbol) { |
|
2154 |
TRACE("var_init_decl_list_c"); |
|
2155 |
return print_list(symbol); |
|
2156 |
return NULL; |
|
2157 |
} |
|
2158 |
||
2159 |
||
2160 |
/**************************************/ |
|
2161 |
/* B.1.5 - Program organization units */ |
|
2162 |
/**************************************/ |
|
2163 |
/***********************/ |
|
2164 |
/* B 1.5.1 - Functions */ |
|
2165 |
/***********************/ |
|
2166 |
/* The missing function_declaration_c |
|
2167 |
* is handled in derived classes |
|
2168 |
*/ |
|
2169 |
||
2170 |
||
2171 |
||
2172 |
/* intermediate helper symbol for function_declaration */ |
|
2173 |
void *visit(var_declarations_list_c *symbol) { |
|
2174 |
TRACE("var_declarations_list_c"); |
|
2175 |
return print_list(symbol); |
|
2176 |
} |
|
2177 |
||
2178 |
||
2179 |
void *visit(function_var_decls_c *symbol) { |
|
2180 |
TRACE("function_var_decls_c"); |
|
2181 |
||
2182 |
if ((wanted_vartype & private_vt) != 0) { |
|
2183 |
/* |
|
2184 |
// TO DO ... |
|
2185 |
if (symbol->option != NULL) |
|
2186 |
symbol->option->accept(*this); |
|
2187 |
*/ |
|
2188 |
current_vartype = private_vt; |
|
2189 |
symbol->decl_list->accept(*this); |
|
2190 |
current_vartype = none_vt; |
|
2191 |
} |
|
2192 |
return NULL; |
|
2193 |
} |
|
2194 |
||
2195 |
||
2196 |
/* intermediate helper symbol for function_var_decls */ |
|
2197 |
void *visit(var2_init_decl_list_c *symbol) { |
|
2198 |
TRACE("var2_init_decl_list_c"); |
|
2199 |
print_list(symbol); |
|
2200 |
return NULL; |
|
2201 |
} |
|
2202 |
||
2203 |
||
2204 |
/*****************************/ |
|
2205 |
/* B 1.5.2 - Function Blocks */ |
|
2206 |
/*****************************/ |
|
2207 |
||
2208 |
/* The missing function_block_declaration_c |
|
2209 |
* is handled in derived classes |
|
2210 |
*/ |
|
2211 |
||
2212 |
||
2213 |
/* VAR_TEMP temp_var_decl_list END_VAR */ |
|
2214 |
void *visit(temp_var_decls_c *symbol) { |
|
2215 |
TRACE("temp_var_decls_c"); |
|
2216 |
if ((wanted_vartype & temp_vt) != 0) { |
|
2217 |
current_vartype = temp_vt; |
|
2218 |
symbol->var_decl_list->accept(*this); |
|
2219 |
current_vartype = none_vt; |
|
2220 |
} |
|
2221 |
return NULL; |
|
2222 |
} |
|
2223 |
||
2224 |
/* intermediate helper symbol for temp_var_decls */ |
|
2225 |
void *visit(temp_var_decls_list_c *symbol) { |
|
2226 |
TRACE("temp_var_decls_list_c"); |
|
2227 |
return print_list(symbol); |
|
2228 |
} |
|
2229 |
||
2230 |
/* VAR NON_RETAIN var_init_decl_list END_VAR */ |
|
2231 |
void *visit(non_retentive_var_decls_c *symbol) { |
|
2232 |
TRACE("non_retentive_var_decls_c"); |
|
2233 |
// TODO ... guarantee the non-retain semantics! |
|
2234 |
if ((wanted_vartype & private_vt) != 0) { |
|
2235 |
current_vartype = private_vt; |
|
2236 |
symbol->var_decl_list->accept(*this); |
|
2237 |
current_vartype = none_vt; |
|
2238 |
} |
|
2239 |
return NULL; |
|
2240 |
} |
|
2241 |
||
2242 |
||
2243 |
||
2244 |
/**********************/ |
|
2245 |
/* B 1.5.3 - Programs */ |
|
2246 |
/**********************/ |
|
2247 |
/* leave for derived classes... */ |
|
2248 |
||
2249 |
/*********************************************/ |
|
2250 |
/* B.1.6 Sequential function chart elements */ |
|
2251 |
/*********************************************/ |
|
2252 |
||
2253 |
/********************************/ |
|
2254 |
/* B 1.7 Configuration elements */ |
|
2255 |
/********************************/ |
|
2256 |
/* Programs instantiated inside configurations are declared as variables!! */ |
|
2257 |
||
2258 |
/* |
|
2259 |
CONFIGURATION configuration_name |
|
2260 |
optional_global_var_declarations |
|
2261 |
(resource_declaration_list | single_resource_declaration) |
|
2262 |
optional_access_declarations |
|
2263 |
optional_instance_specific_initializations |
|
2264 |
END_CONFIGURATION |
|
2265 |
*/ |
|
2266 |
/* |
|
2267 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
2268 |
*/ |
|
2269 |
void *visit(configuration_declaration_c *symbol) { |
|
2270 |
TRACE("configuration_declaration_c"); |
|
2271 |
||
2272 |
if(symbol->global_var_declarations) |
|
2273 |
symbol->global_var_declarations->accept(*this); // will contain VAR_GLOBAL declarations!! |
|
2274 |
symbol->resource_declarations->accept(*this); // will contain PROGRAM declarations!! |
|
2275 |
return NULL; |
|
2276 |
} |
|
2277 |
||
2278 |
||
2279 |
/* helper symbol for configuration_declaration */ |
|
2280 |
// SYM_LIST(resource_declaration_list_c) |
|
2281 |
void *visit(resource_declaration_list_c *symbol) { |
|
2282 |
TRACE("resource_declaration_list_c"); |
|
2283 |
||
2284 |
return print_list(symbol); |
|
2285 |
} |
|
2286 |
||
2287 |
/* |
|
2288 |
RESOURCE resource_name ON resource_type_name |
|
2289 |
optional_global_var_declarations |
|
2290 |
single_resource_declaration |
|
2291 |
END_RESOURCE |
|
2292 |
*/ |
|
2293 |
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
2294 |
void *visit(resource_declaration_c *symbol) { |
|
2295 |
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
|
2296 |
//// 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
|
2297 |
// 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
|
2298 |
// 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
|
2299 |
// 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
|
2300 |
// |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
2301 |
// 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
|
2302 |
// 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
|
2303 |
// 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
|
2304 |
// 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
|
2305 |
// 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
|
2306 |
// 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
|
2307 |
// |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
128
diff
changeset
|
2308 |
// 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
|
2309 |
// 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
|
2310 |
// 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
|
2311 |
// 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
|
2312 |
// } |
70 | 2313 |
return NULL; |
2314 |
} |
|
2315 |
||
2316 |
/* task_configuration_list program_configuration_list */ |
|
2317 |
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
2318 |
void *visit(single_resource_declaration_c *symbol) { |
|
2319 |
TRACE("single_resource_declaration_c"); |
|
2320 |
||
2321 |
if ((wanted_vartype & program_vt) != 0) { |
|
2322 |
unsigned int previous_vartype = current_vartype; |
|
2323 |
// previous_vartype will be resource_vt |
|
2324 |
current_vartype = program_vt; |
|
2325 |
symbol->program_configuration_list->accept(*this); |
|
2326 |
current_vartype = previous_vartype; |
|
2327 |
} |
|
2328 |
return NULL; |
|
2329 |
} |
|
2330 |
||
2331 |
||
2332 |
/* helper symbol for single_resource_declaration */ |
|
2333 |
// SYM_LIST(task_configuration_list_c) |
|
2334 |
||
2335 |
||
2336 |
/* helper symbol for single_resource_declaration */ |
|
2337 |
/* | program_configuration_list program_configuration ';' */ |
|
2338 |
// SYM_LIST(program_configuration_list_c) |
|
2339 |
void *visit(program_configuration_list_c *symbol) { |
|
2340 |
TRACE("program_configuration_list_c"); |
|
2341 |
||
2342 |
return print_list(symbol); |
|
2343 |
} |
|
2344 |
||
2345 |
/* helper symbol for |
|
2346 |
* - access_path |
|
2347 |
* - instance_specific_init |
|
2348 |
*/ |
|
2349 |
// SYM_LIST(any_fb_name_list_c) |
|
2350 |
||
2351 |
/* [resource_name '.'] global_var_name ['.' structure_element_name] */ |
|
2352 |
// SYM_REF4(global_var_reference_c, resource_name, global_var_name, structure_element_name, unused) |
|
2353 |
||
2354 |
/* prev_declared_program_name '.' symbolic_variable */ |
|
2355 |
// SYM_REF2(program_output_reference_c, program_name, symbolic_variable) |
|
2356 |
||
2357 |
/* TASK task_name task_initialization */ |
|
2358 |
// SYM_REF2(task_configuration_c, task_name, task_initialization) |
|
2359 |
||
2360 |
/* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */ |
|
2361 |
// SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused) |
|
2362 |
||
2363 |
/* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
2364 |
// SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
2365 |
private: |
|
2366 |
/* a helper function to the program_configuration_c visitor... */ |
|
2367 |
void program_constructor_call(program_configuration_c *symbol) { |
|
2368 |
program_declaration_c *p_decl = program_type_symtable.find_value(symbol->program_type_name); |
|
2369 |
||
2370 |
if (p_decl == program_type_symtable.end_value()) |
|
2371 |
/* should never occur. The program being called MUST be in the symtable... */ |
|
2372 |
ERROR; |
|
2373 |
||
2374 |
symbol->program_name->accept(*this); |
|
2375 |
s4o.print("("); |
|
2376 |
||
2377 |
/* loop through each function parameter, find the value we should pass |
|
2378 |
* to it, and then output the c equivalent... |
|
2379 |
*/ |
|
2380 |
function_param_iterator_c fp_iterator(p_decl); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
2381 |
#if 0 |
70 | 2382 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
195
diff
changeset
|
2383 |
#endif |
70 | 2384 |
identifier_c *param_name; |
2385 |
nv->push("", ", "); |
|
2386 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
2387 |
||
2388 |
symbol_c *param_type = fp_iterator.param_type(); |
|
2389 |
if (param_type == NULL) ERROR; |
|
2390 |
||
2391 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
2392 |
||
2393 |
#if 0 |
|
2394 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
2395 |
symbol_c *param_value = function_call_param_iterator.search(param_name); |
|
2396 |
#endif |
|
2397 |
||
2398 |
switch (param_direction) { |
|
2399 |
case function_param_iterator_c::direction_in: |
|
2400 |
case function_param_iterator_c::direction_out: |
|
2401 |
case function_param_iterator_c::direction_inout: |
|
2402 |
/* ignore them all!! */ |
|
2403 |
break; |
|
2404 |
||
2405 |
case function_param_iterator_c::direction_extref: |
|
2406 |
#if 0 |
|
2407 |
if (param_value == NULL) |
|
2408 |
/* This is illegal in ST and IL languages. |
|
2409 |
* All variables declared in a VAR_EXTERNAL __must__ |
|
2410 |
* be initialised to reference a specific VAR_GLOBAL variable!! |
|
2411 |
* |
|
2412 |
* The semantic checker should have caught this, we check again just the |
|
2413 |
* same (especially since the semantic checker has not yet been written!). |
|
2414 |
*/ |
|
2415 |
ERROR; |
|
2416 |
s4o.print(nv->get()); |
|
2417 |
s4o.print("&"); |
|
2418 |
param_value->accept(*this); |
|
2419 |
#endif |
|
2420 |
break; |
|
2421 |
} /* switch */ |
|
2422 |
} /* for(...) */ |
|
2423 |
||
2424 |
// symbol->parameter_assignment->accept(*this); |
|
2425 |
s4o.print(")"); |
|
2426 |
nv->pop(); |
|
2427 |
return; |
|
2428 |
} |
|
2429 |
||
2430 |
||
2431 |
public: |
|
2432 |
void *visit(program_configuration_c *symbol) { |
|
2433 |
TRACE("program_configuration_c"); |
|
2434 |
||
2435 |
/* now to produce the c equivalent... */ |
|
2436 |
switch (wanted_varformat) { |
|
2437 |
case local_vf: |
|
2438 |
case localinit_vf: |
|
2439 |
s4o.print(s4o.indent_spaces); |
|
2440 |
symbol->program_type_name->accept(*this); |
|
2441 |
s4o.print(" "); |
|
2442 |
symbol->program_name->accept(*this); |
|
2443 |
if (wanted_varformat == localinit_vf) { |
|
2444 |
// TODO... |
|
2445 |
// program_call(symbol); |
|
2446 |
} |
|
2447 |
s4o.print(";\n"); |
|
2448 |
break; |
|
2449 |
||
2450 |
case constructorinit_vf: |
|
2451 |
s4o.print(nv->get()); |
|
2452 |
program_constructor_call(symbol); |
|
2453 |
/* |
|
2454 |
symbol->program_name->accept(*this); |
|
2455 |
s4o.print("("); |
|
2456 |
symbol->prog_conf_elements->accept(*this); |
|
2457 |
nv->pop(); |
|
2458 |
s4o.print(")"); |
|
2459 |
*/ |
|
2460 |
break; |
|
2461 |
||
2462 |
default: |
|
2463 |
ERROR; /* not supported, and not needed either... */ |
|
2464 |
} |
|
2465 |
||
2466 |
return NULL; |
|
2467 |
} |
|
2468 |
||
2469 |
||
2470 |
||
2471 |
/* prog_conf_elements ',' prog_conf_element */ |
|
2472 |
//SYM_LIST(prog_conf_elements_c) |
|
2473 |
void *visit(prog_conf_elements_c *symbol) { |
|
2474 |
TRACE("prog_conf_elements_c"); |
|
2475 |
||
2476 |
return print_list(symbol); |
|
2477 |
} |
|
2478 |
||
2479 |
/* fb_name WITH task_name */ |
|
2480 |
//SYM_REF2(fb_task_c, fb_name, task_name) |
|
2481 |
void *visit(fb_task_c *symbol) { |
|
2482 |
TRACE("fb_task_c"); |
|
2483 |
||
2484 |
/* TODO... |
|
2485 |
* |
|
2486 |
* NOTE: Not yet supported... |
|
2487 |
* We do not support allocating specific function blocks declared |
|
2488 |
* inside a program to be executed by a different task from the one |
|
2489 |
* already executing the program itself. |
|
2490 |
* This is mostly because I (Mario) simply do not understand the |
|
2491 |
* semantics the standard expects us to implement in this case. It is all |
|
2492 |
* very confusing, and very poorly defined in the standard! |
|
2493 |
*/ |
|
2494 |
ERROR; |
|
2495 |
return NULL; |
|
2496 |
} |
|
2497 |
||
2498 |
||
2499 |
||
2500 |
||
2501 |
||
2502 |
||
2503 |
||
2504 |
||
2505 |
||
2506 |
||
2507 |
||
2508 |
||
2509 |
||
2510 |
||
2511 |
||
2512 |
||
2513 |
||
2514 |
||
2515 |
||
2516 |
||
2517 |
||
2518 |
||
2519 |
||
2520 |
||
2521 |
||
2522 |
||
2523 |
||
2524 |
/* any_symbolic_variable ASSIGN prog_data_source */ |
|
2525 |
// SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source) |
|
2526 |
void *visit(prog_cnxn_assign_c *symbol) { |
|
2527 |
TRACE("prog_cnxn_assign_c"); |
|
2528 |
||
2529 |
/* TODO... */ |
|
2530 |
return NULL; |
|
2531 |
} |
|
2532 |
||
2533 |
/* any_symbolic_variable SENDTO data_sink */ |
|
2534 |
// SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, prog_data_source) |
|
2535 |
void *visit(prog_cnxn_sendto_c *symbol) { |
|
2536 |
TRACE("prog_cnxn_sendto_c"); |
|
2537 |
||
2538 |
/* TODO... */ |
|
2539 |
return NULL; |
|
2540 |
} |
|
2541 |
||
2542 |
#if 0 |
|
2543 |
/* VAR_CONFIG instance_specific_init_list END_VAR_BOGUS */ |
|
2544 |
SYM_REF2(instance_specific_initializations_c, instance_specific_init_list, unused) |
|
2545 |
||
2546 |
/* helper symbol for instance_specific_initializations */ |
|
2547 |
SYM_LIST(instance_specific_init_list_c) |
|
2548 |
||
2549 |
/* resource_name '.' program_name '.' {fb_name '.'} |
|
2550 |
((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization)) |
|
2551 |
*/ |
|
2552 |
SYM_REF6(instance_specific_init_c, resource_name, program_name, any_fb_name_list, variable_name, location, initialization) |
|
2553 |
||
2554 |
/* helper symbol for instance_specific_init */ |
|
2555 |
/* function_block_type_name ':=' structure_initialization */ |
|
2556 |
SYM_REF2(fb_initialization_c, function_block_type_name, structure_initialization) |
|
2557 |
||
2558 |
#endif |
|
2559 |
||
2560 |
||
2561 |
||
2562 |
||
2563 |
/****************************************/ |
|
2564 |
/* B.2 - Language IL (Instruction List) */ |
|
2565 |
/****************************************/ |
|
2566 |
/***********************************/ |
|
2567 |
/* B 2.1 Instructions and Operands */ |
|
2568 |
/***********************************/ |
|
2569 |
/* leave for derived classes... */ |
|
2570 |
||
2571 |
/*******************/ |
|
2572 |
/* B 2.2 Operators */ |
|
2573 |
/*******************/ |
|
2574 |
/* leave for derived classes... */ |
|
2575 |
||
2576 |
||
2577 |
/***************************************/ |
|
2578 |
/* B.3 - Language ST (Structured Text) */ |
|
2579 |
/***************************************/ |
|
2580 |
/***********************/ |
|
2581 |
/* B 3.1 - Expressions */ |
|
2582 |
/***********************/ |
|
2583 |
/* leave for derived classes... */ |
|
2584 |
||
2585 |
/********************/ |
|
2586 |
/* B 3.2 Statements */ |
|
2587 |
/********************/ |
|
2588 |
/* leave for derived classes... */ |
|
2589 |
||
2590 |
/*********************************/ |
|
2591 |
/* B 3.2.1 Assignment Statements */ |
|
2592 |
/*********************************/ |
|
2593 |
/* leave for derived classes... */ |
|
2594 |
||
2595 |
/*****************************************/ |
|
2596 |
/* B 3.2.2 Subprogram Control Statements */ |
|
2597 |
/*****************************************/ |
|
2598 |
/* leave for derived classes... */ |
|
2599 |
||
2600 |
/********************************/ |
|
2601 |
/* B 3.2.3 Selection Statements */ |
|
2602 |
/********************************/ |
|
2603 |
/* leave for derived classes... */ |
|
2604 |
||
2605 |
/********************************/ |
|
2606 |
/* B 3.2.4 Iteration Statements */ |
|
2607 |
/********************************/ |
|
2608 |
/* leave for derived classes... */ |
|
2609 |
||
2610 |
||
2611 |
||
2612 |
}; /* generate_c_vardecl_c */ |
|
2613 |
||
2614 |
||
2615 |