stage4/generate_c/generate_c_typedecl.cc
changeset 958 7474d2cd1d6e
parent 950 935c8b6ba3c5
child 1041 56ebe2a31b5b
equal deleted inserted replaced
957:4489afa5b1c5 958:7474d2cd1d6e
   537 
   537 
   538 /*  identifier ':' array_spec_init */
   538 /*  identifier ':' array_spec_init */
   539 void *visit(array_type_declaration_c *symbol) {
   539 void *visit(array_type_declaration_c *symbol) {
   540   TRACE("array_type_declaration_c");
   540   TRACE("array_type_declaration_c");
   541   
   541   
   542   // NOTE: remeber that symbol->array_spec_init may point to an identifier_c, which is why we use symbol->array_spec_init->datatype instead!
   542   // NOTE: remeber that symbol->array_spec_init may point to a derived_datatype_identifier_c, which is why we use symbol->array_spec_init->datatype instead!
   543   if (NULL == symbol->array_spec_init->datatype) ERROR;
   543   if (NULL == symbol->array_spec_init->datatype) ERROR;
   544   identifier_c *id = generate_datatypes_aliasid_c::create_id(symbol->array_spec_init->datatype);
   544   identifier_c *id = generate_datatypes_aliasid_c::create_id(symbol->array_spec_init->datatype);
   545   
   545   
   546   /* NOTE  An array_type_declaration_c will be created in stage4 for each implicitly defined array,
   546   /* NOTE  An array_type_declaration_c will be created in stage4 for each implicitly defined array,
   547    *       and this generate_c_typedecl_c will be called to define that array in C.
   547    *       and this generate_c_typedecl_c will be called to define that array in C.
   869    *       to the same identifier (e.g: __REF_TO_INT).
   869    *       to the same identifier (e.g: __REF_TO_INT).
   870    *       In order for the C compiler not to find the same datatype being defined two or more times, 
   870    *       In order for the C compiler not to find the same datatype being defined two or more times, 
   871    *       we will keep track of the datatypes that have already been declared, and henceforth
   871    *       we will keep track of the datatypes that have already been declared, and henceforth
   872    *       only declare the datatypes that have not been previously defined.
   872    *       only declare the datatypes that have not been previously defined.
   873    */
   873    */
   874   if (datatypes_already_defined.find(((identifier_c *)(symbol->ref_type_name))->value) != datatypes_already_defined.end())
   874   identifier_c *tmp_id;
       
   875   tmp_id = dynamic_cast<identifier_c *>(symbol->ref_type_name);
       
   876   if (NULL == tmp_id) ERROR;
       
   877   if (datatypes_already_defined.find(tmp_id->value) != datatypes_already_defined.end())
   875     return NULL; // already defined. No need to define it again!!
   878     return NULL; // already defined. No need to define it again!!
   876   datatypes_already_defined[((identifier_c *)(symbol->ref_type_name))->value] = 1; // insert this datatype into the list of already defined arrays!
   879   datatypes_already_defined[tmp_id->value] = 1; // insert this datatype into the list of already defined arrays!
   877   
   880   
   878   current_type_name = NULL;
   881   current_type_name = NULL;
   879   current_typedefinition = none_td;
   882   current_typedefinition = none_td;
   880 
   883 
   881   s4o_incl.print("__DECLARE_REFTO_TYPE(");
   884   s4o_incl.print("__DECLARE_REFTO_TYPE(");