stage4/generate_c/generate_c_typedecl.cc
changeset 377 60b012b7793f
parent 350 2c3c4dc34979
child 547 dab341e80664
equal deleted inserted replaced
376:7dcbd8418771 377:60b012b7793f
    68       subrangebasetype_bd,
    68       subrangebasetype_bd,
    69       subrangetest_bd,
    69       subrangetest_bd,
    70       arrayderiveddeclaration_bd,
    70       arrayderiveddeclaration_bd,
    71       arraybasetype_bd,
    71       arraybasetype_bd,
    72       arraybasetypeincl_bd,
    72       arraybasetypeincl_bd,
    73       arraysubrange_bd,
    73       arraysubrange_bd
    74       arraytranslateindex_bd
       
    75     } basetypedeclaration_t;
    74     } basetypedeclaration_t;
    76     
    75 
    77     basetypedeclaration_t current_basetypedeclaration;
    76     basetypedeclaration_t current_basetypedeclaration;
    78 
    77 
    79     void print_integer(unsigned int integer) {
    78     void print_integer(unsigned int integer) {
    80       char str[10];
    79       char str[10];
    81       sprintf(str, "%d", integer);
    80       sprintf(str, "%d", integer);
   371 	symbol->array_spec_init->accept(*this);
   370 	symbol->array_spec_init->accept(*this);
   372 	current_basetypedeclaration = none_bd;
   371 	current_basetypedeclaration = none_bd;
   373   }
   372   }
   374   s4o_incl.print(")\n");
   373   s4o_incl.print(")\n");
   375 
   374 
   376   if (search_base_type.type_is_subrange(symbol->identifier)) {
       
   377 	s4o.print("#define __CHECK_");
       
   378 	current_type_name->accept(*this);
       
   379 	s4o.print(" __CHECK_");
       
   380 	current_basetypedeclaration = arraybasetype_bd;
       
   381 	symbol->array_spec_init->accept(*this);
       
   382 	current_basetypedeclaration = none_bd;
       
   383 	s4o.print("\n");
       
   384   }
       
   385 
       
   386   current_basetypedeclaration = arraytranslateindex_bd;
       
   387   symbol->array_spec_init->accept(*this);
       
   388   current_basetypedeclaration = none_bd;
       
   389   s4o.print("\n");
       
   390 
       
   391   current_type_name = NULL;
   375   current_type_name = NULL;
   392   current_typedefinition = none_td;
   376   current_typedefinition = none_td;
   393 
   377 
   394   return NULL;
   378   return NULL;
   395 }
   379 }
   402   if (current_typedefinition == array_td) {
   386   if (current_typedefinition == array_td) {
   403     switch (current_basetypedeclaration) {
   387     switch (current_basetypedeclaration) {
   404 	  case arrayderiveddeclaration_bd:
   388 	  case arrayderiveddeclaration_bd:
   405 	    array_is_derived = dynamic_cast<identifier_c *>(symbol->array_specification) != NULL;
   389 	    array_is_derived = dynamic_cast<identifier_c *>(symbol->array_specification) != NULL;
   406 	    break;
   390 	    break;
   407 	  case arraytranslateindex_bd:
       
   408 	    if (!array_is_derived)
       
   409 		  symbol->array_specification->accept(*this);
       
   410 	    s4o.print("#define __");
       
   411 	    current_type_name->accept(*this);
       
   412 	    s4o.print("_TRANSIDX(row, index) __");
       
   413 	    if (array_is_derived)
       
   414 		   symbol->array_specification->accept(*this);
       
   415 	    else
       
   416 		   current_type_name->accept(*this);
       
   417 	    s4o.print("_TRANSIDX##row(index)");
       
   418 	    break;
       
   419 	  default:
   391 	  default:
   420 	    if (array_is_derived)
   392 	    if (array_is_derived)
   421 		  symbol->array_specification->accept(*basedecl);
   393 		  symbol->array_specification->accept(*basedecl);
   422 	    else
   394 	    else
   423 		  symbol->array_specification->accept(*this);
   395 		  symbol->array_specification->accept(*this);
   438       break;
   410       break;
   439     case arraybasetypeincl_bd:
   411     case arraybasetypeincl_bd:
   440       symbol->non_generic_type_name->accept(*basedecl);
   412       symbol->non_generic_type_name->accept(*basedecl);
   441       break;
   413       break;
   442     case arraysubrange_bd:
   414     case arraysubrange_bd:
   443     case arraytranslateindex_bd:
       
   444       symbol->array_subrange_list->accept(*this);
   415       symbol->array_subrange_list->accept(*this);
   445       break;
   416       break;
   446     default:
   417     default:
   447       break;
   418       break;
   448   }
   419   }
   450 }
   421 }
   451 
   422 
   452 /* helper symbol for array_specification */
   423 /* helper symbol for array_specification */
   453 /* array_subrange_list ',' subrange */
   424 /* array_subrange_list ',' subrange */
   454 void *visit(array_subrange_list_c *symbol) {
   425 void *visit(array_subrange_list_c *symbol) {
   455   if (current_basetypedeclaration == arraytranslateindex_bd) {
   426   print_list(symbol);
   456     for (int i = 0; i < symbol->n; i++) {
       
   457       s4o.print("#define __");
       
   458       current_type_name->accept(*this);
       
   459       s4o.print("_TRANSIDX");
       
   460       print_integer(i);
       
   461       s4o.print("(index) (index) - ");
       
   462       symbol->elements[i]->accept(*this);
       
   463       s4o.print("\n");
       
   464     }
       
   465   }
       
   466   else
       
   467     print_list(symbol);
       
   468   return NULL;
   427   return NULL;
   469 }
   428 }
   470 
   429 
   471 /*  TYPE type_declaration_list END_TYPE */
   430 /*  TYPE type_declaration_list END_TYPE */
   472 void *visit(data_type_declaration_c *symbol) {
   431 void *visit(data_type_declaration_c *symbol) {
   489   s4o_incl.print("__DECLARE_DERIVED_TYPE(");
   448   s4o_incl.print("__DECLARE_DERIVED_TYPE(");
   490   symbol->simple_type_name->accept(*basedecl);
   449   symbol->simple_type_name->accept(*basedecl);
   491   s4o_incl.print(",");
   450   s4o_incl.print(",");
   492   symbol->simple_spec_init->accept(*this);
   451   symbol->simple_spec_init->accept(*this);
   493   s4o_incl.print(")\n");
   452   s4o_incl.print(")\n");
       
   453 
       
   454   if (search_base_type.type_is_subrange(symbol->simple_type_name)) {
       
   455 	s4o.print("#define __CHECK_");
       
   456 	current_type_name->accept(*this);
       
   457 	s4o.print(" __CHECK_");
       
   458 	symbol->simple_spec_init->accept(*this);
       
   459 	s4o.print("\n");
       
   460   }
       
   461 
   494   return NULL;
   462   return NULL;
   495 }
   463 }
   496 
   464 
   497 /* simple_specification [ASSIGN constant] */
   465 /* simple_specification [ASSIGN constant] */
   498 //SYM_REF2(simple_spec_init_c, simple_specification, constant)
   466 //SYM_REF2(simple_spec_init_c, simple_specification, constant)