--- a/stage4/generate_c/generate_c_st.cc Sat Dec 05 18:35:38 2009 +0100
+++ b/stage4/generate_c/generate_c_st.cc Sat Dec 05 18:38:53 2009 +0100
@@ -44,6 +44,8 @@
typedef enum {
expression_vg,
assignment_vg,
+ complextype_base_vg,
+ complextype_suffix_vg,
fparam_output_vg
} variablegeneration_t;
@@ -111,14 +113,74 @@
private:
+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);
+ s4o.print("(");
+
+ wanted_variablegeneration = complextype_base_vg;
+ symbol->accept(*this);
+ if (search_varfb_instance_type->type_is_complex())
+ s4o.print(",");
+ wanted_variablegeneration = complextype_suffix_vg;
+ symbol->accept(*this);
+ s4o.print(")");
+ wanted_variablegeneration = expression_vg;
+ return NULL;
+}
+
+void *print_setter(symbol_c* symbol,
+ symbol_c* type,
+ symbol_c* value,
+ symbol_c* fb_symbol = NULL,
+ symbol_c* fb_value = NULL) {
+ unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
+ if (vartype == search_var_instance_decl_c::external_vt)
+ s4o.print(SET_EXTERNAL);
+ else if (vartype == search_var_instance_decl_c::located_vt)
+ s4o.print(SET_LOCATED);
+ else
+ s4o.print(SET_VAR);
+ s4o.print("(");
+
+ if (fb_symbol != NULL) {
+ print_variable_prefix();
+ fb_symbol->accept(*this);
+ s4o.print(".");
+ }
+ else
+ wanted_variablegeneration = complextype_base_vg;
+ symbol->accept(*this);
+ s4o.print(",");
+ wanted_variablegeneration = expression_vg;
+ print_check_function(type, value, fb_value);
+ if (search_varfb_instance_type->type_is_complex()) {
+ s4o.print(",");
+ wanted_variablegeneration = complextype_suffix_vg;
+ symbol->accept(*this);
+ }
+ s4o.print(")");
+ wanted_variablegeneration = expression_vg;
+ return NULL;
+}
/*********************/
/* B 1.4 - Variables */
/*********************/
void *visit(symbolic_variable_c *symbol) {
- unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
- if (this->is_variable_prefix_null()) {
- if (wanted_variablegeneration == fparam_output_vg) {
+ unsigned int vartype;
+ if (wanted_variablegeneration == complextype_base_vg)
+ generate_c_base_c::visit(symbol);
+ else if (wanted_variablegeneration == complextype_suffix_vg)
+ return NULL;
+ 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
@@ -141,7 +203,8 @@
else {
switch (wanted_variablegeneration) {
case expression_vg:
- if (vartype == search_var_instance_decl_c::external_vt)
+ 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);
@@ -152,7 +215,8 @@
s4o.print(")");
break;
case fparam_output_vg:
- if (vartype == search_var_instance_decl_c::external_vt)
+ 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);
@@ -211,60 +275,24 @@
// SYM_REF2(structured_variable_c, record_variable, field_selector)
void *visit(structured_variable_c *symbol) {
TRACE("structured_variable_c");
-
- unsigned int vartype = search_varfb_instance_type->get_vartype(symbol->record_variable);
- if (this->is_variable_prefix_null()) {
- symbol->record_variable->accept(*this);
- s4o.print(".");
- symbol->field_selector->accept(*this);
- }
- else {
- variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
- switch (wanted_variablegeneration) {
- case expression_vg:
- wanted_variablegeneration = assignment_vg;
- if (vartype == search_var_instance_decl_c::external_vt) {
- s4o.print(GET_EXTERNAL);
- s4o.print("(");
- symbol->record_variable->accept(*this);
- s4o.print(").");
- symbol->field_selector->accept(*this);
- }
- else {
- if (vartype == search_var_instance_decl_c::located_vt)
- s4o.print(GET_LOCATED);
- else
- s4o.print(GET_VAR);
- s4o.print("(");
- symbol->record_variable->accept(*this);
- s4o.print(".");
- symbol->field_selector->accept(*this);
- s4o.print(")");
- }
- wanted_variablegeneration = old_wanted_variablegeneration;
- break;
- case fparam_output_vg:
- wanted_variablegeneration = assignment_vg;
- s4o.print("&(");
- 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("(");
- symbol->record_variable->accept(*this);
- s4o.print(").");
- symbol->field_selector->accept(*this);
- s4o.print("))");
- wanted_variablegeneration = old_wanted_variablegeneration;
- break;
- default:
+ switch (wanted_variablegeneration) {
+ case complextype_base_vg:
+ symbol->record_variable->accept(*this);
+ break;
+ case complextype_suffix_vg:
+ symbol->record_variable->accept(*this);
+ s4o.print(".");
+ symbol->field_selector->accept(*this);
+ break;
+ default:
+ if (this->is_variable_prefix_null()) {
symbol->record_variable->accept(*this);
s4o.print(".");
symbol->field_selector->accept(*this);
- break;
- }
+ }
+ else
+ print_getter(symbol);
+ break;
}
return NULL;
}
@@ -272,11 +300,30 @@
/* subscripted_variable '[' subscript_list ']' */
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
void *visit(array_variable_c *symbol) {
- current_array_type = search_varfb_instance_type->get_type(symbol->subscripted_variable, false);
- symbol->subscripted_variable->accept(*this);
- if (current_array_type != NULL) {
- symbol->subscript_list->accept(*this);
- current_array_type = NULL;
+ switch (wanted_variablegeneration) {
+ case complextype_base_vg:
+ symbol->subscripted_variable->accept(*this);
+ break;
+ case complextype_suffix_vg:
+ current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable);
+ symbol->subscripted_variable->accept(*this);
+ if (current_array_type != NULL) {
+ symbol->subscript_list->accept(*this);
+ current_array_type = NULL;
+ }
+ break;
+ default:
+ if (this->is_variable_prefix_null()) {
+ current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable);
+ symbol->subscripted_variable->accept(*this);
+ if (current_array_type != NULL) {
+ symbol->subscript_list->accept(*this);
+ current_array_type = NULL;
+ }
+ }
+ else
+ print_getter(symbol);
+ break;
}
return NULL;
}
@@ -708,32 +755,16 @@
/* B 3.2.1 Assignment Statements */
/*********************************/
void *visit(assignment_statement_c *symbol) {
- symbol_c *left_type = search_varfb_instance_type->get_type(symbol->l_exp, false);
+ symbol_c *left_type = search_varfb_instance_type->get_rawtype(symbol->l_exp);
- if (!this->is_variable_prefix_null()) {
- unsigned int vartype = search_varfb_instance_type->get_vartype(symbol->l_exp);
- if (vartype == search_var_instance_decl_c::external_vt)
- s4o.print(SET_EXTERNAL);
- else if (vartype == search_var_instance_decl_c::located_vt)
- s4o.print(SET_LOCATED);
- else
- s4o.print(SET_VAR);
- s4o.print("(");
-
- wanted_variablegeneration = assignment_vg;
+ if (this->is_variable_prefix_null()) {
symbol->l_exp->accept(*this);
- wanted_variablegeneration = expression_vg;
-
- s4o.print(",");
+ s4o.print(" = ");
+ print_check_function(left_type, symbol->r_exp);
}
else {
- symbol->l_exp->accept(*this);
-
- s4o.print(" = ");
- }
- print_check_function(left_type, symbol->r_exp);
- if (!this->is_variable_prefix_null())
- s4o.print(")");
+ print_setter(symbol->l_exp, left_type, symbol->r_exp);
+ }
return NULL;
}
@@ -781,21 +812,17 @@
if (param_value != NULL)
if ((param_direction == function_param_iterator_c::direction_in) ||
(param_direction == function_param_iterator_c::direction_inout)) {
- if (!this->is_variable_prefix_null()) {
- s4o.print(SET_VAR);
- s4o.print("(");
+ if (this->is_variable_prefix_null()) {
+ print_variable_prefix();
+ symbol->fb_name->accept(*this);
+ s4o.print(".");
+ param_name->accept(*this);
+ s4o.print(" = ");
+ print_check_function(param_type, param_value);
}
- print_variable_prefix();
- symbol->fb_name->accept(*this);
- s4o.print(".");
- param_name->accept(*this);
- if (this->is_variable_prefix_null())
- s4o.print(" = ");
- else
- s4o.print(",");
- print_check_function(param_type, param_value);
- if (!this->is_variable_prefix_null())
- s4o.print(")");
+ else {
+ print_setter(param_name, param_type, param_value, symbol->fb_name);
+ }
s4o.print(";\n" + s4o.indent_spaces);
}
} /* for(...) */
@@ -827,31 +854,15 @@
if (param_value != NULL)
if ((param_direction == function_param_iterator_c::direction_out) ||
(param_direction == function_param_iterator_c::direction_inout)) {
- symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false);
-
- if (!this->is_variable_prefix_null()) {
- unsigned int vartype = search_varfb_instance_type->get_vartype(param_value);
- s4o.print(";\n"+ s4o.indent_spaces);
- if (vartype == search_var_instance_decl_c::external_vt)
- s4o.print(SET_EXTERNAL);
- else if (vartype == search_var_instance_decl_c::located_vt)
- s4o.print(SET_LOCATED);
- else
- s4o.print(SET_VAR);
- s4o.print("(");
-
- wanted_variablegeneration = assignment_vg;
+ symbol_c *param_type = search_varfb_instance_type->get_rawtype(param_value);
+ if (this->is_variable_prefix_null()) {
param_value->accept(*this);
- wanted_variablegeneration = expression_vg;
- s4o.print(",");
+ s4o.print(" = ");
+ print_check_function(param_type, param_name, symbol->fb_name);
}
else {
- param_value->accept(*this);
- s4o.print(" = ");
+ print_setter(param_value, param_type, param_name, NULL, symbol->fb_name);
}
- print_check_function(param_type, param_name, symbol->fb_name);
- if (!this->is_variable_prefix_null())
- s4o.print(")");
}
} /* for(...) */