73 * option (2) will return INT |
73 * option (2) will return INT |
74 * |
74 * |
75 * |
75 * |
76 * Member functions: |
76 * Member functions: |
77 * ================ |
77 * ================ |
|
78 * get_basetype_id() ---> returns 2A (implemented, although currently it is not needed! ) |
78 * get_basetype_decl() ---> returns 2B |
79 * get_basetype_decl() ---> returns 2B |
79 * get_type_id() ---> returns 1A |
80 * get_type_id() ---> returns 1A |
80 * |
81 * |
81 * Since we haven't yet needed them, we don't yet implement |
82 * Since we haven't yet needed it, we don't yet implement |
82 * get_basetype_id() ----> would return 2A |
83 * get_type_decl() ---> returns 1B |
83 * get_type_decl() ----> would return 1B |
|
84 */ |
84 */ |
85 |
85 |
86 |
86 |
87 /* |
87 |
88 * TODO: this code has a memory leak... |
|
89 * We call 'new' in several locations, but bever get to 'delete' the object instances... |
|
90 */ |
|
91 #include "absyntax_utils.hh" |
88 #include "absyntax_utils.hh" |
92 |
89 |
93 |
90 |
|
91 void search_varfb_instance_type_c::init(void) { |
|
92 this->current_type_id = NULL; |
|
93 this->current_basetype_id = NULL; |
|
94 this->current_basetype_decl = NULL; |
|
95 this->current_field_selector = NULL; |
|
96 this->is_complex = false; |
|
97 } |
|
98 |
|
99 |
94 search_varfb_instance_type_c::search_varfb_instance_type_c(symbol_c *search_scope): search_var_instance_decl(search_scope) { |
100 search_varfb_instance_type_c::search_varfb_instance_type_c(symbol_c *search_scope): search_var_instance_decl(search_scope) { |
95 this->decompose_var_instance_name = NULL; |
101 this->init(); |
96 this->current_structelement_name = NULL; |
102 } |
97 this->current_typeid = NULL; |
103 |
98 this->current_basetypeid = NULL; |
104 |
99 } |
105 /* We expect to be passed a symbolic_variable_c */ |
100 |
106 symbol_c *search_varfb_instance_type_c::get_type_id(symbol_c *variable_name) { |
101 symbol_c *search_varfb_instance_type_c::get_type_decl(symbol_c *variable_name) { |
107 this->init(); |
102 this->current_structelement_name = NULL; |
108 variable_name->accept(*this); |
103 this->current_typeid = NULL; |
109 return current_type_id; |
104 this->current_basetypeid = NULL; |
110 } |
105 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
111 |
106 if (NULL == decompose_var_instance_name) ERROR; |
112 |
107 |
113 symbol_c *search_varfb_instance_type_c::get_basetype_id(symbol_c *variable_name) { |
108 /* find the part of the variable name that will appear in the |
114 this->init(); |
109 * variable declaration, for e.g., in window.point.x, this would be |
115 variable_name->accept(*this); |
110 * window! |
116 return current_basetype_id; |
111 */ |
|
112 symbol_c *var_name_part = decompose_var_instance_name->next_part(); |
|
113 if (NULL == var_name_part) ERROR; |
|
114 |
|
115 /* Now we try to find the variable instance declaration, to determine its type... */ |
|
116 symbol_c *var_decl = search_var_instance_decl.get_decl(var_name_part); |
|
117 if (NULL == var_decl) ERROR; |
|
118 |
|
119 /* if it is a struct or function block, we must search the type |
|
120 * of the struct or function block member. |
|
121 * This is done by this class visiting the var_decl. |
|
122 * This class, while visiting, will recursively call |
|
123 * decompose_var_instance_name->get_next() when and if required... |
|
124 */ |
|
125 symbol_c *res = (symbol_c *)var_decl->accept(*this); |
|
126 /* NOTE: A Null result is not really an internal compiler error, but rather an error in |
|
127 * the IEC 61131-3 source code being compiled. This means we cannot just abort the compiler with ERROR. |
|
128 * // if (NULL == res) ERROR; |
|
129 */ |
|
130 if (NULL == res) return NULL; |
|
131 |
|
132 /* make sure that we have decomposed all structure elements of the variable name */ |
|
133 symbol_c *var_name = decompose_var_instance_name->next_part(); |
|
134 /* NOTE: A non-NULL result is not really an internal compiler error, but rather an error in |
|
135 * the IEC 61131-3 source code being compiled. |
|
136 * (for example, 'int_var.struct_elem' in the source code, when 'int_var' is a simple integer, |
|
137 * and not a structure, will result in this result being non-NULL!) |
|
138 * This means we cannot just abort the compiler with ERROR. |
|
139 * // if (NULL != var_name) ERROR; |
|
140 */ |
|
141 if (NULL != var_name) return NULL; |
|
142 |
|
143 return res; |
|
144 } |
117 } |
145 |
118 |
146 |
119 |
147 symbol_c *search_varfb_instance_type_c::get_basetype_decl(symbol_c *variable_name) { |
120 symbol_c *search_varfb_instance_type_c::get_basetype_decl(symbol_c *variable_name) { |
148 symbol_c *res = get_type_decl(variable_name); |
121 this->init(); |
149 if (NULL == res) return NULL; |
122 variable_name->accept(*this); |
150 return (symbol_c *)base_type(res); |
123 return current_basetype_decl; |
151 } |
124 } |
152 |
125 |
153 |
126 |
|
127 |
|
128 |
|
129 |
154 unsigned int search_varfb_instance_type_c::get_vartype(symbol_c *variable_name) { |
130 unsigned int search_varfb_instance_type_c::get_vartype(symbol_c *variable_name) { |
155 this->current_structelement_name = NULL; |
131 this->init(); |
156 this->current_typeid = NULL; |
132 return search_var_instance_decl.get_vartype(variable_name); |
157 this->current_basetypeid = NULL; |
133 } |
158 this->is_complex = false; |
134 |
159 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
135 |
160 if (NULL == decompose_var_instance_name) ERROR; |
|
161 |
|
162 /* find the part of the variable name that will appear in the |
|
163 * variable declaration, for e.g., in window.point.x, this would be |
|
164 * window! |
|
165 */ |
|
166 symbol_c *var_name_part = decompose_var_instance_name->next_part(); |
|
167 if (NULL == var_name_part) ERROR; |
|
168 |
|
169 /* Now we try to find the variable instance declaration, to determine its type... */ |
|
170 symbol_c *var_decl = search_var_instance_decl.get_decl(var_name_part); |
|
171 if (NULL == var_decl) { |
|
172 /* variable instance declaration not found! */ |
|
173 return 0; |
|
174 } |
|
175 |
|
176 /* if it is a struct or function block, we must search the type |
|
177 * of the struct or function block member. |
|
178 * This is done by this class visiting the var_decl. |
|
179 * This class, while visiting, will recursively call |
|
180 * decompose_var_instance_name->get_next() when and if required... |
|
181 */ |
|
182 var_decl->accept(*this); |
|
183 unsigned int res = search_var_instance_decl.get_vartype(); |
|
184 |
|
185 /* make sure that we have decomposed all structure elements of the variable name */ |
|
186 symbol_c *var_name = decompose_var_instance_name->next_part(); |
|
187 if (NULL != var_name) ERROR; |
|
188 |
|
189 return res; |
|
190 } |
|
191 |
|
192 symbol_c *search_varfb_instance_type_c::get_type_id(symbol_c *variable_name) { |
|
193 this->current_typeid = NULL; |
|
194 symbol_c *vartype = this->get_type_decl(variable_name); |
|
195 if (this->current_typeid != NULL) |
|
196 return this->current_typeid; |
|
197 else |
|
198 return vartype; |
|
199 } |
|
200 |
136 |
201 bool search_varfb_instance_type_c::type_is_complex(void) { |
137 bool search_varfb_instance_type_c::type_is_complex(void) { |
202 return this->is_complex; |
138 return this->is_complex; |
203 } |
139 } |
204 |
140 |
205 /* a helper function... */ |
141 |
206 void *search_varfb_instance_type_c::visit_list(list_c *list) { |
142 |
207 if (NULL == current_structelement_name) ERROR; |
143 |
208 |
144 |
209 for(int i = 0; i < list->n; i++) { |
145 |
210 void *res = list->elements[i]->accept(*this); |
146 |
211 if (res != NULL) |
147 |
212 return res; |
148 |
213 } |
|
214 /* not found! */ |
|
215 return NULL; |
|
216 } |
|
217 |
|
218 /* a helper function... */ |
|
219 void *search_varfb_instance_type_c::base_type(symbol_c *symbol) { |
|
220 search_base_type_c search_base_type; |
|
221 return symbol->accept(search_base_type); |
|
222 } |
|
223 |
|
224 /* We override the base class' visitor to identifier_c. |
|
225 * This is so because the base class does not consider a function block |
|
226 * to be a type, unlike this class that allows a variable instance |
|
227 * of a function block type... |
|
228 */ |
|
229 void *search_varfb_instance_type_c::visit(identifier_c *type_name) { |
|
230 /* we only store the new type id if none had been found yet. |
|
231 * Since we will recursively carry on looking at the base type |
|
232 * to determine the base type declaration and id, we must only set this variable |
|
233 * the first time. |
|
234 * e.g. TYPE myint1_t : int := 1; |
|
235 * myint2_t : int1_t := 2; |
|
236 * myint3_t : int2_t := 3; |
|
237 * END_TYPE; |
|
238 * VAR |
|
239 * myint1 : myint1_t; |
|
240 * myint2 : myint2_t; |
|
241 * myint3 : myint3_t; |
|
242 * END_VAR |
|
243 * |
|
244 * If we ask for typeid of myint3, it must return myint3_t |
|
245 * If we ask for basetypeid of myint3, it must return int |
|
246 * |
|
247 * When determining the data type of myint3, we will recursively go all the way |
|
248 * down to int, but we must still only store myint3_t as the base type id. |
|
249 */ |
|
250 if (NULL == this->current_typeid) |
|
251 this->current_typeid = type_name; |
|
252 this->current_basetypeid = type_name; |
|
253 |
|
254 /* look up the type declaration... */ |
|
255 symbol_c *fb_decl = function_block_type_symtable.find_value(type_name); |
|
256 if (fb_decl != function_block_type_symtable.end_value()) |
|
257 /* Type declaration found!! */ |
|
258 return fb_decl->accept(*this); |
|
259 |
|
260 /* No. It is not a function block, so we let |
|
261 * the base class take care of it... |
|
262 */ |
|
263 return search_base_type_c::visit(type_name); |
|
264 } |
|
265 |
149 |
266 /********************************/ |
150 /********************************/ |
267 /* B 1.3.3 - Derived data types */ |
151 /* B 1.3.3 - Derived data types */ |
268 /********************************/ |
152 /********************************/ |
269 |
|
270 /* identifier ':' array_spec_init */ |
153 /* identifier ':' array_spec_init */ |
|
154 /* NOTE: I don't think this will ever get called, since in the visit method for array_variable_c |
|
155 * we use the basetype_decl for recursively calling this class, and the base type should never be a |
|
156 * array_type_declaration_c, but for now, let's leave it in... |
|
157 */ |
271 void *search_varfb_instance_type_c::visit(array_type_declaration_c *symbol) { |
158 void *search_varfb_instance_type_c::visit(array_type_declaration_c *symbol) { |
272 return symbol->array_spec_init->accept(*this); |
159 ERROR; |
|
160 return NULL; |
273 } |
161 } |
274 |
162 |
275 /* array_specification [ASSIGN array_initialization] */ |
163 /* array_specification [ASSIGN array_initialization] */ |
276 /* array_initialization may be NULL ! */ |
164 /* array_initialization may be NULL ! */ |
|
165 /* NOTE: I don't think this will ever get called, since in the visit method for array_variable_c |
|
166 * we use the basetype_decl for recursively calling this class, and the base type should never be a |
|
167 * array_spec_init_c, but for now, let's leave it in... |
|
168 */ |
277 void *search_varfb_instance_type_c::visit(array_spec_init_c *symbol) { |
169 void *search_varfb_instance_type_c::visit(array_spec_init_c *symbol) { |
278 return symbol->array_specification->accept(*this); |
170 /* Note that the 'array_specification' may be either an identifier of a previsously defined array type, |
|
171 * or an array_specification_c, so we can not stop here and simply return a array_spec_init_c, |
|
172 * especially if we are looking for the base class! |
|
173 */ |
|
174 ERROR; |
|
175 return NULL; |
279 } |
176 } |
280 |
177 |
281 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
178 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
179 /* NOTE: This method will be reached after being called from the |
|
180 * search_varfb_instance_type_c::visit(array_variable_c *symbol) |
|
181 * method, so we must return the data type of the data stored in the array, |
|
182 * and not the data type of the array itself! |
|
183 */ |
282 void *search_varfb_instance_type_c::visit(array_specification_c *symbol) { |
184 void *search_varfb_instance_type_c::visit(array_specification_c *symbol) { |
283 this->is_complex = true; |
185 /* found the type of the element we were looking for! */ |
284 this->current_typeid = symbol; |
186 current_type_id = symbol->non_generic_type_name; |
285 return symbol->non_generic_type_name->accept(*this); |
187 current_basetype_decl = search_base_type.get_basetype_decl(current_type_id); |
286 } |
188 current_basetype_id = search_base_type.get_basetype_id (current_type_id); |
|
189 |
|
190 return NULL; |
|
191 } |
|
192 |
287 |
193 |
288 /* structure_type_name ':' structure_specification */ |
194 /* structure_type_name ':' structure_specification */ |
289 /* NOTE: this is only used inside a TYPE ... END_TYPE declaration. |
195 /* NOTE: this is only used inside a TYPE ... END_TYPE declaration. |
290 * It is never used directly when declaring a new variable! |
196 * It is never used directly when declaring a new variable! |
291 */ |
197 */ |
|
198 /* NOTE: I don't think this will ever get called, since in the visit method for structured_variable_c |
|
199 * we use the basetype_decl for recursively calling this class, and the base type should never be a |
|
200 * structure_type_declaration_c, but for now, let's leave it in... |
|
201 */ |
292 void *search_varfb_instance_type_c::visit(structure_type_declaration_c *symbol) { |
202 void *search_varfb_instance_type_c::visit(structure_type_declaration_c *symbol) { |
293 this->is_complex = true; |
203 if (NULL == current_field_selector) ERROR; |
294 |
204 symbol->structure_specification->accept(*this); |
295 if (NULL == current_structelement_name) ERROR; |
205 return NULL; |
296 return symbol->structure_specification->accept(*this); |
|
297 /* NOTE: structure_specification will point to either a |
206 /* NOTE: structure_specification will point to either a |
298 * initialized_structure_c |
207 * initialized_structure_c |
299 * OR A |
208 * OR A |
300 * structure_element_declaration_list_c |
209 * structure_element_declaration_list_c |
301 */ |
210 */ |
302 } |
211 } |
303 |
212 |
304 /* structure_type_name ASSIGN structure_initialization */ |
213 /* structure_type_name ASSIGN structure_initialization */ |
305 /* structure_initialization may be NULL ! */ |
214 /* structure_initialization may be NULL ! */ |
306 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
215 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
307 /* NOTE: only the initialized structure is ever used when declaring a new variable instance */ |
216 /* NOTE: only the initialized structure is never used when declaring a new variable instance */ |
|
217 /* NOTE: I don't think this will ever get called, since in the visit method for structured_variable_c |
|
218 * we use the basetype_decl for recursively calling this class, and the base type should never be a |
|
219 * initialized_structure_c, but for now, let's leave it in... |
|
220 */ |
308 void *search_varfb_instance_type_c::visit(initialized_structure_c *symbol) { |
221 void *search_varfb_instance_type_c::visit(initialized_structure_c *symbol) { |
309 this->is_complex = true; |
222 if (NULL != current_field_selector) ERROR; |
310 if (NULL != current_structelement_name) ERROR; |
223 |
311 |
224 /* recursively find out the data type of current_field_selector... */ |
312 /* make sure that we have decomposed all structure elements of the variable name */ |
225 symbol->structure_type_name->accept(*this); |
313 symbol_c *var_name = decompose_var_instance_name->next_part(); |
226 return NULL; |
314 if (NULL == var_name) { |
|
315 /* this is it... ! |
|
316 * No need to look any further... |
|
317 * Note also that, unlike for the struct types, a function block may |
|
318 * not be defined based on another (i.e. no inheritance is allowed), |
|
319 * so this function block is already the most base type. |
|
320 * We simply return it. |
|
321 */ |
|
322 return (void *)symbol; |
|
323 } |
|
324 |
|
325 /* reset current_type_id because of new structure element part */ |
|
326 this->current_typeid = NULL; |
|
327 |
|
328 /* look for the var_name in the structure declaration */ |
|
329 current_structelement_name = var_name; |
|
330 |
|
331 /* recursively find out the data type of current_structelement_name... */ |
|
332 return symbol->structure_type_name->accept(*this); |
|
333 } |
227 } |
334 |
228 |
335 /* helper symbol for structure_declaration */ |
229 /* helper symbol for structure_declaration */ |
336 /* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
230 /* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
337 /* structure_element_declaration_list structure_element_declaration ';' */ |
231 /* structure_element_declaration_list structure_element_declaration ';' */ |
338 void *search_varfb_instance_type_c::visit(structure_element_declaration_list_c *symbol) { |
232 void *search_varfb_instance_type_c::visit(structure_element_declaration_list_c *symbol) { |
339 if (NULL == current_structelement_name) ERROR; |
233 if (NULL == current_field_selector) ERROR; |
|
234 |
340 /* now search the structure declaration */ |
235 /* now search the structure declaration */ |
341 return visit_list(symbol); |
236 for(int i = 0; i < symbol->n; i++) { |
|
237 symbol->elements[i]->accept(*this); |
|
238 } |
|
239 |
|
240 return NULL; |
342 } |
241 } |
343 |
242 |
344 /* structure_element_name ':' spec_init */ |
243 /* structure_element_name ':' spec_init */ |
345 void *search_varfb_instance_type_c::visit(structure_element_declaration_c *symbol) { |
244 void *search_varfb_instance_type_c::visit(structure_element_declaration_c *symbol) { |
346 if (NULL == current_structelement_name) ERROR; |
245 if (NULL == current_field_selector) ERROR; |
347 |
246 |
348 if (compare_identifiers(symbol->structure_element_name, current_structelement_name) == 0) { |
247 if (compare_identifiers(symbol->structure_element_name, current_field_selector) == 0) { |
349 current_structelement_name = NULL; |
|
350 /* found the type of the element we were looking for! */ |
248 /* found the type of the element we were looking for! */ |
351 return symbol->spec_init->accept(*this); |
249 current_type_id = symbol->spec_init; |
|
250 current_basetype_decl = search_base_type.get_basetype_decl(current_type_id); |
|
251 current_basetype_id = search_base_type.get_basetype_id (current_type_id); |
352 } |
252 } |
353 |
253 |
354 /* Did not find the type of the element we were looking for! */ |
254 /* Did not find the type of the element we were looking for! */ |
355 /* Will keep looking... */ |
255 /* Will keep looking... */ |
356 return NULL; |
256 return NULL; |
362 void *search_varfb_instance_type_c::visit(structure_element_initialization_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
262 void *search_varfb_instance_type_c::visit(structure_element_initialization_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
363 /* structure_element_name ASSIGN value */ |
263 /* structure_element_name ASSIGN value */ |
364 void *search_varfb_instance_type_c::visit(structure_element_initialization_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
264 void *search_varfb_instance_type_c::visit(structure_element_initialization_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
365 |
265 |
366 |
266 |
|
267 /*********************/ |
|
268 /* B 1.4 - Variables */ |
|
269 /*********************/ |
|
270 // SYM_REF1(symbolic_variable_c, var_name) |
|
271 void *search_varfb_instance_type_c::visit(symbolic_variable_c *symbol) { |
|
272 /* Note: although the method is called get_decl(), it is getting the declaration of the variable, which for us is the type_id of that variable! */ |
|
273 current_type_id = search_var_instance_decl.get_decl (symbol->var_name); |
|
274 current_basetype_decl = search_base_type.get_basetype_decl(current_type_id); |
|
275 current_basetype_id = search_base_type.get_basetype_id (current_type_id); |
|
276 |
|
277 if (NULL == current_type_id) ERROR; /* why should this be an error? what if the variable has not been declared? */ |
|
278 |
|
279 return NULL; |
|
280 } |
|
281 |
|
282 /********************************************/ |
|
283 /* B.1.4.1 Directly Represented Variables */ |
|
284 /********************************************/ |
|
285 // SYM_TOKEN(direct_variable_c) |
|
286 /* We do not yet handle this. Will we ever need to handle it, as the data type of the direct variable is |
|
287 * directly obtainable from the syntax of the direct variable itself? |
|
288 */ |
|
289 |
|
290 /*************************************/ |
|
291 /* B 1.4.2 - Multi-element variables */ |
|
292 /*************************************/ |
|
293 /* subscripted_variable '[' subscript_list ']' */ |
|
294 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
295 /* NOTE: when passed a array_variable_c, which represents some IEC61131-3 code similar to X[42] |
|
296 * we must return the data type of the value _stored_ in the array. |
|
297 * If you want to get the data type of the array itself (i.e. just the X variable, without the [42]) |
|
298 * then this class must be called with the identifier_c 'X'. |
|
299 */ |
|
300 void *search_varfb_instance_type_c::visit(array_variable_c *symbol) { |
|
301 this->is_complex = true; |
|
302 |
|
303 /* determine the data type of the subscripted_variable... |
|
304 * This should be an array_specification_c |
|
305 * ARRAY [xx..yy] OF Stored_Data_Type |
|
306 */ |
|
307 symbol->subscripted_variable->accept(*this); |
|
308 |
|
309 /* Now we determine the 'Stored_Data_Type', i.e. the data type of the variable stored in the array. */ |
|
310 if (NULL != current_basetype_decl) { |
|
311 current_basetype_decl->accept(*this); |
|
312 } |
|
313 |
|
314 return NULL; |
|
315 } |
|
316 |
|
317 |
|
318 /* record_variable '.' field_selector */ |
|
319 /* WARNING: input and/or output variables of function blocks |
|
320 * may be accessed as fields of a structured variable! |
|
321 * Code handling a structured_variable_c must take |
|
322 * this into account! |
|
323 */ |
|
324 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
325 void *search_varfb_instance_type_c::visit(structured_variable_c *symbol) { |
|
326 this->is_complex = true; |
|
327 symbol->record_variable->accept(*this); |
|
328 |
|
329 /* Now we search for the data type of the field... But only if we were able to determine the data type of the variable */ |
|
330 if (NULL != current_basetype_decl) { |
|
331 current_field_selector = symbol->field_selector; |
|
332 current_basetype_decl->accept(*this); |
|
333 current_field_selector = NULL; |
|
334 } |
|
335 |
|
336 return NULL; |
|
337 } |
|
338 |
|
339 |
367 |
340 |
368 /**************************************/ |
341 /**************************************/ |
369 /* B.1.5 - Program organization units */ |
342 /* B.1.5 - Program organization units */ |
370 /**************************************/ |
343 /**************************************/ |
371 /*****************************/ |
344 /*****************************/ |
372 /* B 1.5.2 - Function Blocks */ |
345 /* B 1.5.2 - Function Blocks */ |
373 /*****************************/ |
346 /*****************************/ |
|
347 |
374 /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
348 /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
375 // SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) |
349 // SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) |
376 void *search_varfb_instance_type_c::visit(function_block_declaration_c *symbol) { |
350 void *search_varfb_instance_type_c::visit(function_block_declaration_c *symbol) { |
377 /* make sure that we have decomposed all structure elements of the variable name */ |
351 if (NULL == current_field_selector) ERROR; |
378 symbol_c *var_name = decompose_var_instance_name->next_part(); |
352 |
379 if (NULL == var_name) { |
353 /* now search the function block declaration for the variable... */ |
380 /* this is it... ! |
354 /* If not found, these pointers will all be set to NULL!! */ |
381 * No need to look any further... |
355 search_var_instance_decl_c search_decl(symbol); |
382 * Note also that, unlike for the struct types, a function block may |
356 current_type_id = search_decl.get_decl(current_field_selector); |
383 * not be defined based on another (i.e. no inheritance is allowed), |
357 current_basetype_decl = search_base_type.get_basetype_decl(current_type_id); |
384 * so this function block is already the most base type. |
358 current_basetype_id = search_base_type.get_basetype_id (current_type_id); |
385 * We simply return it. |
359 |
386 */ |
360 return NULL; |
387 return (void *)symbol; |
361 } |
388 } |
|
389 |
|
390 /* reset current_type_id because of new structure element part */ |
|
391 this->current_typeid = NULL; |
|
392 |
|
393 /* now search the function block declaration for the variable... */ |
|
394 search_var_instance_decl_c search_decl(symbol); |
|
395 symbol_c *var_decl = search_decl.get_decl(var_name); |
|
396 if (NULL == var_decl) { |
|
397 /* variable instance declaration not found! */ |
|
398 return NULL; |
|
399 } |
|
400 #if 0 |
|
401 /* We have found the declaration. |
|
402 * Should we look any further? |
|
403 */ |
|
404 var_name = decompose_var_instance_name->next_part(); |
|
405 if (NULL == var_name) { |
|
406 /* this is it... ! */ |
|
407 return base_type(var_decl); |
|
408 } |
|
409 |
|
410 current_structelement_name = var_name; |
|
411 /* recursively find out the data type of var_name... */ |
|
412 return symbol->var_declarations->accept(*this); |
|
413 #endif |
|
414 /* carry on recursively, in case the variable has more elements to be decomposed... */ |
|
415 return var_decl->accept(*this); |
|
416 } |
|