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