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