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