stage4/generate_c/generate_c_st.cc
changeset 625 c0bda77b37a0
parent 411 3e21d98d0a71
parent 594 c8092e909886
child 667 bd1360f29f15
child 706 31553c22f318
equal deleted inserted replaced
412:aad38592bdde 625:c0bda77b37a0
    87      * remaining st code is being handled.
    87      * remaining st code is being handled.
    88      */
    88      */
    89     search_expression_type_c *search_expression_type;
    89     search_expression_type_c *search_expression_type;
    90 
    90 
    91     search_varfb_instance_type_c *search_varfb_instance_type;
    91     search_varfb_instance_type_c *search_varfb_instance_type;
       
    92     search_var_instance_decl_c   *search_var_instance_decl;
    92 
    93 
    93     search_base_type_c search_base_type;
    94     search_base_type_c search_base_type;
    94 
    95 
    95     symbol_c* current_array_type;
    96     symbol_c* current_array_type;
    96     symbol_c* current_param_type;
    97     symbol_c* current_param_type;
   107     generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
   108     generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
   108     : generate_c_typedecl_c(s4o_ptr) {
   109     : generate_c_typedecl_c(s4o_ptr) {
   109       search_fb_instance_decl = new search_fb_instance_decl_c(scope);
   110       search_fb_instance_decl = new search_fb_instance_decl_c(scope);
   110       search_expression_type = new search_expression_type_c(scope);
   111       search_expression_type = new search_expression_type_c(scope);
   111       search_varfb_instance_type = new search_varfb_instance_type_c(scope);
   112       search_varfb_instance_type = new search_varfb_instance_type_c(scope);
       
   113       search_var_instance_decl   = new search_var_instance_decl_c(scope);
       
   114       
   112       this->set_variable_prefix(variable_prefix);
   115       this->set_variable_prefix(variable_prefix);
   113       current_array_type = NULL;
   116       current_array_type = NULL;
   114       current_param_type = NULL;
   117       current_param_type = NULL;
   115       fcall_number = 0;
   118       fcall_number = 0;
   116       fbname = name;
   119       fbname = name;
   120 
   123 
   121     virtual ~generate_c_st_c(void) {
   124     virtual ~generate_c_st_c(void) {
   122       delete search_fb_instance_decl;
   125       delete search_fb_instance_decl;
   123       delete search_expression_type;
   126       delete search_expression_type;
   124       delete search_varfb_instance_type;
   127       delete search_varfb_instance_type;
       
   128       delete search_var_instance_decl;
   125     }
   129     }
   126 
   130 
   127 
   131 
   128   public:
   132   public:
   129     void generate(statement_list_c *stl) {
   133     void generate(statement_list_c *stl) {
   130       stl->accept(*this);
   134       stl->accept(*this);
   131     }
   135     }
   132 
   136 
   133   private:
   137   private:
       
   138     
       
   139     
       
   140 
       
   141 
       
   142 
   134 
   143 
   135 void *print_getter(symbol_c *symbol) {
   144 void *print_getter(symbol_c *symbol) {
   136   unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   145   unsigned int vartype = search_var_instance_decl->get_vartype(symbol);
   137   if (wanted_variablegeneration == fparam_output_vg) {
   146   if (wanted_variablegeneration == fparam_output_vg) {
   138   	if (vartype == search_var_instance_decl_c::external_vt)
   147     if (vartype == search_var_instance_decl_c::external_vt)
   139       s4o.print(GET_EXTERNAL_BY_REF);
   148       s4o.print(GET_EXTERNAL_BY_REF);
   140     else if (vartype == search_var_instance_decl_c::located_vt)
   149     else if (vartype == search_var_instance_decl_c::located_vt)
   141       s4o.print(GET_LOCATED_BY_REF);
   150       s4o.print(GET_LOCATED_BY_REF);
   142     else
   151     else
   143       s4o.print(GET_VAR_BY_REF);
   152       s4o.print(GET_VAR_BY_REF);
   144   }
   153   }
   145   else {
   154   else {
   146 	if (vartype == search_var_instance_decl_c::external_vt)
   155     if (vartype == search_var_instance_decl_c::external_vt)
   147 	  s4o.print(GET_EXTERNAL);
   156       s4o.print(GET_EXTERNAL);
   148 	else if (vartype == search_var_instance_decl_c::located_vt)
   157     else if (vartype == search_var_instance_decl_c::located_vt)
   149 	  s4o.print(GET_LOCATED);
   158       s4o.print(GET_LOCATED);
   150 	else
   159     else
   151 	  s4o.print(GET_VAR);
   160       s4o.print(GET_VAR);
   152   }
   161   }
   153   s4o.print("(");
   162   s4o.print("(");
   154 
   163 
   155   variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
   164   variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
   156   wanted_variablegeneration = complextype_base_vg;
   165   wanted_variablegeneration = complextype_base_vg;
   157   symbol->accept(*this);
   166   symbol->accept(*this);
   158   if (search_varfb_instance_type->type_is_complex())
   167   if (search_var_instance_decl->type_is_complex(symbol))
   159     s4o.print(",");
   168     s4o.print(",");
   160   wanted_variablegeneration = complextype_suffix_vg;
   169   wanted_variablegeneration = complextype_suffix_vg;
   161   symbol->accept(*this);
   170   symbol->accept(*this);
   162   s4o.print(")");
   171   s4o.print(")");
   163   wanted_variablegeneration = old_wanted_variablegeneration;
   172   wanted_variablegeneration = old_wanted_variablegeneration;
   170 		symbol_c* fb_symbol = NULL,
   179 		symbol_c* fb_symbol = NULL,
   171 		symbol_c* fb_value = NULL) {
   180 		symbol_c* fb_value = NULL) {
   172   
   181   
   173   bool type_is_complex = false;
   182   bool type_is_complex = false;
   174   if (fb_symbol == NULL) {
   183   if (fb_symbol == NULL) {
   175 	unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   184     unsigned int vartype = search_var_instance_decl->get_vartype(symbol);
   176     type_is_complex = search_varfb_instance_type->type_is_complex();
   185     type_is_complex = search_var_instance_decl->type_is_complex(symbol);
   177     if (vartype == search_var_instance_decl_c::external_vt)
   186     if (vartype == search_var_instance_decl_c::external_vt)
   178       s4o.print(SET_EXTERNAL);
   187       s4o.print(SET_EXTERNAL);
   179     else if (vartype == search_var_instance_decl_c::located_vt)
   188     else if (vartype == search_var_instance_decl_c::located_vt)
   180       s4o.print(SET_LOCATED);
   189       s4o.print(SET_LOCATED);
   181     else
   190     else
   237 
   246 
   238 /*********************/
   247 /*********************/
   239 /* B 1.4 - Variables */
   248 /* B 1.4 - Variables */
   240 /*********************/
   249 /*********************/
   241 void *visit(symbolic_variable_c *symbol) {
   250 void *visit(symbolic_variable_c *symbol) {
   242   unsigned int vartype;
       
   243   switch (wanted_variablegeneration) {
   251   switch (wanted_variablegeneration) {
   244     case complextype_base_assignment_vg:
   252     case complextype_base_assignment_vg:
   245     case assignment_vg:
   253     case assignment_vg:
   246       this->print_variable_prefix();
   254       this->print_variable_prefix();
   247       s4o.print(",");
   255       s4o.print(",");
   252       break;
   260       break;
   253     case complextype_suffix_vg:
   261     case complextype_suffix_vg:
   254       break;
   262       break;
   255     default:
   263     default:
   256       if (this->is_variable_prefix_null()) {
   264       if (this->is_variable_prefix_null()) {
   257         vartype = search_varfb_instance_type->get_vartype(symbol);
       
   258         if (wanted_variablegeneration == fparam_output_vg) {
   265         if (wanted_variablegeneration == fparam_output_vg) {
   259           s4o.print("&(");
   266           s4o.print("&(");
   260           generate_c_base_c::visit(symbol);
   267           generate_c_base_c::visit(symbol);
   261           s4o.print(")");
   268           s4o.print(")");
   262         }
   269         }
   310 /*************************************/
   317 /*************************************/
   311 
   318 
   312 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   319 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   313 void *visit(structured_variable_c *symbol) {
   320 void *visit(structured_variable_c *symbol) {
   314   TRACE("structured_variable_c");
   321   TRACE("structured_variable_c");
   315   unsigned int vartype = search_varfb_instance_type->get_vartype(symbol->record_variable);
   322   bool type_is_complex = search_var_instance_decl->type_is_complex(symbol->record_variable);
   316   bool type_is_complex = search_varfb_instance_type->type_is_complex();
       
   317   switch (wanted_variablegeneration) {
   323   switch (wanted_variablegeneration) {
   318     case complextype_base_vg:
   324     case complextype_base_vg:
   319     case complextype_base_assignment_vg:
   325     case complextype_base_assignment_vg:
   320       symbol->record_variable->accept(*this);
   326       symbol->record_variable->accept(*this);
   321       if (!type_is_complex) {
   327       if (!type_is_complex) {
   357       symbol->subscripted_variable->accept(*this);
   363       symbol->subscripted_variable->accept(*this);
   358       break;
   364       break;
   359     case complextype_suffix_vg:
   365     case complextype_suffix_vg:
   360       symbol->subscripted_variable->accept(*this);
   366       symbol->subscripted_variable->accept(*this);
   361 
   367 
   362       current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
   368       current_array_type = search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable);
   363       if (current_array_type == NULL) ERROR;
   369       if (current_array_type == NULL) ERROR;
   364 
   370 
   365       s4o.print(".table");
   371       s4o.print(".table");
   366       wanted_variablegeneration = expression_vg;
   372       wanted_variablegeneration = expression_vg;
   367       symbol->subscript_list->accept(*this);
   373       symbol->subscript_list->accept(*this);
   371       break;
   377       break;
   372     default:
   378     default:
   373       if (this->is_variable_prefix_null()) {
   379       if (this->is_variable_prefix_null()) {
   374     	symbol->subscripted_variable->accept(*this);
   380     	symbol->subscripted_variable->accept(*this);
   375 
   381 
   376     	current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
   382     	current_array_type = search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable);
   377     	if (current_array_type == NULL) ERROR;
   383     	if (current_array_type == NULL) ERROR;
   378 
   384 
   379     	s4o.print(".table");
   385     	s4o.print(".table");
   380         symbol->subscript_list->accept(*this);
   386         symbol->subscript_list->accept(*this);
   381 
   387 
   795       /* function being called is overloaded! */
   801       /* function being called is overloaded! */
   796       s4o.print("__");
   802       s4o.print("__");
   797       print_function_parameter_data_types_c overloaded_func_suf(&s4o);
   803       print_function_parameter_data_types_c overloaded_func_suf(&s4o);
   798       f_decl->accept(overloaded_func_suf);
   804       f_decl->accept(overloaded_func_suf);
   799     }
   805     }
   800     s4o.print_integer(fcall_number);
   806     s4o.print(fcall_number);
   801   }
   807   }
   802   else {
   808   else {
   803     function_name->accept(*this);
   809     function_name->accept(*this);
   804     if (fdecl_mutiplicity == 2) {
   810     if (fdecl_mutiplicity == 2) {
   805       /* function being called is overloaded! */
   811       /* function being called is overloaded! */