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