author | Mario de Sousa <msousa@fe.up.pt> |
Fri, 29 Jul 2011 16:05:03 +0100 | |
changeset 351 | e7d236750709 |
parent 350 | 2c3c4dc34979 |
child 377 | 60b012b7793f |
permissions | -rwxr-xr-x |
70 | 1 |
/* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
221
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
221
diff
changeset
|
3 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
221
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:
221
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
221
diff
changeset
|
6 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
221
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:
221
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:
221
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:
221
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:
221
diff
changeset
|
11 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
221
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:
221
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:
221
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:
221
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:
221
diff
changeset
|
16 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
221
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:
221
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:
221
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 |
*/ |
|
139
668a54686827
added missing includes on some platform (gentoo/gcc-4.3.1)
etisserant
parents:
123
diff
changeset
|
24 |
#include <stdlib.h> |
70 | 25 |
|
26 |
class generate_c_typedecl_c: public generate_c_base_c { |
|
27 |
||
121 | 28 |
protected: |
29 |
stage4out_c &s4o_incl; |
|
30 |
||
98 | 31 |
private: |
32 |
symbol_c* current_type_name; |
|
309
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
33 |
bool array_is_derived; |
98 | 34 |
search_base_type_c search_base_type; |
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
35 |
search_constant_type_c search_constant_type; |
98 | 36 |
|
121 | 37 |
generate_c_base_c *basedecl; |
38 |
||
70 | 39 |
public: |
121 | 40 |
generate_c_typedecl_c(stage4out_c *s4o_ptr, stage4out_c *s4o_incl_ptr): generate_c_base_c(s4o_ptr), s4o_incl(*s4o_incl_ptr) { |
98 | 41 |
current_typedefinition = none_td; |
42 |
current_basetypedeclaration = none_bd; |
|
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
43 |
current_type_name = NULL; |
121 | 44 |
basedecl = new generate_c_base_c(&s4o_incl); |
98 | 45 |
} |
121 | 46 |
generate_c_typedecl_c(stage4out_c *s4o_ptr): generate_c_base_c(s4o_ptr), s4o_incl(*s4o_ptr) { |
47 |
current_typedefinition = none_td; |
|
48 |
current_basetypedeclaration = none_bd; |
|
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
49 |
current_type_name = NULL; |
121 | 50 |
basedecl = new generate_c_base_c(&s4o_incl); |
51 |
} |
|
52 |
~generate_c_typedecl_c(void) { |
|
53 |
delete basedecl; |
|
54 |
} |
|
70 | 55 |
|
98 | 56 |
typedef enum { |
57 |
none_td, |
|
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
58 |
enumerated_td, |
98 | 59 |
subrange_td, |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
60 |
array_td, |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
61 |
struct_td, |
98 | 62 |
} typedefinition_t; |
63 |
||
64 |
typedefinition_t current_typedefinition; |
|
65 |
||
66 |
typedef enum { |
|
67 |
none_bd, |
|
68 |
subrangebasetype_bd, |
|
69 |
subrangetest_bd, |
|
309
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
70 |
arrayderiveddeclaration_bd, |
98 | 71 |
arraybasetype_bd, |
121 | 72 |
arraybasetypeincl_bd, |
98 | 73 |
arraysubrange_bd, |
74 |
arraytranslateindex_bd |
|
75 |
} basetypedeclaration_t; |
|
76 |
||
77 |
basetypedeclaration_t current_basetypedeclaration; |
|
78 |
||
79 |
void print_integer(unsigned int integer) { |
|
80 |
char str[10]; |
|
81 |
sprintf(str, "%d", integer); |
|
82 |
s4o.print(str); |
|
83 |
} |
|
70 | 84 |
|
121 | 85 |
void print_integer_incl(unsigned int integer) { |
86 |
char str[10]; |
|
87 |
sprintf(str, "%d", integer); |
|
88 |
s4o_incl.print(str); |
|
89 |
} |
|
90 |
||
91 |
void *print_list_incl(list_c *list, |
|
92 |
std::string pre_elem_str = "", |
|
93 |
std::string inter_elem_str = "", |
|
94 |
std::string post_elem_str = "", |
|
95 |
visitor_c *visitor = NULL) { |
|
96 |
if (visitor == NULL) visitor = this; |
|
97 |
||
98 |
if (list->n > 0) { |
|
99 |
//std::cout << "generate_c_base_c::print_list(n = " << list->n << ") 000\n"; |
|
100 |
s4o_incl.print(pre_elem_str); |
|
101 |
list->elements[0]->accept(*visitor); |
|
102 |
} |
|
103 |
||
104 |
for(int i = 1; i < list->n; i++) { |
|
105 |
//std::cout << "generate_c_base_c::print_list " << i << "\n"; |
|
106 |
s4o_incl.print(inter_elem_str); |
|
107 |
list->elements[i]->accept(*visitor); |
|
108 |
} |
|
109 |
||
110 |
if (list->n > 0) |
|
111 |
s4o_incl.print(post_elem_str); |
|
112 |
||
113 |
return NULL; |
|
114 |
} |
|
115 |
||
116 |
||
70 | 117 |
/***************************/ |
118 |
/* B 0 - Programming Model */ |
|
119 |
/***************************/ |
|
120 |
/* leave for derived classes... */ |
|
121 |
||
122 |
/*************************/ |
|
123 |
/* B.1 - Common elements */ |
|
124 |
/*************************/ |
|
125 |
/*******************************************/ |
|
126 |
/* B 1.1 - Letters, digits and identifiers */ |
|
127 |
/*******************************************/ |
|
128 |
/* done in base class(es) */ |
|
129 |
||
130 |
/*********************/ |
|
131 |
/* B 1.2 - Constants */ |
|
132 |
/*********************/ |
|
133 |
/* originally empty... */ |
|
134 |
||
135 |
/******************************/ |
|
136 |
/* B 1.2.1 - Numeric Literals */ |
|
137 |
/******************************/ |
|
138 |
/* done in base class(es) */ |
|
139 |
||
140 |
/*******************************/ |
|
141 |
/* B.1.2.2 Character Strings */ |
|
142 |
/*******************************/ |
|
143 |
/* done in base class(es) */ |
|
144 |
||
145 |
/***************************/ |
|
146 |
/* B 1.2.3 - Time Literals */ |
|
147 |
/***************************/ |
|
148 |
/************************/ |
|
149 |
/* B 1.2.3.1 - Duration */ |
|
150 |
/************************/ |
|
151 |
/* done in base class(es) */ |
|
152 |
||
153 |
/************************************/ |
|
154 |
/* B 1.2.3.2 - Time of day and Date */ |
|
155 |
/************************************/ |
|
156 |
/* done in base class(es) */ |
|
157 |
||
158 |
/**********************/ |
|
159 |
/* B.1.3 - Data types */ |
|
160 |
/**********************/ |
|
161 |
/***********************************/ |
|
162 |
/* B 1.3.1 - Elementary Data Types */ |
|
163 |
/***********************************/ |
|
164 |
/* done in base class(es) */ |
|
165 |
||
166 |
/********************************/ |
|
167 |
/* B.1.3.2 - Generic data types */ |
|
168 |
/********************************/ |
|
169 |
/* originally empty... */ |
|
170 |
||
171 |
/********************************/ |
|
172 |
/* B 1.3.3 - Derived data types */ |
|
173 |
/********************************/ |
|
98 | 174 |
/* subrange_type_name ':' subrange_spec_init */ |
175 |
void *visit(subrange_type_declaration_c *symbol) { |
|
176 |
TRACE("subrange_type_declaration_c"); |
|
177 |
||
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
178 |
current_typedefinition = subrange_td; |
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
179 |
current_type_name = symbol->subrange_type_name; |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
180 |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
178
diff
changeset
|
181 |
s4o_incl.print("__DECLARE_DERIVED_TYPE("); |
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
182 |
current_type_name->accept(*basedecl); |
327 | 183 |
s4o_incl.print(","); |
98 | 184 |
current_basetypedeclaration = subrangebasetype_bd; |
185 |
symbol->subrange_spec_init->accept(*this); |
|
186 |
current_basetypedeclaration = none_bd; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
178
diff
changeset
|
187 |
s4o_incl.print(")\n"); |
98 | 188 |
|
189 |
current_basetypedeclaration = subrangetest_bd; |
|
190 |
symbol->subrange_spec_init->accept(*this); |
|
191 |
current_basetypedeclaration = none_bd; |
|
192 |
||
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
193 |
current_type_name = NULL; |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
194 |
current_typedefinition = none_td; |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
195 |
|
98 | 196 |
return NULL; |
197 |
} |
|
198 |
||
199 |
/* subrange_specification ASSIGN signed_integer */ |
|
70 | 200 |
void *visit(subrange_spec_init_c *symbol) { |
201 |
TRACE("subrange_spec_init_c"); |
|
98 | 202 |
symbol->subrange_specification->accept(*this); |
203 |
return NULL; |
|
204 |
} |
|
205 |
||
206 |
/* integer_type_name '(' subrange')' */ |
|
207 |
void *visit(subrange_specification_c *symbol) { |
|
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
208 |
if (current_typedefinition == subrange_td) { |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
209 |
switch (current_basetypedeclaration) { |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
210 |
case subrangebasetype_bd: |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
211 |
symbol->integer_type_name->accept(*basedecl); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
212 |
break; |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
213 |
case subrangetest_bd: |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
214 |
if (symbol->subrange != NULL) { |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
215 |
current_type_name->accept(*this); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
216 |
s4o.print(" __CHECK_"); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
217 |
current_type_name->accept(*this); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
218 |
s4o.print("("); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
219 |
current_type_name->accept(*this); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
220 |
s4o.print(" value) {\n"); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
221 |
s4o.indent_right(); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
222 |
|
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
223 |
if (search_base_type.type_is_subrange(symbol->integer_type_name)) { |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
224 |
s4o.print(s4o.indent_spaces + "value = __CHECK_"); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
225 |
symbol->integer_type_name->accept(*this); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
226 |
s4o.print("(value);\n"); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
227 |
} |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
228 |
|
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
229 |
symbol->subrange->accept(*this); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
230 |
|
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
231 |
s4o.indent_left(); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
232 |
s4o.print("}\n"); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
233 |
} |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
234 |
else { |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
235 |
s4o.print("#define __CHECK_"); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
236 |
current_type_name->accept(*this); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
237 |
s4o.print(" __CHECK_"); |
98 | 238 |
symbol->integer_type_name->accept(*this); |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
239 |
s4o.print("\n"); |
98 | 240 |
} |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
241 |
break; |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
242 |
default: |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
243 |
break; |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
244 |
} |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
245 |
} |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
246 |
else { |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
247 |
symbol->integer_type_name->accept(*basedecl); |
98 | 248 |
} |
249 |
return NULL; |
|
250 |
} |
|
251 |
||
252 |
/* signed_integer DOTDOT signed_integer */ |
|
253 |
void *visit(subrange_c *symbol) { |
|
254 |
int dimension; |
|
255 |
switch (current_typedefinition) { |
|
256 |
case array_td: |
|
257 |
if (current_basetypedeclaration == arraysubrange_bd) { |
|
121 | 258 |
s4o_incl.print("["); |
98 | 259 |
dimension = extract_integer(symbol->upper_limit) - extract_integer(symbol->lower_limit) + 1; |
121 | 260 |
print_integer_incl(dimension); |
261 |
s4o_incl.print("]"); |
|
98 | 262 |
} |
263 |
else |
|
264 |
symbol->lower_limit->accept(*this); |
|
265 |
break; |
|
266 |
case subrange_td: |
|
267 |
s4o.print(s4o.indent_spaces + "if (value < "); |
|
268 |
symbol->lower_limit->accept(*this); |
|
269 |
s4o.print(")\n"); |
|
270 |
s4o.indent_right(); |
|
271 |
s4o.print(s4o.indent_spaces + "return "); |
|
272 |
symbol->lower_limit->accept(*this); |
|
273 |
s4o.print(";\n"); |
|
274 |
s4o.indent_left(); |
|
275 |
s4o.print(s4o.indent_spaces + "else if (value > "); |
|
276 |
symbol->upper_limit->accept(*this); |
|
277 |
s4o.print(")\n"); |
|
278 |
s4o.indent_right(); |
|
279 |
s4o.print(s4o.indent_spaces + "return "); |
|
280 |
symbol->upper_limit->accept(*this); |
|
281 |
s4o.print(";\n"); |
|
282 |
s4o.indent_left(); |
|
283 |
s4o.print(s4o.indent_spaces + "else\n"); |
|
284 |
s4o.indent_right(); |
|
285 |
s4o.print(s4o.indent_spaces + "return value;\n"); |
|
286 |
s4o.indent_left(); |
|
287 |
default: |
|
288 |
break; |
|
289 |
} |
|
290 |
return NULL; |
|
291 |
} |
|
292 |
||
293 |
/* enumerated_type_name ':' enumerated_spec_init */ |
|
294 |
void *visit(enumerated_type_declaration_c *symbol) { |
|
295 |
TRACE("enumerated_type_declaration_c"); |
|
296 |
||
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
297 |
current_typedefinition = enumerated_td; |
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
298 |
current_type_name = symbol->enumerated_type_name; |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
299 |
|
327 | 300 |
s4o_incl.print("__DECLARE_ENUMERATED_TYPE("); |
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
301 |
current_type_name->accept(*basedecl); |
327 | 302 |
s4o_incl.print(",\n"); |
121 | 303 |
s4o_incl.indent_right(); |
98 | 304 |
symbol->enumerated_spec_init->accept(*this); |
121 | 305 |
s4o_incl.indent_left(); |
327 | 306 |
s4o_incl.print(")\n"); |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
307 |
|
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
308 |
current_type_name = NULL; |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
309 |
current_typedefinition = none_td; |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
310 |
|
70 | 311 |
return NULL; |
312 |
} |
|
313 |
||
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
314 |
/* enumerated_specification ASSIGN enumerated_value */ |
70 | 315 |
void *visit(enumerated_spec_init_c *symbol) { |
316 |
TRACE("enumerated_spec_init_c"); |
|
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
317 |
if (current_typedefinition == enumerated_td) |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
318 |
symbol->enumerated_specification->accept(*this); |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
319 |
else |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
320 |
symbol->enumerated_specification->accept(*basedecl); |
98 | 321 |
return NULL; |
322 |
} |
|
323 |
||
324 |
/* helper symbol for enumerated_specification->enumerated_spec_init */ |
|
325 |
/* enumerated_value_list ',' enumerated_value */ |
|
326 |
void *visit(enumerated_value_list_c *symbol) { |
|
121 | 327 |
print_list_incl(symbol, s4o_incl.indent_spaces, ",\n"+s4o_incl.indent_spaces, "\n"); |
98 | 328 |
return NULL; |
329 |
} |
|
330 |
||
331 |
/* enumerated_type_name '#' identifier */ |
|
332 |
void *visit(enumerated_value_c *symbol) { |
|
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
333 |
symbol_c *value_type; |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
334 |
if (current_typedefinition == enumerated_td) |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
335 |
current_type_name->accept(*basedecl); |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
336 |
else { |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
337 |
value_type = (symbol_c *)symbol->accept(search_constant_type); |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
338 |
if (value_type == NULL) ERROR; |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
339 |
|
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
340 |
value_type->accept(*basedecl); |
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
341 |
} |
329
882f5f1e5f6f
Adding double underscore in computed enumerated value to avoid conflict with other user defined identifiers
laurent
parents:
328
diff
changeset
|
342 |
s4o_incl.print("__"); |
121 | 343 |
symbol->value->accept(*basedecl); |
98 | 344 |
return NULL; |
345 |
} |
|
346 |
||
347 |
/* identifier ':' array_spec_init */ |
|
348 |
void *visit(array_type_declaration_c *symbol) { |
|
349 |
TRACE("array_type_declaration_c"); |
|
350 |
||
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
351 |
current_typedefinition = array_td; |
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
352 |
current_type_name = symbol->identifier; |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
353 |
|
309
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
354 |
array_is_derived = false; |
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
355 |
current_basetypedeclaration = arrayderiveddeclaration_bd; |
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
356 |
symbol->array_spec_init->accept(*this); |
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
357 |
current_basetypedeclaration = none_bd; |
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
358 |
|
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
359 |
if (array_is_derived) |
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
360 |
s4o_incl.print("__DECLARE_DERIVED_TYPE("); |
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
361 |
else |
322
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
362 |
s4o_incl.print("__DECLARE_ARRAY_TYPE("); |
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
363 |
current_type_name->accept(*basedecl); |
327 | 364 |
s4o_incl.print(","); |
121 | 365 |
current_basetypedeclaration = arraybasetypeincl_bd; |
98 | 366 |
symbol->array_spec_init->accept(*this); |
367 |
current_basetypedeclaration = none_bd; |
|
309
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
368 |
if (!array_is_derived) { |
322
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
369 |
s4o_incl.print(","); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
370 |
current_basetypedeclaration = arraysubrange_bd; |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
371 |
symbol->array_spec_init->accept(*this); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
372 |
current_basetypedeclaration = none_bd; |
309
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
373 |
} |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
178
diff
changeset
|
374 |
s4o_incl.print(")\n"); |
322
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
375 |
|
174 | 376 |
if (search_base_type.type_is_subrange(symbol->identifier)) { |
322
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
377 |
s4o.print("#define __CHECK_"); |
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
378 |
current_type_name->accept(*this); |
322
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
379 |
s4o.print(" __CHECK_"); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
380 |
current_basetypedeclaration = arraybasetype_bd; |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
381 |
symbol->array_spec_init->accept(*this); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
382 |
current_basetypedeclaration = none_bd; |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
383 |
s4o.print("\n"); |
98 | 384 |
} |
322
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
385 |
|
98 | 386 |
current_basetypedeclaration = arraytranslateindex_bd; |
387 |
symbol->array_spec_init->accept(*this); |
|
388 |
current_basetypedeclaration = none_bd; |
|
389 |
s4o.print("\n"); |
|
322
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
390 |
|
328
66cd5d9893dd
Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents:
327
diff
changeset
|
391 |
current_type_name = NULL; |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
392 |
current_typedefinition = none_td; |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
393 |
|
98 | 394 |
return NULL; |
395 |
} |
|
396 |
||
160 | 397 |
/* array_specification [ASSIGN array_initialization] */ |
98 | 398 |
/* array_initialization may be NULL ! */ |
399 |
void *visit(array_spec_init_c *symbol) { |
|
400 |
TRACE("array_spec_init_c"); |
|
160 | 401 |
|
322
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
402 |
if (current_typedefinition == array_td) { |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
403 |
switch (current_basetypedeclaration) { |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
404 |
case arrayderiveddeclaration_bd: |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
405 |
array_is_derived = dynamic_cast<identifier_c *>(symbol->array_specification) != NULL; |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
406 |
break; |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
407 |
case arraytranslateindex_bd: |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
408 |
if (!array_is_derived) |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
409 |
symbol->array_specification->accept(*this); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
410 |
s4o.print("#define __"); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
411 |
current_type_name->accept(*this); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
412 |
s4o.print("_TRANSIDX(row, index) __"); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
413 |
if (array_is_derived) |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
414 |
symbol->array_specification->accept(*this); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
415 |
else |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
416 |
current_type_name->accept(*this); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
417 |
s4o.print("_TRANSIDX##row(index)"); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
418 |
break; |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
419 |
default: |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
420 |
if (array_is_derived) |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
421 |
symbol->array_specification->accept(*basedecl); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
422 |
else |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
423 |
symbol->array_specification->accept(*this); |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
424 |
break; |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
425 |
} |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
426 |
} |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
427 |
else { |
293967b9277d
Fix bug with array attribute in structure declaration
laurent
parents:
310
diff
changeset
|
428 |
symbol->array_specification->accept(*basedecl); |
160 | 429 |
} |
98 | 430 |
return NULL; |
431 |
} |
|
432 |
||
433 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
434 |
void *visit(array_specification_c *symbol) { |
|
435 |
switch (current_basetypedeclaration) { |
|
436 |
case arraybasetype_bd: |
|
437 |
symbol->non_generic_type_name->accept(*this); |
|
438 |
break; |
|
121 | 439 |
case arraybasetypeincl_bd: |
440 |
symbol->non_generic_type_name->accept(*basedecl); |
|
441 |
break; |
|
98 | 442 |
case arraysubrange_bd: |
443 |
case arraytranslateindex_bd: |
|
444 |
symbol->array_subrange_list->accept(*this); |
|
445 |
break; |
|
446 |
default: |
|
447 |
break; |
|
448 |
} |
|
449 |
return NULL; |
|
450 |
} |
|
451 |
||
452 |
/* helper symbol for array_specification */ |
|
453 |
/* array_subrange_list ',' subrange */ |
|
454 |
void *visit(array_subrange_list_c *symbol) { |
|
455 |
if (current_basetypedeclaration == arraytranslateindex_bd) { |
|
456 |
for (int i = 0; i < symbol->n; i++) { |
|
457 |
s4o.print("#define __"); |
|
458 |
current_type_name->accept(*this); |
|
459 |
s4o.print("_TRANSIDX"); |
|
460 |
print_integer(i); |
|
461 |
s4o.print("(index) (index) - "); |
|
462 |
symbol->elements[i]->accept(*this); |
|
463 |
s4o.print("\n"); |
|
464 |
} |
|
465 |
} |
|
466 |
else |
|
467 |
print_list(symbol); |
|
70 | 468 |
return NULL; |
469 |
} |
|
470 |
||
471 |
/* TYPE type_declaration_list END_TYPE */ |
|
472 |
void *visit(data_type_declaration_c *symbol) { |
|
473 |
TRACE("data_type_declaration_c"); |
|
474 |
symbol->type_declaration_list->accept(*this); |
|
475 |
s4o.print("\n\n"); |
|
476 |
return NULL; |
|
477 |
} |
|
478 |
||
479 |
/* helper symbol for data_type_declaration */ |
|
480 |
void *visit(type_declaration_list_c *symbol) { |
|
481 |
TRACE("type_declaration_list_c"); |
|
160 | 482 |
return print_list_incl(symbol, "", "\n", "\n"); |
70 | 483 |
} |
484 |
||
485 |
/* simple_type_name ':' simple_spec_init */ |
|
486 |
void *visit(simple_type_declaration_c *symbol) { |
|
487 |
TRACE("simple_type_declaration_c"); |
|
488 |
||
307
6ea381792f59
Fix missing '(' when declaring new simple derived data type.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
489 |
s4o_incl.print("__DECLARE_DERIVED_TYPE("); |
327 | 490 |
symbol->simple_type_name->accept(*basedecl); |
491 |
s4o_incl.print(","); |
|
70 | 492 |
symbol->simple_spec_init->accept(*this); |
309
f93bcada0f51
Fix bug when declaring data type directly derived from array type
laurent
parents:
307
diff
changeset
|
493 |
s4o_incl.print(")\n"); |
70 | 494 |
return NULL; |
495 |
} |
|
496 |
||
497 |
/* simple_specification [ASSIGN constant] */ |
|
498 |
//SYM_REF2(simple_spec_init_c, simple_specification, constant) |
|
499 |
// <constant> may be NULL |
|
500 |
void *visit(simple_spec_init_c *symbol) { |
|
501 |
TRACE("simple_spec_init_c"); |
|
121 | 502 |
symbol->simple_specification->accept(*basedecl); |
70 | 503 |
return NULL; |
504 |
} |
|
505 |
||
506 |
#if 0 |
|
507 |
/* subrange_type_name ':' subrange_spec_init */ |
|
508 |
SYM_REF2(subrange_type_declaration_c, subrange_type_name, subrange_spec_init) |
|
509 |
||
510 |
/* subrange_specification ASSIGN signed_integer */ |
|
511 |
SYM_REF2(subrange_spec_init_c, subrange_specification, signed_integer) |
|
512 |
||
513 |
/* integer_type_name '(' subrange')' */ |
|
514 |
SYM_REF2(subrange_specification_c, integer_type_name, subrange) |
|
515 |
||
516 |
/* signed_integer DOTDOT signed_integer */ |
|
517 |
SYM_REF2(subrange_c, lower_limit, upper_limit) |
|
518 |
||
519 |
/* enumerated_type_name ':' enumerated_spec_init */ |
|
520 |
SYM_REF2(enumerated_type_declaration_c, enumerated_type_name, enumerated_spec_init) |
|
521 |
||
522 |
/* enumerated_specification ASSIGN enumerated_value */ |
|
523 |
SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value) |
|
524 |
||
525 |
/* helper symbol for enumerated_specification->enumerated_spec_init */ |
|
526 |
/* enumerated_value_list ',' enumerated_value */ |
|
527 |
SYM_LIST(enumerated_value_list_c) |
|
528 |
||
529 |
/* enumerated_type_name '#' identifier */ |
|
530 |
SYM_REF2(enumerated_value_c, type, value) |
|
531 |
||
532 |
/* identifier ':' array_spec_init */ |
|
533 |
SYM_REF2(array_type_declaration_c, identifier, array_spec_init) |
|
534 |
||
535 |
/* array_specification [ASSIGN array_initialization} */ |
|
536 |
/* array_initialization may be NULL ! */ |
|
537 |
SYM_REF2(array_spec_init_c, array_specification, array_initialization) |
|
538 |
||
539 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
540 |
SYM_REF2(array_specification_c, array_subrange_list, non_generic_type_name) |
|
541 |
||
542 |
/* helper symbol for array_specification */ |
|
543 |
/* array_subrange_list ',' subrange */ |
|
544 |
SYM_LIST(array_subrange_list_c) |
|
545 |
||
546 |
/* array_initialization: '[' array_initial_elements_list ']' */ |
|
547 |
/* helper symbol for array_initialization */ |
|
548 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
549 |
SYM_LIST(array_initial_elements_list_c) |
|
550 |
||
551 |
/* integer '(' [array_initial_element] ')' */ |
|
552 |
/* array_initial_element may be NULL ! */ |
|
553 |
SYM_REF2(array_initial_elements_c, integer, array_initial_element) |
|
554 |
#endif |
|
555 |
||
556 |
/* structure_type_name ':' structure_specification */ |
|
557 |
//SYM_REF2(structure_type_declaration_c, structure_type_name, structure_specification) |
|
558 |
void *visit(structure_type_declaration_c *symbol) { |
|
559 |
TRACE("structure_type_declaration_c"); |
|
560 |
||
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
561 |
current_typedefinition = struct_td; |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
562 |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
178
diff
changeset
|
563 |
s4o_incl.print("__DECLARE_STRUCT_TYPE("); |
327 | 564 |
symbol->structure_type_name->accept(*basedecl); |
565 |
s4o_incl.print(","); |
|
70 | 566 |
symbol->structure_specification->accept(*this); |
327 | 567 |
s4o_incl.print(")\n"); |
310
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
568 |
|
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
569 |
current_typedefinition = none_td; |
f111a6986c22
Fix bug when using an enumerated or subrange type to define a structure element
laurent
parents:
309
diff
changeset
|
570 |
|
70 | 571 |
return NULL; |
572 |
} |
|
573 |
||
574 |
/* structure_type_name ASSIGN structure_initialization */ |
|
575 |
/* structure_initialization may be NULL ! */ |
|
576 |
//SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
|
577 |
void *visit(initialized_structure_c *symbol) { |
|
578 |
TRACE("initialized_structure_c"); |
|
164 | 579 |
|
580 |
symbol->structure_type_name->accept(*basedecl); |
|
581 |
||
70 | 582 |
return NULL; |
583 |
} |
|
584 |
||
585 |
/* helper symbol for structure_declaration */ |
|
586 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
587 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
588 |
//SYM_LIST(structure_element_declaration_list_c) |
|
589 |
void *visit(structure_element_declaration_list_c *symbol) { |
|
590 |
TRACE("structure_element_declaration_list_c"); |
|
327 | 591 |
s4o_incl.print("\n"); |
160 | 592 |
s4o_incl.indent_right(); |
593 |
s4o_incl.print(s4o_incl.indent_spaces); |
|
594 |
||
595 |
print_list_incl(symbol, "", s4o_incl.indent_spaces, ""); |
|
596 |
||
597 |
s4o_incl.indent_left(); |
|
598 |
s4o_incl.print(s4o_incl.indent_spaces); |
|
70 | 599 |
return NULL; |
600 |
} |
|
601 |
||
602 |
/* structure_element_name ':' spec_init */ |
|
603 |
//SYM_REF2(structure_element_declaration_c, structure_element_name, spec_init) |
|
604 |
void *visit(structure_element_declaration_c *symbol) { |
|
605 |
TRACE("structure_element_declaration_c"); |
|
606 |
||
607 |
symbol->spec_init->accept(*this); |
|
160 | 608 |
s4o_incl.print(" "); |
609 |
symbol->structure_element_name->accept(*basedecl); |
|
610 |
s4o_incl.print(";\n"); |
|
611 |
s4o_incl.print(s4o.indent_spaces); |
|
70 | 612 |
|
613 |
return NULL; |
|
614 |
} |
|
615 |
||
616 |
/* helper symbol for structure_initialization */ |
|
617 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
618 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
619 |
//SYM_LIST(structure_element_initialization_list_c) |
|
620 |
void *visit(structure_element_initialization_list_c *symbol) { |
|
621 |
TRACE("structure_element_initialization_list_c"); |
|
622 |
||
623 |
// TODO ??? |
|
160 | 624 |
//ERROR; |
70 | 625 |
return NULL; |
626 |
} |
|
627 |
||
628 |
/* structure_element_name ASSIGN value */ |
|
629 |
//SYM_REF2(structure_element_initialization_c, structure_element_name, value) |
|
630 |
void *visit(structure_element_initialization_c *symbol) { |
|
631 |
TRACE("structure_element_initialization_c"); |
|
632 |
||
633 |
// TODO ??? |
|
160 | 634 |
//ERROR; |
70 | 635 |
return NULL; |
636 |
} |
|
637 |
||
638 |
#if 0 |
|
639 |
/* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
640 |
/* |
|
641 |
* NOTE: |
|
642 |
* (Summary: Contrary to what is expected, the |
|
643 |
* string_type_declaration_c is not used to store |
|
644 |
* simple string type declarations that do not include |
|
645 |
* size limits. |
|
646 |
* For e.g.: |
|
647 |
* str1_type: STRING := "hello!" |
|
648 |
* will be stored in a simple_type_declaration_c |
|
649 |
* instead of a string_type_declaration_c. |
|
650 |
* The following: |
|
651 |
* str2_type: STRING [64] := "hello!" |
|
652 |
* will be stored in a sring_type_declaration_c |
|
653 |
* |
|
654 |
* Read on for why this is done... |
|
655 |
* End Summary) |
|
656 |
* |
|
657 |
* According to the spec, the valid construct |
|
658 |
* TYPE new_str_type : STRING := "hello!"; END_TYPE |
|
659 |
* has two possible routes to type_declaration... |
|
660 |
* |
|
661 |
* Route 1: |
|
662 |
* type_declaration: single_element_type_declaration |
|
663 |
* single_element_type_declaration: simple_type_declaration |
|
664 |
* simple_type_declaration: identifier ':' simple_spec_init |
|
665 |
* simple_spec_init: simple_specification ASSIGN constant |
|
666 |
* (shift: identifier <- 'new_str_type') |
|
667 |
* simple_specification: elementary_type_name |
|
668 |
* elementary_type_name: STRING |
|
669 |
* (shift: elementary_type_name <- STRING) |
|
670 |
* (reduce: simple_specification <- elementary_type_name) |
|
671 |
* (shift: constant <- "hello!") |
|
672 |
* (reduce: simple_spec_init: simple_specification ASSIGN constant) |
|
673 |
* (reduce: ...) |
|
674 |
* |
|
675 |
* |
|
676 |
* Route 2: |
|
677 |
* type_declaration: string_type_declaration |
|
678 |
* string_type_declaration: identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init |
|
679 |
* (shift: identifier <- 'new_str_type') |
|
680 |
* elementary_string_type_name: STRING |
|
681 |
* (shift: elementary_string_type_name <- STRING) |
|
682 |
* (shift: string_type_declaration_size <- empty ) |
|
683 |
* string_type_declaration_init: ASSIGN character_string |
|
684 |
* (shift: character_string <- "hello!") |
|
685 |
* (reduce: string_type_declaration_init <- ASSIGN character_string) |
|
686 |
* (reduce: string_type_declaration <- identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init ) |
|
687 |
* (reduce: type_declaration <- string_type_declaration) |
|
688 |
* |
|
689 |
* |
|
690 |
* At first glance it seems that removing route 1 would make |
|
691 |
* the most sense. Unfortunately the construct 'simple_spec_init' |
|
692 |
* shows up multiple times in other rules, so changing this construct |
|
693 |
* would also mean changing all the rules in which it appears. |
|
694 |
* I (Mario) therefore chose to remove route 2 instead. This means |
|
695 |
* that the above declaration gets stored in a |
|
696 |
* simple_type_declaration_c, and not in a string_type_declaration_c |
|
697 |
* as would be expected! |
|
698 |
*/ |
|
699 |
/* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
700 |
SYM_REF4(string_type_declaration_c, string_type_name, |
|
701 |
elementary_string_type_name, |
|
702 |
string_type_declaration_size, |
|
703 |
string_type_declaration_init) /* may be == NULL! */ |
|
704 |
#endif |
|
705 |
||
706 |
/*********************/ |
|
707 |
/* B 1.4 - Variables */ |
|
708 |
/*********************/ |
|
709 |
/* done in base class(es) */ |
|
710 |
||
711 |
/********************************************/ |
|
712 |
/* B.1.4.1 Directly Represented Variables */ |
|
713 |
/********************************************/ |
|
714 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
715 |
void *visit(direct_variable_c *symbol) { |
|
716 |
TRACE("direct_variable_c"); |
|
717 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
718 |
if (strlen(symbol->value) == 0) ERROR; |
|
719 |
return s4o.printlocation(symbol->value + 1); |
|
720 |
} |
|
721 |
||
722 |
||
723 |
/*************************************/ |
|
724 |
/* B.1.4.2 Multi-element Variables */ |
|
725 |
/*************************************/ |
|
726 |
/* done in base class(es) */ |
|
727 |
||
728 |
/******************************************/ |
|
729 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
730 |
/******************************************/ |
|
731 |
/* leave for derived classes... */ |
|
732 |
||
733 |
/**************************************/ |
|
734 |
/* B.1.5 - Program organization units */ |
|
735 |
/**************************************/ |
|
736 |
/***********************/ |
|
737 |
/* B 1.5.1 - Functions */ |
|
738 |
/***********************/ |
|
739 |
/* leave for derived classes... */ |
|
740 |
||
741 |
/*****************************/ |
|
742 |
/* B 1.5.2 - Function Blocks */ |
|
743 |
/*****************************/ |
|
744 |
/* leave for derived classes... */ |
|
745 |
||
746 |
/**********************/ |
|
747 |
/* B 1.5.3 - Programs */ |
|
748 |
/**********************/ |
|
749 |
/* leave for derived classes... */ |
|
750 |
||
751 |
/*********************************************/ |
|
752 |
/* B.1.6 Sequential function chart elements */ |
|
753 |
/*********************************************/ |
|
754 |
||
755 |
/********************************/ |
|
756 |
/* B 1.7 Configuration elements */ |
|
757 |
/********************************/ |
|
758 |
/* leave for derived classes... */ |
|
759 |
||
760 |
/****************************************/ |
|
761 |
/* B.2 - Language IL (Instruction List) */ |
|
762 |
/****************************************/ |
|
763 |
/***********************************/ |
|
764 |
/* B 2.1 Instructions and Operands */ |
|
765 |
/***********************************/ |
|
766 |
/* leave for derived classes... */ |
|
767 |
||
768 |
/*******************/ |
|
769 |
/* B 2.2 Operators */ |
|
770 |
/*******************/ |
|
771 |
/* leave for derived classes... */ |
|
772 |
||
773 |
||
774 |
/***************************************/ |
|
775 |
/* B.3 - Language ST (Structured Text) */ |
|
776 |
/***************************************/ |
|
777 |
/***********************/ |
|
778 |
/* B 3.1 - Expressions */ |
|
779 |
/***********************/ |
|
780 |
/* leave for derived classes... */ |
|
781 |
||
782 |
/********************/ |
|
783 |
/* B 3.2 Statements */ |
|
784 |
/********************/ |
|
785 |
/* leave for derived classes... */ |
|
786 |
||
787 |
/*********************************/ |
|
788 |
/* B 3.2.1 Assignment Statements */ |
|
789 |
/*********************************/ |
|
790 |
/* leave for derived classes... */ |
|
791 |
||
792 |
/*****************************************/ |
|
793 |
/* B 3.2.2 Subprogram Control Statements */ |
|
794 |
/*****************************************/ |
|
795 |
/* leave for derived classes... */ |
|
796 |
||
797 |
/********************************/ |
|
798 |
/* B 3.2.3 Selection Statements */ |
|
799 |
/********************************/ |
|
800 |
/* leave for derived classes... */ |
|
801 |
||
802 |
/********************************/ |
|
803 |
/* B 3.2.4 Iteration Statements */ |
|
804 |
/********************************/ |
|
805 |
/* leave for derived classes... */ |
|
806 |
||
807 |
||
808 |
||
809 |
||
810 |
}; /* generate_c_typedecl_c */ |
|
811 |
||
812 |
||
813 |