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