stage4/generate_c/generate_c_inlinefcall.cc
changeset 388 17eaad42ba88
parent 383 0b81b59f333b
child 392 9b88b8b6bccd
equal deleted inserted replaced
387:db368e53133c 388:17eaad42ba88
    98 	il_default_variable_c default_variable_back_name;
    98 	il_default_variable_c default_variable_back_name;
    99 
    99 
   100 	symbol_c* current_array_type;
   100 	symbol_c* current_array_type;
   101 
   101 
   102 	int fcall_number;
   102 	int fcall_number;
       
   103 	bool generating_inlinefunction;
   103 	symbol_c *fbname;
   104 	symbol_c *fbname;
   104 
   105 
   105     search_expression_type_c *search_expression_type;
   106     search_expression_type_c *search_expression_type;
   106 
   107 
   107     search_varfb_instance_type_c *search_varfb_instance_type;
   108     search_varfb_instance_type_c *search_varfb_instance_type;
   120       search_varfb_instance_type = new search_varfb_instance_type_c(scope);
   121       search_varfb_instance_type = new search_varfb_instance_type_c(scope);
   121       this->set_variable_prefix(variable_prefix);
   122       this->set_variable_prefix(variable_prefix);
   122       fcall_number = 0;
   123       fcall_number = 0;
   123       fbname = name;
   124       fbname = name;
   124       wanted_variablegeneration = expression_vg;
   125       wanted_variablegeneration = expression_vg;
       
   126       generating_inlinefunction = false;
   125     }
   127     }
   126 
   128 
   127     virtual ~generate_c_inlinefcall_c(void) {
   129     virtual ~generate_c_inlinefcall_c(void) {
   128       delete search_expression_type;
   130       delete search_expression_type;
   129       delete search_varfb_instance_type;
   131       delete search_varfb_instance_type;
   142     void generate_inline(symbol_c *function_name,
   144     void generate_inline(symbol_c *function_name,
   143             symbol_c *function_type_prefix,
   145             symbol_c *function_type_prefix,
   144             symbol_c *function_type_suffix,
   146             symbol_c *function_type_suffix,
   145             std::list<FUNCTION_PARAM*> param_list,
   147             std::list<FUNCTION_PARAM*> param_list,
   146             function_declaration_c *f_decl = NULL) {
   148             function_declaration_c *f_decl = NULL) {
   147             std::list<FUNCTION_PARAM*>::iterator pt;
   149 
       
   150       std::list<FUNCTION_PARAM*>::iterator pt;
       
   151       generating_inlinefunction = true;
   148 
   152 
   149       fcall_number++;
   153       fcall_number++;
   150       function_type_prefix = search_expression_type->default_literal_type(function_type_prefix);
   154       function_type_prefix = search_expression_type->default_literal_type(function_type_prefix);
   151       if (function_type_suffix) {
   155       if (function_type_suffix) {
   152         function_type_suffix = search_expression_type->default_literal_type(function_type_suffix);
   156         function_type_suffix = search_expression_type->default_literal_type(function_type_suffix);
   253       s4o.print(INLINE_RESULT_TEMP_VAR);
   257       s4o.print(INLINE_RESULT_TEMP_VAR);
   254       s4o.print(";\n");
   258       s4o.print(";\n");
   255 
   259 
   256       s4o.indent_left();
   260       s4o.indent_left();
   257       s4o.print(s4o.indent_spaces + "}\n\n");
   261       s4o.print(s4o.indent_spaces + "}\n\n");
       
   262 
       
   263       generating_inlinefunction = false;
   258     }
   264     }
   259 
   265 
   260   private:
   266   private:
   261 
   267 
   262     /* A helper function... */
   268     /* A helper function... */
   364     /*********************/
   370     /*********************/
   365     /* B 1.4 - Variables */
   371     /* B 1.4 - Variables */
   366     /*********************/
   372     /*********************/
   367     void *visit(symbolic_variable_c *symbol) {
   373     void *visit(symbolic_variable_c *symbol) {
   368       unsigned int vartype;
   374       unsigned int vartype;
   369       if (wanted_variablegeneration == complextype_base_vg)
   375       if (generating_inlinefunction) {
   370         generate_c_base_c::visit(symbol);
   376         if (wanted_variablegeneration == complextype_base_vg)
   371       else if (wanted_variablegeneration == complextype_suffix_vg)
   377           generate_c_base_c::visit(symbol);
   372         return NULL;
   378         else if (wanted_variablegeneration == complextype_suffix_vg)
   373       else
   379           return NULL;
   374         print_getter(symbol);
   380         else
       
   381           print_getter(symbol);
       
   382       }
   375       return NULL;
   383       return NULL;
   376     }
   384     }
   377 
   385 
   378     /********************************************/
   386     /********************************************/
   379     /* B.1.4.1   Directly Represented Variables */
   387     /* B.1.4.1   Directly Represented Variables */
   380     /********************************************/
   388     /********************************************/
   381     // direct_variable: direct_variable_token   {$$ = new direct_variable_c($1);};
   389     // direct_variable: direct_variable_token   {$$ = new direct_variable_c($1);};
   382     void *visit(direct_variable_c *symbol) {
   390     void *visit(direct_variable_c *symbol) {
   383       TRACE("direct_variable_c");
   391       TRACE("direct_variable_c");
   384       /* Do not use print_token() as it will change everything into uppercase */
   392       if (generating_inlinefunction) {
   385       if (strlen(symbol->value) == 0) ERROR;
   393         /* Do not use print_token() as it will change everything into uppercase */
   386       s4o.print(GET_LOCATED);
   394         if (strlen(symbol->value) == 0) ERROR;
   387       s4o.print("(");
   395         s4o.print(GET_LOCATED);
   388       this->print_variable_prefix();
   396         s4o.print("(");
   389       s4o.printlocation(symbol->value + 1);
   397         this->print_variable_prefix();
   390       s4o.print(")");
   398         s4o.printlocation(symbol->value + 1);
       
   399         s4o.print(")");
       
   400       }
   391       return NULL;
   401       return NULL;
   392     }
   402     }
   393 
   403 
   394     /*************************************/
   404     /*************************************/
   395     /* B.1.4.2   Multi-element Variables */
   405     /* B.1.4.2   Multi-element Variables */
   396     /*************************************/
   406     /*************************************/
   397 
   407 
   398     // SYM_REF2(structured_variable_c, record_variable, field_selector)
   408     // SYM_REF2(structured_variable_c, record_variable, field_selector)
   399     void *visit(structured_variable_c *symbol) {
   409     void *visit(structured_variable_c *symbol) {
   400       TRACE("structured_variable_c");
   410       TRACE("structured_variable_c");
   401       switch (wanted_variablegeneration) {
   411       if (generating_inlinefunction) {
   402         case complextype_base_vg:
   412         switch (wanted_variablegeneration) {
   403           symbol->record_variable->accept(*this);
   413           case complextype_base_vg:
   404           break;
   414             symbol->record_variable->accept(*this);
   405         case complextype_suffix_vg:
   415             break;
   406           symbol->record_variable->accept(*this);
   416           case complextype_suffix_vg:
   407           s4o.print(".");
   417             symbol->record_variable->accept(*this);
   408           symbol->field_selector->accept(*this);
   418             s4o.print(".");
   409           break;
   419             symbol->field_selector->accept(*this);
   410         default:
   420             break;
   411           print_getter(symbol);
   421           default:
   412           break;
   422             print_getter(symbol);
       
   423             break;
       
   424         }
   413       }
   425       }
   414       return NULL;
   426       return NULL;
   415     }
   427     }
   416 
   428 
   417     /*  subscripted_variable '[' subscript_list ']' */
   429     /*  subscripted_variable '[' subscript_list ']' */
   418     //SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   430     //SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   419     void *visit(array_variable_c *symbol) {
   431     void *visit(array_variable_c *symbol) {
   420       switch (wanted_variablegeneration) {
   432       if (generating_inlinefunction) {
   421         case complextype_base_vg:
   433         switch (wanted_variablegeneration) {
   422           symbol->subscripted_variable->accept(*this);
   434           case complextype_base_vg:
   423           break;
   435             symbol->subscripted_variable->accept(*this);
   424         case complextype_suffix_vg:
   436             break;
   425           symbol->subscripted_variable->accept(*this);
   437           case complextype_suffix_vg:
   426 
   438             symbol->subscripted_variable->accept(*this);
   427           current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
   439 
   428           if (current_array_type == NULL) ERROR;
   440             current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
   429 
   441             if (current_array_type == NULL) ERROR;
   430           s4o.print(".table");
   442 
   431           symbol->subscript_list->accept(*this);
   443             s4o.print(".table");
   432 
   444             symbol->subscript_list->accept(*this);
   433           current_array_type = NULL;
   445 
   434           break;
   446             current_array_type = NULL;
   435         default:
   447             break;
   436           print_getter(symbol);
   448           default:
   437           break;
   449             print_getter(symbol);
       
   450             break;
       
   451         }
   438       }
   452       }
   439       return NULL;
   453       return NULL;
   440     }
   454     }
   441 
   455 
   442     /****************************************/
   456     /****************************************/
  1148       CLEAR_PARAM_LIST()
  1162       CLEAR_PARAM_LIST()
  1149 
  1163 
  1150       return NULL;
  1164       return NULL;
  1151     }
  1165     }
  1152 
  1166 
       
  1167 	/*********************************************/
       
  1168 	/* B.1.6  Sequential function chart elements */
       
  1169 	/*********************************************/
       
  1170 
       
  1171 	void *visit(initial_step_c *symbol) {
       
  1172 		return NULL;
       
  1173 	}
       
  1174 
       
  1175 	void *visit(step_c *symbol) {
       
  1176 		return NULL;
       
  1177 	}
       
  1178 
       
  1179 	void *visit(transition_c *symbol) {
       
  1180 		return symbol->transition_condition->accept(*this);
       
  1181 	}
       
  1182 
       
  1183 	void *visit(transition_condition_c *symbol) {
       
  1184 		// Transition condition is in IL
       
  1185 		if (symbol->transition_condition_il != NULL) {
       
  1186 			symbol->transition_condition_il->accept(*this);
       
  1187 		}
       
  1188 
       
  1189 		// Transition condition is in ST
       
  1190 		if (symbol->transition_condition_st != NULL) {
       
  1191 			symbol->transition_condition_st->accept(*this);
       
  1192 		}
       
  1193 
       
  1194 		return NULL;
       
  1195 	}
       
  1196 
       
  1197 	void *visit(action_c *symbol) {
       
  1198 		return symbol->function_block_body->accept(*this);
       
  1199 	}
       
  1200 
  1153 };  /* generate_c_inlinefcall_c */
  1201 };  /* generate_c_inlinefcall_c */
  1154 
  1202 
  1155