absyntax_utils/search_varfb_instance_type.cc
changeset 235 ed66dc50f31a
parent 226 29f8ffc203c1
child 238 0919986a5c98
equal deleted inserted replaced
234:e4d31cd0e6d8 235:ed66dc50f31a
   173   symbol_c *fb_decl = function_block_type_symtable.find_value(type_name);
   173   symbol_c *fb_decl = function_block_type_symtable.find_value(type_name);
   174   if (fb_decl != function_block_type_symtable.end_value())
   174   if (fb_decl != function_block_type_symtable.end_value())
   175     /* Type declaration found!! */
   175     /* Type declaration found!! */
   176     return fb_decl->accept(*this);
   176     return fb_decl->accept(*this);
   177 
   177 
       
   178   this->current_rawtype = type_name;
       
   179 
   178   /* No. It is not a function block, so we let
   180   /* No. It is not a function block, so we let
   179    * the base class take care of it...
   181    * the base class take care of it...
   180    */
   182    */
   181   this->current_rawtype = type_name;
   183   current_structelement_name = decompose_var_instance_name->next_part();
   182   if (current_structelement_name == NULL)
   184   if (NULL == current_structelement_name) {
   183 	return base_type(type_name);
   185 	/* this is it... !
       
   186      * No need to look any further...
       
   187      */
       
   188     /* NOTE: we could simply do a
       
   189      *   return (void *)symbol;
       
   190      *       nevertheless, note that this search_varfb_instance_type_c
       
   191      *       class inherits from the search_base_type_c class,
       
   192      *       which means that it will usually return the base type,
       
   193      *       and not the derived type (*). If we are to be consistent,
       
   194      *       we should guarantee that we always return the base type.
       
   195      *       To do this we could use
       
   196      *   return (void *)symbol->accept(*this);
       
   197      *       since this class inherits from the search_base_type_c.
       
   198      *       However, in this case we don't want it to follow
       
   199      *       the structs as this search_varfb_instance_type_c does.
       
   200      *       We therefore have to create a new search_base_type_c
       
   201      *       instance to search through this type without going
       
   202      *       through the structs...
       
   203      */
       
   204     return base_type(type_name);
       
   205   }
   184   else
   206   else
   185     return search_base_type_c::visit(type_name);
   207     return search_base_type_c::visit(type_name);
   186 }
   208 }
   187 
   209 
   188 /********************************/
   210 /********************************/
   196     
   218     
   197 /* array_specification [ASSIGN array_initialization} */
   219 /* array_specification [ASSIGN array_initialization} */
   198 /* array_initialization may be NULL ! */
   220 /* array_initialization may be NULL ! */
   199 void *search_varfb_instance_type_c::visit(array_spec_init_c *symbol) {
   221 void *search_varfb_instance_type_c::visit(array_spec_init_c *symbol) {
   200   this->is_complex = true;
   222   this->is_complex = true;
   201   symbol_c *var_name = decompose_var_instance_name->next_part();
       
   202   if (NULL != var_name)
       
   203     current_structelement_name = var_name;
       
   204   return symbol->array_specification->accept(*this);
   223   return symbol->array_specification->accept(*this);
   205 }
   224 }
   206     
   225     
   207 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
   226 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
   208 void *search_varfb_instance_type_c::visit(array_specification_c *symbol) {
   227 void *search_varfb_instance_type_c::visit(array_specification_c *symbol) {
   209   symbol_c *var_name = decompose_var_instance_name->next_part();
   228   this->is_complex = true;
   210   if (NULL != var_name)
       
   211     current_structelement_name = var_name;
       
   212   return symbol->non_generic_type_name->accept(*this);
   229   return symbol->non_generic_type_name->accept(*this);
   213 }
   230 }
   214 
   231 
   215 /*  structure_type_name ':' structure_specification */
   232 /*  structure_type_name ':' structure_specification */
   216 void *search_varfb_instance_type_c::visit(structure_type_declaration_c *symbol) {
   233 void *search_varfb_instance_type_c::visit(structure_type_declaration_c *symbol) {
       
   234   this->is_complex = true;
   217   return symbol->structure_specification->accept(*this);
   235   return symbol->structure_specification->accept(*this);
   218   /* NOTE: structure_specification will point to either a
   236   /* NOTE: structure_specification will point to either a
   219    *       initialized_structure_c
   237    *       initialized_structure_c
   220    *       OR A
   238    *       OR A
   221    *       structure_element_declaration_list_c
   239    *       structure_element_declaration_list_c
   225 /* structure_type_name ASSIGN structure_initialization */
   243 /* structure_type_name ASSIGN structure_initialization */
   226 /* structure_initialization may be NULL ! */
   244 /* structure_initialization may be NULL ! */
   227 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
   245 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
   228 void *search_varfb_instance_type_c::visit(initialized_structure_c *symbol)	{
   246 void *search_varfb_instance_type_c::visit(initialized_structure_c *symbol)	{
   229   this->is_complex = true;
   247   this->is_complex = true;
   230   /* make sure that we have decomposed all structure elements of the variable name */
       
   231   symbol_c *var_name = decompose_var_instance_name->next_part();
       
   232   if (NULL == var_name) {
       
   233     /* this is it... !
       
   234      * No need to look any further...
       
   235      */
       
   236     /* NOTE: we could simply do a
       
   237     *   return (void *)symbol;
       
   238     *       nevertheless, note that this search_varfb_instance_type_c
       
   239     *       class inherits from the search_base_type_c class,
       
   240     *       which means that it will usually return the base type,
       
   241     *       and not the derived type (*). If we are to be consistent,
       
   242     *       we should guarantee that we always return the base type.
       
   243     *       To do this we could use
       
   244     *   return (void *)symbol->accept(*this);
       
   245     *       since this class inherits from the search_base_type_c.
       
   246     *       However, in this case we don't want it to follow
       
   247     *       the structs as this search_varfb_instance_type_c does.
       
   248     *       We therefore have to create a new search_base_type_c
       
   249     *       instance to search through this type without going
       
   250     *       through the structs...
       
   251     */
       
   252       return base_type(symbol->structure_type_name);
       
   253   }
       
   254 
       
   255   /* now search the structure declaration */
       
   256   current_structelement_name = var_name;
       
   257   /* recursively find out the data type of var_name... */
   248   /* recursively find out the data type of var_name... */
   258   return symbol->structure_type_name->accept(*this);
   249   return symbol->structure_type_name->accept(*this);
   259 }
   250 }
   260 
   251 
   261 /* helper symbol for structure_declaration */
   252 /* helper symbol for structure_declaration */