stage4/generate_c/generate_c_il.cc
changeset 392 9b88b8b6bccd
parent 382 ac6dfec701c9
child 399 55b074ea7255
child 453 4733f662362a
equal deleted inserted replaced
391:4798bd4739d0 392:9b88b8b6bccd
   130   public:
   130   public:
   131     typedef enum {
   131     typedef enum {
   132       expression_vg,
   132       expression_vg,
   133       assignment_vg,
   133       assignment_vg,
   134       complextype_base_vg,
   134       complextype_base_vg,
       
   135       complextype_base_assignment_vg,
   135       complextype_suffix_vg,
   136       complextype_suffix_vg,
   136       fparam_output_vg
   137       fparam_output_vg
   137     } variablegeneration_t;
   138     } variablegeneration_t;
   138 
   139 
   139   private:
   140   private:
   285     
   286     
   286     void print_backup_variable(void) {
   287     void print_backup_variable(void) {
   287       this->default_variable_back_name.accept(*this);
   288       this->default_variable_back_name.accept(*this);
   288     }
   289     }
   289 
   290 
       
   291     void reset_default_variable_name(void) {
       
   292       this->default_variable_name.current_type = NULL;
       
   293       this->default_variable_back_name.current_type = NULL;
       
   294     }
       
   295 
   290   private:
   296   private:
   291     /* A helper function... */
   297     /* A helper function... */
   292     /*
   298     /*
   293     bool is_bool_type(symbol_c *type_symbol) {
   299     bool is_bool_type(symbol_c *type_symbol) {
   294       return (NULL != dynamic_cast<bool_type_name_c *>(type_symbol));
   300       return (NULL != dynamic_cast<bool_type_name_c *>(type_symbol));
   466     		symbol_c* fb_symbol = NULL,
   472     		symbol_c* fb_symbol = NULL,
   467     		symbol_c* fb_value = NULL,
   473     		symbol_c* fb_value = NULL,
   468     		bool negative = false) {
   474     		bool negative = false) {
   469       unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   475       unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   470       bool type_is_complex = search_varfb_instance_type->type_is_complex();
   476       bool type_is_complex = search_varfb_instance_type->type_is_complex();
   471       if (vartype == search_var_instance_decl_c::external_vt) {
   477       if (vartype == search_var_instance_decl_c::external_vt)
   472         symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol);
   478         s4o.print(SET_EXTERNAL);
   473         /* TODO Find a solution for forcing global complex variables */
   479       else if (vartype == search_var_instance_decl_c::located_vt)
   474         if (variable != NULL) {
   480         s4o.print(SET_LOCATED);
   475           s4o.print(SET_EXTERNAL);
   481       else
   476           s4o.print("(");
   482         s4o.print(SET_VAR);
   477           variable->var_name->accept(*this);
   483       s4o.print("(");
   478           s4o.print(",");
       
   479         }
       
   480         else {
       
   481           s4o.print(SET_COMPLEX_EXTERNAL);
       
   482           s4o.print("(");
       
   483         }
       
   484       }
       
   485       else {
       
   486         if (vartype == search_var_instance_decl_c::located_vt)
       
   487           s4o.print(SET_LOCATED);
       
   488         else
       
   489           s4o.print(SET_VAR);
       
   490         s4o.print("(");
       
   491       }
       
   492 
   484 
   493       if (fb_symbol != NULL) {
   485       if (fb_symbol != NULL) {
   494         print_variable_prefix();
   486         print_variable_prefix();
   495         fb_symbol->accept(*this);
   487         fb_symbol->accept(*this);
   496         s4o.print(".");
   488         s4o.print(".,");
   497       }
   489       }
   498       else if (type_is_complex)
   490       else if (type_is_complex)
   499         wanted_variablegeneration = complextype_base_vg;
   491         wanted_variablegeneration = complextype_base_assignment_vg;
   500       else
   492       else
   501         wanted_variablegeneration = assignment_vg;
   493         wanted_variablegeneration = assignment_vg;
   502 
   494 
   503       symbol->accept(*this);
   495       symbol->accept(*this);
   504       s4o.print(",");
   496       s4o.print(",");
   578 /*********************/
   570 /*********************/
   579 
   571 
   580 void *visit(symbolic_variable_c *symbol) {
   572 void *visit(symbolic_variable_c *symbol) {
   581   unsigned int vartype;
   573   unsigned int vartype;
   582   switch (wanted_variablegeneration) {
   574   switch (wanted_variablegeneration) {
       
   575     case complextype_base_assignment_vg:
       
   576     case assignment_vg:
       
   577       this->print_variable_prefix();
       
   578       s4o.print(",");
       
   579       symbol->var_name->accept(*this);
       
   580       break;
   583     case complextype_base_vg:
   581     case complextype_base_vg:
   584     case assignment_vg:
       
   585       generate_c_base_c::visit(symbol);
   582       generate_c_base_c::visit(symbol);
   586       break;
   583       break;
   587     case complextype_suffix_vg:
   584     case complextype_suffix_vg:
   588 	  break;
   585 	  break;
   589     default:
   586     default:
   646 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   643 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   647 void *visit(structured_variable_c *symbol) {
   644 void *visit(structured_variable_c *symbol) {
   648   TRACE("structured_variable_c");
   645   TRACE("structured_variable_c");
   649   switch (wanted_variablegeneration) {
   646   switch (wanted_variablegeneration) {
   650     case complextype_base_vg:
   647     case complextype_base_vg:
       
   648     case complextype_base_assignment_vg:
   651       symbol->record_variable->accept(*this);
   649       symbol->record_variable->accept(*this);
   652       break;
   650       break;
   653     case complextype_suffix_vg:
   651     case complextype_suffix_vg:
   654     case assignment_vg:
   652     case assignment_vg:
   655       symbol->record_variable->accept(*this);
   653       symbol->record_variable->accept(*this);
   672 /*  subscripted_variable '[' subscript_list ']' */
   670 /*  subscripted_variable '[' subscript_list ']' */
   673 //SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   671 //SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   674 void *visit(array_variable_c *symbol) {
   672 void *visit(array_variable_c *symbol) {
   675   switch (wanted_variablegeneration) {
   673   switch (wanted_variablegeneration) {
   676     case complextype_base_vg:
   674     case complextype_base_vg:
       
   675     case complextype_base_assignment_vg:
   677       symbol->subscripted_variable->accept(*this);
   676       symbol->subscripted_variable->accept(*this);
   678       break;
   677       break;
   679     case complextype_suffix_vg:
   678     case complextype_suffix_vg:
   680       symbol->subscripted_variable->accept(*this);
   679       symbol->subscripted_variable->accept(*this);
   681 
   680