stage4/generate_c/generate_var_list.cc
changeset 1097 520a4b937f13
parent 1088 9cb7c8bf7dbc
child 1099 cdb045e8be20
equal deleted inserted replaced
1096:fad6e7a818e2 1097:520a4b937f13
   236     unsigned int transition_number;
   236     unsigned int transition_number;
   237     unsigned int action_number;
   237     unsigned int action_number;
   238     bool configuration_defined;
   238     bool configuration_defined;
   239     std::list<SYMBOL> current_symbol_list;
   239     std::list<SYMBOL> current_symbol_list;
   240     search_type_symbol_c *search_type_symbol;
   240     search_type_symbol_c *search_type_symbol;
   241     
   241     unsigned int is_retain;
       
   242 
   242   public:
   243   public:
   243     generate_var_list_c(stage4out_c *s4o_ptr, symbol_c *scope)
   244     generate_var_list_c(stage4out_c *s4o_ptr, symbol_c *scope)
   244     : generate_c_base_and_typeid_c(s4o_ptr) {
   245     : generate_c_base_and_typeid_c(s4o_ptr) {
   245       search_type_symbol = new search_type_symbol_c(scope);
   246       search_type_symbol = new search_type_symbol_c(scope);
   246       current_var_number = 0;
   247       current_var_number = 0;
   247       current_var_type_symbol = NULL;
   248       current_var_type_symbol = NULL;
   248       current_var_type_name = NULL;
   249       current_var_type_name = NULL;
   249       current_declarationtype = none_dt;
   250       current_declarationtype = none_dt;
   250       current_var_class_category = none_vcc;
   251       current_var_class_category = none_vcc;
       
   252       is_retain = 0;
   251     }
   253     }
   252     
   254     
   253     ~generate_var_list_c(void) {
   255     ~generate_var_list_c(void) {
   254       delete search_type_symbol;
   256       delete search_type_symbol;
   255     }
   257     }
   343       s4o.print(";");
   345       s4o.print(";");
   344       switch (search_type_symbol->current_var_type_category) {
   346       switch (search_type_symbol->current_var_type_category) {
   345         case search_type_symbol_c::structure_vtc:
   347         case search_type_symbol_c::structure_vtc:
   346         case search_type_symbol_c::function_block_vtc:
   348         case search_type_symbol_c::function_block_vtc:
   347           this->current_var_type_name->accept(*this);
   349           this->current_var_type_name->accept(*this);
   348           s4o.print(";;\n");
   350           s4o.print(";;");
       
   351           print_retain();
       
   352           s4o.print(";\n");
   349           if (this->current_var_class_category != external_vcc) {
   353           if (this->current_var_class_category != external_vcc) {
   350               SYMBOL *current_name;
   354               SYMBOL *current_name;
   351               symbol_c *tmp_var_type;
   355               symbol_c *tmp_var_type;
   352               current_name = new SYMBOL;
   356               current_name = new SYMBOL;
   353               current_name->symbol = symbol;
   357               current_name->symbol = symbol;
   358               this->current_var_type_symbol = tmp_var_type;
   362               this->current_var_type_symbol = tmp_var_type;
   359           }
   363           }
   360           break;
   364           break;
   361         case search_type_symbol_c::array_vtc:
   365         case search_type_symbol_c::array_vtc:
   362           this->current_var_type_name->accept(*this);
   366           this->current_var_type_name->accept(*this);
   363           s4o.print(";;\n");
   367           s4o.print(";;");
       
   368           print_retain();
       
   369           s4o.print(";\n");
   364           break;
   370           break;
   365         default:
   371         default:
   366           // base type name
   372           // base type name
   367           this->current_var_type_symbol->accept(*this);
   373           this->current_var_type_symbol->accept(*this);
   368           s4o.print(";");
   374           s4o.print(";");
   369           // type name (eventualy derived)
   375           // type name (eventualy derived)
   370           this->current_var_type_name->accept(*this);
   376           this->current_var_type_name->accept(*this);
       
   377           s4o.print(";");
       
   378           print_retain();
   371           s4o.print(";\n");
   379           s4o.print(";\n");
   372           break;
   380           break;
   373       }
   381       }
       
   382     }
       
   383     void print_retain() {
       
   384       if(is_retain)
       
   385           s4o.print("1");
       
   386       else
       
   387           s4o.print("0");
   374     }
   388     }
   375 
   389 
   376     void print_var_number(void) {
   390     void print_var_number(void) {
   377       char str[10];
   391       char str[10];
   378       sprintf(str, "%d", current_var_number);
   392       sprintf(str, "%d", current_var_number);
   442 
   456 
   443 /********************************************/
   457 /********************************************/
   444 /* B.1.4.3 - Declaration and initialization */
   458 /* B.1.4.3 - Declaration and initialization */
   445 /********************************************/
   459 /********************************************/
   446     
   460     
       
   461     void *visit(retain_option_c *symbol) {
       
   462       is_retain = 1;
       
   463       return NULL;
       
   464     }
       
   465 
       
   466     void *visit(non_retain_option_c *symbol) {
       
   467       is_retain = 0;
       
   468       return NULL;
       
   469     }
       
   470 
       
   471     /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
       
   472     void *visit(output_declarations_c *symbol) {
       
   473       unsigned int was_retain = is_retain;
       
   474       if (symbol->option != NULL)
       
   475         symbol->option->accept(*this);
       
   476       symbol->var_init_decl_list->accept(*this);
       
   477       is_retain = was_retain;
       
   478       return NULL;
       
   479     }
       
   480 
       
   481     /*  VAR RETAIN var_init_decl_list END_VAR */
       
   482     void *visit(retentive_var_declarations_c *symbol) {
       
   483       unsigned int was_retain = is_retain;
       
   484       symbol->var_init_decl_list->accept(*this);
       
   485       is_retain = was_retain;
       
   486       return NULL;
       
   487     }
       
   488 
       
   489     /*  VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */
       
   490     void *visit(located_var_declarations_c *symbol) {
       
   491       unsigned int was_retain = is_retain;
       
   492       if (symbol->option != NULL)
       
   493         symbol->option->accept(*this);
       
   494       symbol->located_var_decl_list->accept(*this);
       
   495       is_retain = was_retain;
       
   496       return NULL;
       
   497     }
       
   498 
       
   499     /* VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */
       
   500     void *visit(global_var_declarations_c *symbol) {
       
   501       unsigned int was_retain = is_retain;
       
   502       if (symbol->option != NULL)
       
   503         symbol->option->accept(*this);
       
   504       symbol->global_var_decl_list->accept(*this);
       
   505       is_retain = was_retain;
       
   506       return NULL;
       
   507     }
       
   508 
   447     /*  [variable_name] location ':' located_var_spec_init */
   509     /*  [variable_name] location ':' located_var_spec_init */
   448     /* variable_name -> may be NULL ! */
   510     /* variable_name -> may be NULL ! */
   449     //SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused)
   511     //SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused)
   450     void *visit(located_var_decl_c *symbol) {
   512     void *visit(located_var_decl_c *symbol) {
   451         /* Start off by setting the current_var_type_symbol and
   513         /* Start off by setting the current_var_type_symbol and