--- a/stage4/generate_c/generate_c_sfc.cc Tue Sep 11 01:05:24 2012 +0200
+++ b/stage4/generate_c/generate_c_sfc.cc Tue Sep 11 16:27:33 2012 +0200
@@ -51,6 +51,7 @@
generate_c_il_c *generate_c_il;
generate_c_st_c *generate_c_st;
generate_c_SFC_IL_ST_c *generate_c_code;
+ search_var_instance_decl_c *search_var_instance_decl;
int transition_number;
std::list<TRANSITION> transition_list;
@@ -66,6 +67,7 @@
generate_c_il = new generate_c_il_c(s4o_ptr, name, scope, variable_prefix);
generate_c_st = new generate_c_st_c(s4o_ptr, name, scope, variable_prefix);
generate_c_code = new generate_c_SFC_IL_ST_c(s4o_ptr, name, scope, variable_prefix);
+ search_var_instance_decl = new search_var_instance_decl_c(scope);
this->set_variable_prefix(variable_prefix);
}
@@ -74,7 +76,16 @@
delete generate_c_il;
delete generate_c_st;
delete generate_c_code;
- }
+ delete search_var_instance_decl;
+ }
+
+
+ bool is_variable(symbol_c *symbol) {
+ /* we try to find the variable instance declaration, to determine if symbol is variable... */
+ symbol_c *var_decl = search_var_instance_decl->get_decl(symbol);
+
+ return var_decl != NULL;
+ }
void reset_transition_number(void) {transition_number = 0;}
@@ -423,8 +434,8 @@
if (symbol->step_name != NULL) {
switch (wanted_sfcgeneration) {
case transitiontest_sg:
- s4o.print(GET_VAR);
- s4o.print("(");
+ s4o.print(GET_VAR);
+ s4o.print("(");
print_step_argument(symbol->step_name, "state");
s4o.print(")");
break;
@@ -448,8 +459,8 @@
switch (wanted_sfcgeneration) {
case transitiontest_sg:
for(int i = 0; i < symbol->n; i++) {
- s4o.print(GET_VAR);
- s4o.print("(");
+ s4o.print(GET_VAR);
+ s4o.print("(");
print_step_argument(symbol->elements[i], "state");
s4o.print(")");
if (i < symbol->n - 1) {
@@ -524,8 +535,8 @@
s4o.print("active");
}
else if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 ||
- strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0 ||
- strcmp(qualifier, "P0") == 0) {
+ strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0 ||
+ strcmp(qualifier, "P0") == 0) {
s4o.print("activated");
}
else if (strcmp(qualifier, "P1") == 0) {
@@ -549,10 +560,44 @@
if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 ||
strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0 ||
strcmp(qualifier, "P0") == 0 || strcmp(qualifier, "P1") == 0) {
- s4o.print(SET_VAR);
- s4o.print("(");
- print_action_argument(current_action, "state", true);
- s4o.print(",1);\n");
+
+ if (is_variable(current_action)) {
+ unsigned int vartype = search_var_instance_decl->get_vartype(current_action);
+
+ 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("(");
+ print_variable_prefix();
+ s4o.print(",");
+ current_action->accept(*this);
+ s4o.print(",1);\n");
+ s4o.indent_left();
+ s4o.print("}\n");
+ s4o.print(s4o.indent_spaces + "else if (active) {\n");
+ s4o.indent_right();
+ 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("(");
+ print_variable_prefix();
+ s4o.print(",");
+ current_action->accept(*this);
+ s4o.print(",0);\n");
+ }
+
+ else {
+ s4o.print(SET_VAR);
+ s4o.print("(");
+ print_action_argument(current_action, "state", true);
+ s4o.print(",1);\n");
+ }
}
if (strcmp(qualifier, "S") == 0 || strcmp(qualifier, "SL") == 0) {
print_action_argument(current_action, "set");
@@ -865,29 +910,52 @@
{
std::list<VARIABLE>::iterator pt;
for(pt = variable_list.begin(); pt != variable_list.end(); pt++) {
- symbol_c *var_decl = search_var_instance_decl->get_decl(pt->symbol);
- if (var_decl != NULL) {
+
+ if (is_variable(pt->symbol)) {
unsigned int vartype = search_var_instance_decl->get_vartype(pt->symbol);
- s4o.print(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("(");
- print_variable_prefix();
- s4o.print(",");
- pt->symbol->accept(*this);
- s4o.print(",");
- s4o.print(GET_VAR);
- s4o.print("(");
+ s4o.print(s4o.indent_spaces + "if (");
print_variable_prefix();
s4o.print("__action_list[");
s4o.print(SFC_STEP_ACTION_PREFIX);
pt->symbol->accept(*this);
- s4o.print("].state));\n");
+ s4o.print("].reset) {\n");
+ s4o.indent_right();
+ s4o.print(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("(");
+ print_variable_prefix();
+ s4o.print(",");
+ pt->symbol->accept(*this);
+ s4o.print(",0);\n");
+ s4o.indent_left();
+ s4o.print(s4o.indent_spaces + "}\n");
+ s4o.print(s4o.indent_spaces + "else if (");
+ print_variable_prefix();
+ s4o.print("__action_list[");
+ s4o.print(SFC_STEP_ACTION_PREFIX);
+ pt->symbol->accept(*this);
+ s4o.print("].set) {\n");
+ s4o.indent_right();
+ s4o.print(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("(");
+ print_variable_prefix();
+ s4o.print(",");
+ pt->symbol->accept(*this);
+ s4o.print(",1);\n");
+ s4o.indent_left();
+ s4o.print(s4o.indent_spaces + "}\n");
}
}
}
@@ -910,9 +978,7 @@
}
void *visit(action_association_c *symbol) {
- symbol_c *var_decl = search_var_instance_decl->get_decl(symbol->action_name);
-
- if (var_decl != NULL) {
+ if (is_variable(symbol->action_name)) {
std::list<VARIABLE>::iterator pt;
for(pt = variable_list.begin(); pt != variable_list.end(); pt++) {
if (!compare_identifiers(pt->symbol, symbol->action_name))