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