diff -r e4d31cd0e6d8 -r ed66dc50f31a stage4/generate_c/generate_c_st.cc --- a/stage4/generate_c/generate_c_st.cc Sun Dec 13 11:41:22 2009 +0100 +++ b/stage4/generate_c/generate_c_st.cc Tue Dec 15 08:51:44 2009 +0100 @@ -80,6 +80,7 @@ search_base_type_c search_base_type; symbol_c* current_array_type; + symbol_c* current_param_type; int fcall_number; symbol_c *fbname; @@ -94,6 +95,7 @@ search_varfb_instance_type = new search_varfb_instance_type_c(scope); this->set_variable_prefix(variable_prefix); current_array_type = NULL; + current_param_type = NULL; fcall_number = 0; fbname = name; wanted_variablegeneration = expression_vg; @@ -115,22 +117,33 @@ void *print_getter(symbol_c *symbol) { unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); - if (vartype == search_var_instance_decl_c::external_vt) - s4o.print(GET_EXTERNAL); - else if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED); - else - s4o.print(GET_VAR); + if (wanted_variablegeneration == fparam_output_vg) { + if (vartype == search_var_instance_decl_c::external_vt) + s4o.print(GET_EXTERNAL_BY_REF); + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED_BY_REF); + else + s4o.print(GET_VAR_BY_REF); + } + else { + if (vartype == search_var_instance_decl_c::external_vt) + s4o.print(GET_EXTERNAL); + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED); + else + s4o.print(GET_VAR); + } s4o.print("("); + variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; wanted_variablegeneration = complextype_base_vg; symbol->accept(*this); if (search_varfb_instance_type->type_is_complex()) - s4o.print(","); + s4o.print(","); wanted_variablegeneration = complextype_suffix_vg; symbol->accept(*this); s4o.print(")"); - wanted_variablegeneration = expression_vg; + wanted_variablegeneration = old_wanted_variablegeneration; return NULL; } @@ -195,18 +208,17 @@ else if (this->is_variable_prefix_null()) { vartype = search_varfb_instance_type->get_vartype(symbol); if (wanted_variablegeneration == fparam_output_vg) { - if (vartype == search_var_instance_decl_c::external_vt) - s4o.print(GET_EXTERNAL); - else - s4o.print("&"); - s4o.print("("); - generate_c_base_c::visit(symbol); - s4o.print(")"); + if (vartype == search_var_instance_decl_c::inoutput_vt) + generate_c_base_c::visit(symbol); + else { + s4o.print("&("); + generate_c_base_c::visit(symbol); + s4o.print(")"); + } } else { - if (vartype == search_var_instance_decl_c::external_vt) { - s4o.print(GET_EXTERNAL); - s4o.print("("); + if (vartype == search_var_instance_decl_c::inoutput_vt) { + s4o.print("(*"); generate_c_base_c::visit(symbol); s4o.print(")"); } @@ -214,37 +226,8 @@ generate_c_base_c::visit(symbol); } } - else { - switch (wanted_variablegeneration) { - case expression_vg: - vartype = search_varfb_instance_type->get_vartype(symbol); - if (vartype == search_var_instance_decl_c::external_vt) - s4o.print(GET_EXTERNAL); - else if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED); - else - s4o.print(GET_VAR); - s4o.print("("); - generate_c_base_c::visit(symbol); - s4o.print(")"); - break; - case fparam_output_vg: - vartype = search_varfb_instance_type->get_vartype(symbol); - if (vartype == search_var_instance_decl_c::external_vt) - s4o.print(GET_EXTERNAL_BY_REF); - else if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED_BY_REF); - else - s4o.print(GET_VAR_BY_REF); - s4o.print("("); - generate_c_base_c::visit(symbol); - s4o.print(")"); - break; - default: - generate_c_base_c::visit(symbol); - break; - } - } + else + print_getter(symbol); return NULL; } @@ -356,6 +339,17 @@ return NULL; } +/******************************************/ +/* B 1.4.3 - Declaration & Initialisation */ +/******************************************/ +void *visit(structure_element_initialization_list_c *symbol) { + generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); + structure_initialization->init_structure_default(this->current_param_type); + structure_initialization->current_mode = generate_c_structure_initialization_c::initializationvalue_sm; + symbol->accept(*structure_initialization); + delete structure_initialization; + return NULL; +} /***************************************/ /* B.3 - Language ST (Structured Text) */ @@ -611,21 +605,21 @@ int nb_param = ((list_c *)parameter_assignment_list)->n; - identifier_c en_param_name("EN"); + symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); /* Get the value from EN param */ - symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name); + symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); if (EN_param_value == NULL) EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); else nb_param --; - ADD_PARAM_LIST(&en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) - - identifier_c eno_param_name("ENO"); + ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) + + symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); /* Get the value from ENO param */ - symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name); + symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); if (ENO_param_value != NULL) nb_param --; - ADD_PARAM_LIST(&eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) + ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) #include "st_code_gen.c" @@ -692,6 +686,8 @@ fbname->accept(*this); s4o.print("_"); function_name->accept(*this); + if (function_type_suffix != NULL) + function_type_suffix->accept(*this); s4o.print_integer(fcall_number); } else { @@ -705,7 +701,7 @@ int nb_param = 0; PARAM_LIST_ITERATOR() { symbol_c *param_value = PARAM_VALUE; - symbol_c *param_type = PARAM_TYPE; + current_param_type = PARAM_TYPE; switch (PARAM_DIRECTION) { case function_param_iterator_c::direction_in: @@ -713,18 +709,18 @@ s4o.print(",\n"+s4o.indent_spaces); if (param_value == NULL) { /* If not, get the default value of this variable's type */ - param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); + param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); } if (param_value == NULL) ERROR; s4o.print("("); - if (search_expression_type->is_literal_integer_type(param_type)) + if (search_expression_type->is_literal_integer_type(current_param_type)) search_expression_type->lint_type_name.accept(*this); - else if (search_expression_type->is_literal_real_type(param_type)) + else if (search_expression_type->is_literal_real_type(current_param_type)) search_expression_type->lreal_type_name.accept(*this); else - param_type->accept(*this); + current_param_type->accept(*this); s4o.print(")"); - print_check_function(param_type, param_value); + print_check_function(current_param_type, param_value); nb_param++; break; case function_param_iterator_c::direction_out: