stage4/generate_c/generate_c_st.cc
changeset 887 a5e2eedeef53
parent 885 b2604fc6d25c
child 888 4893e6b11b25
equal deleted inserted replaced
886:111414d79ecd 887:a5e2eedeef53
    47 class generate_c_st_c: public generate_c_base_c {
    47 class generate_c_st_c: public generate_c_base_c {
    48 
    48 
    49   public:
    49   public:
    50     typedef enum {
    50     typedef enum {
    51       expression_vg,
    51       expression_vg,
    52       assignment_vg,
       
    53       complextype_base_vg,
    52       complextype_base_vg,
    54       complextype_base_assignment_vg,
       
    55       complextype_suffix_vg,
    53       complextype_suffix_vg,
    56       fparam_output_vg
    54       fparam_output_vg
    57     } variablegeneration_t;
    55     } variablegeneration_t;
    58 
    56 
    59     typedef enum {
    57     typedef enum {
   155     else if (vartype == search_var_instance_decl_c::located_vt)
   153     else if (vartype == search_var_instance_decl_c::located_vt)
   156       s4o.print(GET_LOCATED);
   154       s4o.print(GET_LOCATED);
   157     else
   155     else
   158       s4o.print(GET_VAR);
   156       s4o.print(GET_VAR);
   159   }
   157   }
       
   158   
       
   159   variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
   160   s4o.print("(");
   160   s4o.print("(");
   161 
   161   print_variable_prefix();  
   162   variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
       
   163   wanted_variablegeneration = complextype_base_vg;
   162   wanted_variablegeneration = complextype_base_vg;
   164   symbol->accept(*this);
   163   symbol->accept(*this);
   165   s4o.print(",");
   164   s4o.print(",");
   166   wanted_variablegeneration = complextype_suffix_vg;
   165   wanted_variablegeneration = complextype_suffix_vg;
   167   symbol->accept(*this);
   166   symbol->accept(*this);
   201     else
   200     else
   202       s4o.print(SET_VAR);
   201       s4o.print(SET_VAR);
   203   }
   202   }
   204   s4o.print("(");
   203   s4o.print("(");
   205 
   204 
       
   205   
   206   if (fb_symbol != NULL) {
   206   if (fb_symbol != NULL) {
   207     print_variable_prefix();
   207     print_variable_prefix();
   208     fb_symbol->accept(*this);
   208     fb_symbol->accept(*this);
   209     s4o.print(".,");
   209     s4o.print(".,");
   210   }
   210   }
   211   else if (type_is_complex)
   211   else {
   212     wanted_variablegeneration = complextype_base_assignment_vg;
   212     wanted_variablegeneration = complextype_base_vg;
   213   else
   213     print_variable_prefix();
   214     wanted_variablegeneration = assignment_vg;
   214     s4o.print(",");    
   215   
   215   }  
   216 /*
   216 
   217   symbol->accept(*this);
       
   218   s4o.print(",");
       
   219   wanted_variablegeneration = expression_vg;
       
   220   print_check_function(type, value, fb_value);
       
   221   if (type_is_complex) {
       
   222     s4o.print(",");
       
   223     wanted_variablegeneration = complextype_suffix_vg;
       
   224     symbol->accept(*this);
       
   225   }
       
   226   s4o.print(")");
       
   227   wanted_variablegeneration = expression_vg;
       
   228   return NULL;
       
   229 */
       
   230   symbol->accept(*this);
   217   symbol->accept(*this);
   231   s4o.print(",");
   218   s4o.print(",");
   232   if (type_is_complex) {
   219   if (type_is_complex) {
   233     wanted_variablegeneration = complextype_suffix_vg;
   220     wanted_variablegeneration = complextype_suffix_vg;
   234     symbol->accept(*this);
   221     symbol->accept(*this);
   276 /*********************/
   263 /*********************/
   277 /* B 1.4 - Variables */
   264 /* B 1.4 - Variables */
   278 /*********************/
   265 /*********************/
   279 void *visit(symbolic_variable_c *symbol) {
   266 void *visit(symbolic_variable_c *symbol) {
   280   switch (wanted_variablegeneration) {
   267   switch (wanted_variablegeneration) {
   281     case complextype_base_assignment_vg:
       
   282     case assignment_vg:
       
   283       this->print_variable_prefix();
       
   284       s4o.print(",");
       
   285       symbol->var_name->accept(*this);
       
   286       break;
       
   287     case complextype_base_vg:
   268     case complextype_base_vg:
   288       generate_c_base_c::visit(symbol);
   269       symbol->var_name->accept(*this); //generate_c_base_c::visit(symbol);
   289       break;
   270       break;
   290     case complextype_suffix_vg:
   271     case complextype_suffix_vg:
   291       break;
   272       break;
   292     default:
   273     default:
   293       if (this->is_variable_prefix_null()) {
   274       if (this->is_variable_prefix_null()) {
   333         break;
   314         break;
   334     }
   315     }
   335   }
   316   }
   336   this->print_variable_prefix();
   317   this->print_variable_prefix();
   337   s4o.printlocation(symbol->value + 1);
   318   s4o.printlocation(symbol->value + 1);
   338   if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) ||
   319   if (( this->is_variable_prefix_null() && (wanted_variablegeneration != fparam_output_vg)) ||
   339       wanted_variablegeneration != assignment_vg)
   320       (!this->is_variable_prefix_null() && (wanted_variablegeneration == expression_vg   )) ||
       
   321       (!this->is_variable_prefix_null() && (wanted_variablegeneration == fparam_output_vg)))
   340     s4o.print(")");
   322     s4o.print(")");
   341   return NULL;
   323   return NULL;
   342 }
   324 }
   343 
   325 
   344 /*************************************/
   326 /*************************************/
   349 void *visit(structured_variable_c *symbol) {
   331 void *visit(structured_variable_c *symbol) {
   350   TRACE("structured_variable_c");
   332   TRACE("structured_variable_c");
   351   bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable);
   333   bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable);
   352   switch (wanted_variablegeneration) {
   334   switch (wanted_variablegeneration) {
   353     case complextype_base_vg:
   335     case complextype_base_vg:
   354     case complextype_base_assignment_vg:
       
   355       symbol->record_variable->accept(*this);
   336       symbol->record_variable->accept(*this);
   356       if (!type_is_complex) {
   337       if (!type_is_complex) {
   357         s4o.print(".");
   338         s4o.print(".");
   358         symbol->field_selector->accept(*this);
   339         symbol->field_selector->accept(*this);
   359       }
   340       }
   362       symbol->record_variable->accept(*this);
   343       symbol->record_variable->accept(*this);
   363       if (type_is_complex) {
   344       if (type_is_complex) {
   364         s4o.print(".");
   345         s4o.print(".");
   365         symbol->field_selector->accept(*this);
   346         symbol->field_selector->accept(*this);
   366       }
   347       }
   367       break;
       
   368     case assignment_vg:
       
   369       symbol->record_variable->accept(*this);
       
   370       s4o.print(".");
       
   371       symbol->field_selector->accept(*this);
       
   372       break;
   348       break;
   373     default:
   349     default:
   374       if (this->is_variable_prefix_null()) {
   350       if (this->is_variable_prefix_null()) {
   375         symbol->record_variable->accept(*this);
   351         symbol->record_variable->accept(*this);
   376         s4o.print(".");
   352         s4o.print(".");
   386 /*  subscripted_variable '[' subscript_list ']' */
   362 /*  subscripted_variable '[' subscript_list ']' */
   387 //SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   363 //SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   388 void *visit(array_variable_c *symbol) {
   364 void *visit(array_variable_c *symbol) {
   389   switch (wanted_variablegeneration) {
   365   switch (wanted_variablegeneration) {
   390     case complextype_base_vg:
   366     case complextype_base_vg:
   391     case complextype_base_assignment_vg:
       
   392       symbol->subscripted_variable->accept(*this);
   367       symbol->subscripted_variable->accept(*this);
   393       break;
   368       break;
   394     case complextype_suffix_vg:
   369     case complextype_suffix_vg:
   395       symbol->subscripted_variable->accept(*this);
   370       symbol->subscripted_variable->accept(*this);
   396 
   371 
   494       s4o.print(GET_VAR_REF);
   469       s4o.print(GET_VAR_REF);
   495     
   470     
   496     variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; 
   471     variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; 
   497     s4o.print("(");
   472     s4o.print("(");
   498     wanted_variablegeneration = complextype_base_vg;
   473     wanted_variablegeneration = complextype_base_vg;
       
   474     print_variable_prefix();
   499     symbol->exp->accept(*this);
   475     symbol->exp->accept(*this);
   500     s4o.print(",");
   476     s4o.print(",");
   501     wanted_variablegeneration = complextype_suffix_vg;
   477     wanted_variablegeneration = complextype_suffix_vg;
   502     symbol->exp->accept(*this);
   478     symbol->exp->accept(*this);
   503     s4o.print(")");
   479     s4o.print(")");