271 |
280 |
272 get_datatype_id_str_c *get_datatype_id_str_c::singleton = NULL; |
281 get_datatype_id_str_c *get_datatype_id_str_c::singleton = NULL; |
273 |
282 |
274 |
283 |
275 |
284 |
|
285 /*********************************************************/ |
|
286 /*********************************************************/ |
|
287 /* get the datatype of a field inside a struct data type */ |
|
288 /*********************************************************/ |
|
289 /*********************************************************/ |
|
290 |
|
291 class get_struct_info_c : null_visitor_c { |
|
292 private: |
|
293 symbol_c *current_field; |
|
294 /* singleton class! */ |
|
295 static get_struct_info_c *singleton; |
|
296 |
|
297 public: |
|
298 get_struct_info_c(void) {current_field = NULL;} |
|
299 |
|
300 static symbol_c *get_field_type_id(symbol_c *struct_type, symbol_c *field_name) { |
|
301 if (NULL == singleton) singleton = new get_struct_info_c; |
|
302 if (NULL == singleton) ERROR; |
|
303 singleton->current_field = field_name; |
|
304 return (symbol_c *)struct_type->accept(*singleton); |
|
305 } |
|
306 |
|
307 |
|
308 private: |
|
309 /*************************/ |
|
310 /* B.1 - Common elements */ |
|
311 /*************************/ |
|
312 /********************************/ |
|
313 /* B 1.3.3 - Derived data types */ |
|
314 /********************************/ |
|
315 /* structure_type_name ':' structure_specification */ |
|
316 /* NOTE: this is only used inside a TYPE ... END_TYPE declaration. It is never used directly when declaring a new variable! */ |
|
317 /* NOTE: structure_specification will point to either initialized_structure_c OR structure_element_declaration_list_c */ |
|
318 void *visit(structure_type_declaration_c *symbol) {return symbol->structure_specification->accept(*this);} |
|
319 |
|
320 /* structure_type_name ASSIGN structure_initialization */ |
|
321 /* structure_initialization may be NULL ! */ |
|
322 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
|
323 /* NOTE: only the initialized structure is never used when declaring a new variable instance */ |
|
324 void *visit(initialized_structure_c *symbol) {return symbol->structure_type_name->accept(*this);} |
|
325 |
|
326 /* helper symbol for structure_declaration */ |
|
327 /* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
328 /* structure_element_declaration_list structure_element_declaration ';' */ |
|
329 void *visit(structure_element_declaration_list_c *symbol) { |
|
330 /* now search the structure declaration */ |
|
331 for(int i = 0; i < symbol->n; i++) { |
|
332 void *tmp = symbol->elements[i]->accept(*this); |
|
333 if (NULL != tmp) return tmp; |
|
334 } |
|
335 return NULL; // not found!! |
|
336 } |
|
337 |
|
338 /* structure_element_name ':' spec_init */ |
|
339 void *visit(structure_element_declaration_c *symbol) { |
|
340 if (compare_identifiers(symbol->structure_element_name, current_field) == 0) |
|
341 return symbol->spec_init; /* found the type of the element we were looking for! */ |
|
342 return NULL; /* not the element we are looking for! */ |
|
343 } |
|
344 |
|
345 |
|
346 /* helper symbol for structure_initialization */ |
|
347 /* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
348 /* structure_element_initialization_list ',' structure_element_initialization */ |
|
349 void *visit(structure_element_initialization_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
350 /* structure_element_name ASSIGN value */ |
|
351 void *visit(structure_element_initialization_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
352 |
|
353 |
|
354 /**************************************/ |
|
355 /* B.1.5 - Program organization units */ |
|
356 /**************************************/ |
|
357 /*****************************/ |
|
358 /* B 1.5.2 - Function Blocks */ |
|
359 /*****************************/ |
|
360 /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
361 // SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) |
|
362 void *visit(function_block_declaration_c *symbol) { |
|
363 /* now search the function block declaration for the variable... */ |
|
364 search_var_instance_decl_c search_decl(symbol); |
|
365 return search_decl.get_decl(current_field); |
|
366 } |
|
367 |
|
368 /*********************************************/ |
|
369 /* B.1.6 Sequential function chart elements */ |
|
370 /*********************************************/ |
|
371 /* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
|
372 // SYM_REF2(initial_step_c, step_name, action_association_list) |
|
373 void *visit(initial_step_c *symbol) { |
|
374 identifier_c T("T"); identifier_c X("X"); |
|
375 /* Hard code the datatypes of the implicit variables Stepname.X and Stepname.T */ |
|
376 if (compare_identifiers(&T, current_field) == 0) return &get_datatype_info_c::time_type_name; |
|
377 if (compare_identifiers(&X, current_field) == 0) return &get_datatype_info_c::bool_type_name; |
|
378 return NULL; |
|
379 } |
|
380 |
|
381 /* STEP step_name ':' action_association_list END_STEP */ |
|
382 // SYM_REF2(step_c, step_name, action_association_list) |
|
383 /* The code here should be identicial to the code in the visit(initial_step_c *) visitor! So we simply call the other visitor! */ |
|
384 void *visit(step_c *symbol) {initial_step_c initial_step(NULL, NULL); return initial_step.accept(*this);} |
|
385 |
|
386 }; // get_struct_info_c |
|
387 |
|
388 get_struct_info_c *get_struct_info_c::singleton = NULL; |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
276 /**********************************************************/ |
394 /**********************************************************/ |
277 /**********************************************************/ |
395 /**********************************************************/ |
278 /**********************************************************/ |
396 /**********************************************************/ |
279 /***** *****/ |
397 /***** *****/ |
280 /***** *****/ |
398 /***** *****/ |