author | Edouard TISSERANT <edouard.tisserant@gmail.com> |
Sun, 29 Nov 2009 19:09:56 +0100 | |
changeset 218 | 413842f6152f |
parent 217 | f5dfadf5de54 |
child 221 | c6aed7e5f070 |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
/* Determine the data type of a specific variable instance, including |
|
26 |
* function block instances. |
|
27 |
* A reference to the relevant variable declaration is returned. |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
28 |
* The variable instance may NOT be a member of a structure of a member |
181 | 29 |
* of a structure of an element of an array of ... |
30 |
* |
|
31 |
* example: |
|
32 |
* window.points[1].coordinate.x |
|
33 |
* window.points[1].colour |
|
34 |
* etc... ARE NOT ALLOWED! |
|
35 |
* |
|
36 |
* This class must only be passed the name of the variable that will appear |
|
37 |
* in the variable declaration. In the above examples, this would be |
|
38 |
* 'window' !! |
|
39 |
* |
|
40 |
* |
|
41 |
* If you need to pass a complete name of a variable instance (such as |
|
42 |
* 'window.points[1].coordinate.x') use the search_varfb_instance_type_c instead! |
|
43 |
*/ |
|
44 |
||
45 |
/* Note that current_type_decl that this class returns may reference the |
|
46 |
* name of a type, or the type declaration itself! |
|
47 |
* For an example of the first, consider a variable declared as ... |
|
48 |
* x : AAA; |
|
49 |
* where the AAA type is previously declared as whatever. |
|
50 |
* For an example of the second, consider a variable declared as ... |
|
51 |
* x : array of int [10]; ----> is allowed |
|
52 |
* |
|
53 |
* If it is the first, we will return a reference to the name, if the second |
|
54 |
* we return a reference to the declaration!! |
|
55 |
*/ |
|
56 |
#include "absyntax_utils.hh" |
|
57 |
||
58 |
||
59 |
search_var_instance_decl_c::search_var_instance_decl_c(symbol_c *search_scope) { |
|
60 |
this->current_vartype = none_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
61 |
this->current_varqualifier = none_vq; |
181 | 62 |
this->search_scope = search_scope; |
63 |
this->search_name = NULL; |
|
64 |
this->current_type_decl = NULL; |
|
65 |
} |
|
66 |
||
67 |
symbol_c *search_var_instance_decl_c::get_decl(symbol_c *variable_instance_name) { |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
68 |
this->current_vartype = none_vt; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
69 |
this->current_varqualifier = none_vq; |
181 | 70 |
this->search_name = variable_instance_name; |
71 |
return (symbol_c *)search_scope->accept(*this); |
|
72 |
} |
|
73 |
||
74 |
unsigned int search_var_instance_decl_c::get_vartype() { |
|
75 |
return current_vartype; |
|
76 |
} |
|
77 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
78 |
unsigned int search_var_instance_decl_c::get_varqualifier() { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
79 |
return current_varqualifier; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
80 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
81 |
|
181 | 82 |
/***************************/ |
83 |
/* B 0 - Programming Model */ |
|
84 |
/***************************/ |
|
85 |
void *search_var_instance_decl_c::visit(library_c *symbol) { |
|
86 |
/* we do not want to search multiple declaration scopes, |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
87 |
* so we do not visit all the functions, function blocks, etc... |
181 | 88 |
*/ |
89 |
return NULL; |
|
90 |
} |
|
91 |
||
92 |
||
93 |
||
94 |
/******************************************/ |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
95 |
/* B 1.4.3 - Declaration & Initialization */ |
181 | 96 |
/******************************************/ |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
97 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
98 |
void *search_var_instance_decl_c::visit(constant_option_c *symbol) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
99 |
current_varqualifier = constant_vq; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
100 |
return NULL; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
101 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
102 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
103 |
void *search_var_instance_decl_c::visit(retain_option_c *symbol) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
104 |
current_varqualifier = retain_vq; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
105 |
return NULL; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
106 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
107 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
108 |
void *search_var_instance_decl_c::visit(non_retain_option_c *symbol) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
109 |
current_varqualifier = non_retain_vq; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
110 |
return NULL; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
111 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
112 |
|
181 | 113 |
/* edge -> The F_EDGE or R_EDGE directive */ |
114 |
// SYM_REF2(edge_declaration_c, edge, var1_list) |
|
115 |
// TODO |
|
116 |
||
117 |
void *search_var_instance_decl_c::visit(input_declarations_c *symbol) { |
|
118 |
current_vartype = input_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
119 |
if (symbol->option != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
120 |
symbol->option->accept(*this); |
181 | 121 |
void *res = symbol->input_declaration_list->accept(*this); |
122 |
if (res == NULL) { |
|
123 |
current_vartype = none_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
124 |
current_varqualifier = none_vq; |
181 | 125 |
} |
126 |
return res; |
|
127 |
} |
|
128 |
||
129 |
/* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
|
130 |
/* option -> may be NULL ! */ |
|
131 |
void *search_var_instance_decl_c::visit(output_declarations_c *symbol) { |
|
132 |
current_vartype = output_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
133 |
if (symbol->option != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
134 |
symbol->option->accept(*this); |
181 | 135 |
void *res = symbol->var_init_decl_list->accept(*this); |
136 |
if (res == NULL) { |
|
137 |
current_vartype = none_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
138 |
current_varqualifier = none_vq; |
181 | 139 |
} |
140 |
return res; |
|
141 |
} |
|
142 |
||
143 |
/* VAR_IN_OUT var_declaration_list END_VAR */ |
|
144 |
void *search_var_instance_decl_c::visit(input_output_declarations_c *symbol) { |
|
145 |
current_vartype = inoutput_vt; |
|
146 |
void *res = symbol->var_declaration_list->accept(*this); |
|
147 |
if (res == NULL) { |
|
148 |
current_vartype = none_vt; |
|
149 |
} |
|
150 |
return res; |
|
151 |
} |
|
152 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
153 |
/* ENO : BOOL */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
154 |
void *search_var_instance_decl_c::visit(eno_param_declaration_c *symbol) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
155 |
if (compare_identifiers(symbol->name, search_name) == 0) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
156 |
return symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
157 |
return NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
158 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
159 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
160 |
|
181 | 161 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
162 |
/* option -> may be NULL ! */ |
|
163 |
/* helper symbol for input_declarations */ |
|
164 |
void *search_var_instance_decl_c::visit(var_declarations_c *symbol) { |
|
165 |
current_vartype = private_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
166 |
if (symbol->option != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
167 |
symbol->option->accept(*this); |
181 | 168 |
void *res = symbol->var_init_decl_list->accept(*this); |
169 |
if (res == NULL) { |
|
170 |
current_vartype = none_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
171 |
current_varqualifier = none_vq; |
181 | 172 |
} |
173 |
return res; |
|
174 |
} |
|
175 |
||
176 |
/* VAR RETAIN var_init_decl_list END_VAR */ |
|
177 |
void *search_var_instance_decl_c::visit(retentive_var_declarations_c *symbol) { |
|
178 |
current_vartype = private_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
179 |
current_varqualifier = retain_vq; |
181 | 180 |
void *res = symbol->var_init_decl_list->accept(*this); |
181 |
if (res == NULL) { |
|
182 |
current_vartype = none_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
183 |
current_varqualifier = none_vq; |
181 | 184 |
} |
185 |
return res; |
|
186 |
} |
|
187 |
||
188 |
/* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ |
|
189 |
/* option -> may be NULL ! */ |
|
190 |
//SYM_REF2(located_var_declarations_c, option, located_var_decl_list) |
|
191 |
void *search_var_instance_decl_c::visit(located_var_declarations_c *symbol) { |
|
192 |
current_vartype = located_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
193 |
if (symbol->option != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
194 |
symbol->option->accept(*this); |
181 | 195 |
void *res = symbol->located_var_decl_list->accept(*this); |
196 |
if (res == NULL) { |
|
197 |
current_vartype = none_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
198 |
current_varqualifier = none_vq; |
181 | 199 |
} |
200 |
return res; |
|
201 |
} |
|
202 |
||
203 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
204 |
/* option -> may be NULL ! */ |
|
205 |
//SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
206 |
void *search_var_instance_decl_c::visit(external_var_declarations_c *symbol) { |
|
207 |
current_vartype = external_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
208 |
if (symbol->option != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
209 |
symbol->option->accept(*this); |
181 | 210 |
void *res = symbol->external_declaration_list->accept(*this); |
211 |
if (res == NULL) { |
|
212 |
current_vartype = none_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
213 |
current_varqualifier = none_vq; |
181 | 214 |
} |
215 |
return res; |
|
216 |
} |
|
217 |
||
218 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
219 |
/* option -> may be NULL ! */ |
|
220 |
//SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
221 |
void *search_var_instance_decl_c::visit(global_var_declarations_c *symbol) { |
|
222 |
current_vartype = global_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
223 |
if (symbol->option != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
224 |
symbol->option->accept(*this); |
181 | 225 |
void *res = symbol->global_var_decl_list->accept(*this); |
226 |
if (res == NULL) { |
|
227 |
current_vartype = none_vt; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
228 |
current_varqualifier = none_vq; |
181 | 229 |
} |
230 |
return res; |
|
231 |
} |
|
232 |
||
233 |
/* var1_list is one of the following... |
|
234 |
* simple_spec_init_c * |
|
235 |
* subrange_spec_init_c * |
|
236 |
* enumerated_spec_init_c * |
|
237 |
*/ |
|
238 |
// SYM_REF2(var1_init_decl_c, var1_list, spec_init) |
|
239 |
void *search_var_instance_decl_c::visit(var1_init_decl_c *symbol) { |
|
240 |
current_type_decl = symbol->spec_init; |
|
241 |
return symbol->var1_list->accept(*this); |
|
242 |
} |
|
243 |
||
244 |
/* var1_list ',' variable_name */ |
|
245 |
// SYM_LIST(var1_list_c) |
|
246 |
void *search_var_instance_decl_c::visit(var1_list_c *symbol) { |
|
247 |
list_c *list = symbol; |
|
248 |
for(int i = 0; i < list->n; i++) { |
|
249 |
if (compare_identifiers(list->elements[i], search_name) == 0) |
|
250 |
/* by now, current_type_decl should be != NULL */ |
|
251 |
return current_type_decl; |
|
252 |
} |
|
253 |
return NULL; |
|
254 |
} |
|
255 |
||
256 |
/* name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
257 |
/* structure_initialization -> may be NULL ! */ |
|
258 |
void *search_var_instance_decl_c::visit(fb_name_decl_c *symbol) { |
|
259 |
current_type_decl = symbol->function_block_type_name; |
|
260 |
return symbol->fb_name_list->accept(*this); |
|
261 |
} |
|
262 |
||
263 |
/* name_list ',' fb_name */ |
|
264 |
void *search_var_instance_decl_c::visit(fb_name_list_c *symbol) { |
|
265 |
list_c *list = symbol; |
|
266 |
for(int i = 0; i < list->n; i++) { |
|
267 |
if (compare_identifiers(list->elements[i], search_name) == 0) |
|
268 |
/* by now, current_fb_declaration should be != NULL */ |
|
269 |
return current_type_decl; |
|
270 |
} |
|
271 |
return NULL; |
|
272 |
} |
|
273 |
||
274 |
/* var1_list ':' array_spec_init */ |
|
275 |
// SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
276 |
void *search_var_instance_decl_c::visit(array_var_init_decl_c *symbol) { |
|
277 |
current_type_decl = symbol->array_spec_init; |
|
278 |
return symbol->var1_list->accept(*this); |
|
279 |
} |
|
280 |
||
281 |
/* var1_list ':' initialized_structure */ |
|
282 |
// SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
283 |
void *search_var_instance_decl_c::visit(structured_var_init_decl_c *symbol) { |
|
284 |
current_type_decl = symbol->initialized_structure; |
|
285 |
return symbol->var1_list->accept(*this); |
|
286 |
} |
|
287 |
||
288 |
/* var1_list ':' array_specification */ |
|
289 |
// SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
290 |
void *search_var_instance_decl_c::visit(array_var_declaration_c *symbol) { |
|
291 |
current_type_decl = symbol->array_specification; |
|
292 |
return symbol->var1_list->accept(*this); |
|
293 |
} |
|
294 |
||
295 |
/* var1_list ':' structure_type_name */ |
|
296 |
// SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
297 |
void *search_var_instance_decl_c::visit(structured_var_declaration_c *symbol) { |
|
298 |
current_type_decl = symbol->structure_type_name; |
|
299 |
return symbol->var1_list->accept(*this); |
|
300 |
} |
|
301 |
||
302 |
/* [variable_name] location ':' located_var_spec_init */ |
|
303 |
/* variable_name -> may be NULL ! */ |
|
304 |
// SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
305 |
// TODO!! |
|
306 |
||
307 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
308 |
// SYM_REF2(external_declaration_c, global_var_name, specification) |
|
309 |
void *search_var_instance_decl_c::visit(external_declaration_c *symbol) { |
|
310 |
if (compare_identifiers(symbol->global_var_name, search_name) == 0) |
|
311 |
return symbol->specification; |
|
312 |
return NULL; |
|
313 |
} |
|
314 |
||
315 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
316 |
/* type_specification ->may be NULL ! */ |
|
317 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
318 |
void *search_var_instance_decl_c::visit(global_var_decl_c *symbol) { |
|
319 |
if (symbol->type_specification != NULL) { |
|
320 |
current_type_decl = symbol->type_specification; |
|
321 |
return symbol->global_var_spec->accept(*this); |
|
322 |
} |
|
323 |
else |
|
324 |
return NULL; |
|
325 |
} |
|
326 |
||
327 |
/*| global_var_name location */ |
|
328 |
//SYM_REF2(global_var_spec_c, global_var_name, location) |
|
329 |
void *search_var_instance_decl_c::visit(global_var_spec_c *symbol) { |
|
330 |
if (symbol->global_var_name != NULL && compare_identifiers(symbol->global_var_name, search_name) == 0) |
|
331 |
return current_type_decl; |
|
332 |
else |
|
333 |
return symbol->location->accept(*this); |
|
334 |
} |
|
335 |
||
336 |
/*| global_var_list ',' global_var_name */ |
|
337 |
//SYM_LIST(global_var_list_c) |
|
338 |
void *search_var_instance_decl_c::visit(global_var_list_c *symbol) { |
|
339 |
list_c *list = symbol; |
|
340 |
for(int i = 0; i < list->n; i++) { |
|
341 |
if (compare_identifiers(list->elements[i], search_name) == 0) |
|
342 |
/* by now, current_type_decl should be != NULL */ |
|
343 |
return current_type_decl; |
|
344 |
} |
|
345 |
return NULL; |
|
346 |
} |
|
347 |
||
348 |
/* [variable_name] location ':' located_var_spec_init */ |
|
349 |
/* variable_name -> may be NULL ! */ |
|
350 |
//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
351 |
void *search_var_instance_decl_c::visit(located_var_decl_c *symbol) { |
|
352 |
if (symbol->variable_name != NULL && compare_identifiers(symbol->variable_name, search_name) == 0) |
|
353 |
return symbol->located_var_spec_init; |
|
354 |
else { |
|
355 |
current_type_decl = symbol->located_var_spec_init; |
|
356 |
return symbol->location->accept(*this); |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
361 |
/* type_specification ->may be NULL ! */ |
|
362 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
363 |
// TODO!! |
|
364 |
||
365 |
/* AT direct_variable */ |
|
366 |
// SYM_REF2(location_c, direct_variable, unused) |
|
367 |
void *search_var_instance_decl_c::visit(location_c *symbol) { |
|
368 |
if (compare_identifiers(symbol->direct_variable, search_name) == 0) |
|
369 |
return current_type_decl; |
|
370 |
else |
|
371 |
return NULL; |
|
372 |
} |
|
373 |
||
374 |
/*| global_var_list ',' global_var_name */ |
|
375 |
// SYM_LIST(global_var_list_c) |
|
376 |
// TODO!! |
|
377 |
||
378 |
/* var1_list ':' single_byte_string_spec */ |
|
379 |
// SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
380 |
void *search_var_instance_decl_c::visit(single_byte_string_var_declaration_c *symbol) { |
|
381 |
current_type_decl = symbol->single_byte_string_spec; |
|
382 |
return symbol->var1_list->accept(*this); |
|
383 |
} |
|
384 |
||
385 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
386 |
/* integer ->may be NULL ! */ |
|
387 |
/* single_byte_character_string ->may be NULL ! */ |
|
388 |
// SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
389 |
// TODO!! |
|
390 |
||
391 |
/* var1_list ':' double_byte_string_spec */ |
|
392 |
// SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
393 |
void *search_var_instance_decl_c::visit(double_byte_string_var_declaration_c *symbol) { |
|
394 |
current_type_decl = symbol->double_byte_string_spec; |
|
395 |
return symbol->var1_list->accept(*this); |
|
396 |
} |
|
397 |
||
398 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
399 |
/* integer ->may be NULL ! */ |
|
400 |
/* double_byte_character_string ->may be NULL ! */ |
|
401 |
// SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
402 |
// TODO!! |
|
403 |
||
404 |
/* variable_name incompl_location ':' var_spec */ |
|
405 |
// SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
406 |
// TODO!! |
|
407 |
||
408 |
/* AT incompl_location_token */ |
|
409 |
// SYM_TOKEN(incompl_location_c) |
|
410 |
// TODO!! |
|
411 |
||
412 |
||
413 |
/**************************************/ |
|
414 |
/* B.1.5 - Program organization units */ |
|
415 |
/**************************************/ |
|
416 |
/***********************/ |
|
417 |
/* B 1.5.1 - Functions */ |
|
418 |
/***********************/ |
|
419 |
// SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body) |
|
420 |
void *search_var_instance_decl_c::visit(function_declaration_c *symbol) { |
|
421 |
/* functions have a variable named after themselves, to store |
|
422 |
* the variable that will be returned!! |
|
423 |
*/ |
|
424 |
if (compare_identifiers(symbol->derived_function_name, search_name) == 0) |
|
425 |
return symbol->type_name; |
|
426 |
||
427 |
/* no need to search through all the body, so we only |
|
428 |
* visit the variable declarations...! |
|
429 |
*/ |
|
430 |
return symbol->var_declarations_list->accept(*this); |
|
431 |
} |
|
432 |
||
433 |
/*****************************/ |
|
434 |
/* B 1.5.2 - Function Blocks */ |
|
435 |
/*****************************/ |
|
436 |
void *search_var_instance_decl_c::visit(function_block_declaration_c *symbol) { |
|
437 |
/* no need to search through all the body, so we only |
|
438 |
* visit the variable declarations...! |
|
439 |
*/ |
|
440 |
return symbol->var_declarations->accept(*this); |
|
441 |
} |
|
442 |
||
443 |
/**********************/ |
|
444 |
/* B 1.5.3 - Programs */ |
|
445 |
/**********************/ |
|
446 |
void *search_var_instance_decl_c::visit(program_declaration_c *symbol) { |
|
447 |
/* no need to search through all the body, so we only |
|
448 |
* visit the variable declarations...! |
|
449 |
*/ |
|
450 |
return symbol->var_declarations->accept(*this); |
|
451 |
} |
|
452 |
||
453 |
||
454 |
/********************************/ |
|
455 |
/* B 1.7 Configuration elements */ |
|
456 |
/********************************/ |
|
457 |
||
458 |
/* |
|
459 |
CONFIGURATION configuration_name |
|
460 |
optional_global_var_declarations |
|
461 |
(resource_declaration_list | single_resource_declaration) |
|
462 |
optional_access_declarations |
|
463 |
optional_instance_specific_initializations |
|
464 |
END_CONFIGURATION |
|
465 |
*/ |
|
466 |
/* |
|
467 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
468 |
*/ |
|
469 |
void *search_var_instance_decl_c::visit(configuration_declaration_c *symbol) { |
|
470 |
/* no need to search through all the configuration, so we only |
|
471 |
* visit the global variable declarations...! |
|
472 |
*/ |
|
473 |
if (symbol->global_var_declarations != NULL) |
|
474 |
return symbol->global_var_declarations->accept(*this); |
|
475 |
else |
|
476 |
return NULL; |
|
477 |
} |
|
478 |
||
479 |
/* |
|
480 |
RESOURCE resource_name ON resource_type_name |
|
481 |
optional_global_var_declarations |
|
482 |
single_resource_declaration |
|
483 |
END_RESOURCE |
|
484 |
*/ |
|
485 |
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
486 |
void *search_var_instance_decl_c::visit(resource_declaration_c *symbol) { |
|
487 |
/* no need to search through all the resource, so we only |
|
488 |
* visit the global variable declarations...! |
|
489 |
*/ |
|
490 |
if (symbol->global_var_declarations != NULL) |
|
491 |
return symbol->global_var_declarations->accept(*this); |
|
492 |
else |
|
493 |
return NULL; |
|
494 |
} |
|
495 |
||
496 |
/* task_configuration_list program_configuration_list */ |
|
497 |
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
498 |
void *search_var_instance_decl_c::visit(single_resource_declaration_c *symbol) { |
|
499 |
/* no need to search through all the resource, |
|
500 |
* and there is no global variable declarations...! |
|
501 |
*/ |
|
502 |
return NULL; |
|
503 |
} |
|
504 |
||
505 |
#if 0 |
|
506 |
/*********************/ |
|
507 |
/* B 1.4 - Variables */ |
|
508 |
/*********************/ |
|
509 |
SYM_REF2(symbolic_variable_c, var_name, unused) |
|
510 |
||
511 |
/********************************************/ |
|
512 |
/* B.1.4.1 Directly Represented Variables */ |
|
513 |
/********************************************/ |
|
514 |
SYM_TOKEN(direct_variable_c) |
|
515 |
||
516 |
/*************************************/ |
|
517 |
/* B.1.4.2 Multi-element Variables */ |
|
518 |
/*************************************/ |
|
519 |
/* subscripted_variable '[' subscript_list ']' */ |
|
520 |
SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
521 |
||
522 |
/* subscript_list ',' subscript */ |
|
523 |
SYM_LIST(subscript_list_c) |
|
524 |
||
525 |
/* record_variable '.' field_selector */ |
|
526 |
/* WARNING: input and/or output variables of function blocks |
|
527 |
* may be accessed as fields of a tructured variable! |
|
528 |
* Code handling a structured_variable_c must take |
|
529 |
* this into account! |
|
530 |
*/ |
|
531 |
SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
532 |
||
533 |
||
534 |
||
535 |
}; |
|
536 |
#endif |