# HG changeset patch # User lbessard # Date 1172593450 -3600 # Node ID e6af5eb5f5460df6659292d71210aa9af857c9b4 # Parent 38754701ac41bdfe11c23a09544c3e6f1d6737f1 SFC generator improved diff -r 38754701ac41 -r e6af5eb5f546 stage4/generate_cc/generate_cc.cc --- a/stage4/generate_cc/generate_cc.cc Fri Feb 23 19:19:23 2007 +0100 +++ b/stage4/generate_cc/generate_cc.cc Tue Feb 27 17:24:10 2007 +0100 @@ -147,7 +147,7 @@ #define FB_FUNCTION_SUFFIX "_body__" /* The FB body function is passed as the only parameter a pointer to the FB data - * structure instance. The name of this parameter is given by the following cosntant. + * structure instance. The name of this parameter is given by the following constant. * In order not to clash with any variable in the IL and ST source codem the * following constant should contain a double underscore, which is not allowed * in IL and ST. @@ -160,6 +160,9 @@ #define FB_FUNCTION_PARAM "data__" +#define SFC_STEP_ACTION_PREFIX "__SFC_" + + /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ @@ -521,7 +524,7 @@ s4o.print(s4o.indent_spaces + "// FB private variables - TEMP, private and located variables\n"); vardecl = new generate_cc_vardecl_c(&s4o, generate_cc_vardecl_c::local_vf, - generate_cc_vardecl_c::temp_vt | + generate_cc_vardecl_c::temp_vt | generate_cc_vardecl_c::private_vt | generate_cc_vardecl_c::located_vt); vardecl->print(symbol->var_declarations); @@ -627,12 +630,11 @@ generate_cc_vardecl_c::external_vt); vardecl->print(symbol->var_declarations); delete vardecl; + /* (A.4) Generate private internal variables for SFC */ + generate_cc_sfctables_c generate_cc_sfctables(&s4o); + symbol->function_block_body->accept(generate_cc_sfctables); s4o.print("\n"); - /* (A.4) Generate private internal variables for SFC*/ - generate_cc_sfcdecl_c generate_cc_sfcdecl(&s4o); - symbol->function_block_body->accept(generate_cc_sfcdecl); - /* (A.5) Program data structure type name. */ s4o.indent_left(); s4o.print("} "); @@ -640,7 +642,11 @@ s4o.print(";\n\n"); /* (B) Function with PROGRAM body */ - /* (B.1) Function declaration */ + /* (B.1) Step and Action definitions */ + generate_cc_sfcdecl_c generate_cc_sfcdecl(&s4o); + symbol->function_block_body->accept(generate_cc_sfcdecl); + + /* (B.2) Function declaration */ s4o.print("// Code part\n"); /* function interface */ s4o.print("void "); @@ -654,7 +660,7 @@ s4o.print(") {\n"); s4o.indent_right(); - /* (B.2) Initialize TEMP variables */ + /* (B.3) Initialize TEMP variables */ /* function body */ s4o.print(s4o.indent_spaces + "// Initialise TEMP variables\n"); vardecl = new generate_cc_vardecl_c(&s4o, @@ -664,7 +670,7 @@ delete vardecl; s4o.print("\n"); - /* (B.3) Function code */ + /* (B.4) Function code */ generate_cc_SFC_IL_ST_c generate_cc_code(&s4o, symbol, FB_FUNCTION_PARAM"->"); symbol->function_block_body->accept(generate_cc_code); s4o.indent_left(); @@ -673,6 +679,10 @@ s4o.print(FB_FUNCTION_SUFFIX); s4o.print(s4o.indent_spaces + "() \n\n"); + /* (B.5) Step and Action undefinitions */ + generate_cc_sfcundecl_c generate_cc_sfcundecl(&s4o); + symbol->function_block_body->accept(generate_cc_sfcundecl); + s4o.indent_left(); s4o.print("\n\n\n\n"); diff -r 38754701ac41 -r e6af5eb5f546 stage4/generate_cc/generate_cc_sfc.cc --- a/stage4/generate_cc/generate_cc_sfc.cc Fri Feb 23 19:19:23 2007 +0100 +++ b/stage4/generate_cc/generate_cc_sfc.cc Tue Feb 27 17:24:10 2007 +0100 @@ -41,6 +41,9 @@ class generate_cc_sfc_transitiontest_c: public generate_cc_base_c { private: + char transition_number; + + private: generate_cc_il_c *generate_cc_il; generate_cc_st_c *generate_cc_st; @@ -57,83 +60,21 @@ delete generate_cc_st; } + void reset_transition_number(void) {transition_number = 0;} + void print_transition_number(void) { + char str[10]; + sprintf(str, "%d", transition_number); + s4o.print(str); + } + void print_step_argument(symbol_c *step_name, const char* argument) { print_variable_prefix(); s4o.print("step_list["); + s4o.print(SFC_STEP_ACTION_PREFIX); step_name->accept(*this); s4o.print("]."); s4o.print(argument); } - - void print_reset_step(symbol_c *step_name) { - s4o.print(s4o.indent_spaces); - print_step_argument(step_name, "state"); - s4o.print(" = 0;\n" + s4o.indent_spaces + "if ("); - print_step_argument(step_name, "pulse"); - s4o.print(" != 1 {\n"); - s4o.indent_right(); - s4o.print(s4o.indent_spaces); - print_step_argument(step_name, "pulse"); - s4o.print(" = 2;\n"); - s4o.indent_left(); - s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n"); - s4o.indent_right(); - s4o.print(s4o.indent_spaces); - print_step_argument(step_name, "pulse"); - s4o.print(" = 0;\n"); - s4o.indent_left(); - s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces); - print_step_argument(step_name, "elapsed_time"); - s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);"); - } - - void print_set_step(symbol_c *step_name) { - s4o.print(s4o.indent_spaces); - print_step_argument(step_name, "state"); - s4o.print(" = 1;\n" + s4o.indent_spaces); - print_step_argument(step_name, "pulse"); - s4o.print(" = 1;"); - } - - void print_steps_state_test(steps_c *symbol) { - if (symbol->step_name != NULL) { - print_step_argument(symbol->step_name, "state"); - } - if (symbol->step_name_list != NULL) { - for(int i = 0; i < ((list_c*)symbol->step_name_list)->n; i++) { - print_step_argument(((list_c*)symbol->step_name_list)->elements[i], "state"); - if (i < ((list_c*)symbol->step_name_list)->n - 1) { - s4o.print(" && "); - } - } - } - } - - void print_reset_steps(steps_c *symbol) { - if (symbol->step_name != NULL) { - print_reset_step(symbol->step_name); - s4o.print("\n"); - } - if (symbol->step_name_list != NULL) { - for(int i = 0; i < ((list_c*)symbol->step_name_list)->n; i++) { - print_reset_step(((list_c*)symbol->step_name_list)->elements[i]); - s4o.print("\n"); - } - } - } - - void print_set_steps(steps_c *symbol) { - if (symbol->step_name != NULL) { - print_set_step(symbol->step_name); - s4o.print("\n"); - } - if (symbol->step_name_list != NULL) { - for(int i = 0; i < ((list_c*)symbol->step_name_list)->n; i++) { - print_set_step(((list_c*)symbol->step_name_list)->elements[i]); - s4o.print("\n"); - } - } - } /*********************************************/ /* B.1.6 Sequential function chart elements */ @@ -145,7 +86,7 @@ void *visit(transition_c *symbol) { s4o.print(s4o.indent_spaces + "if ("); - print_steps_state_test((steps_c *)symbol->from_steps); + symbol->from_steps->accept(*this); s4o.print(") {\n"); s4o.indent_right(); @@ -154,24 +95,53 @@ generate_cc_il->declare_backup_variable(); s4o.print(s4o.indent_spaces); symbol->transition_condition_il->accept(*generate_cc_il); - s4o.print("if ("); + print_variable_prefix(); + s4o.print("transition_list["); + print_transition_number(); + s4o.print("] = "); generate_cc_il->print_backup_variable(); - s4o.print(") {\n"); + s4o.print(";\n"); } if (symbol->transition_condition_st != NULL) { - s4o.print(s4o.indent_spaces + "if ("); + print_variable_prefix(); + s4o.print("transition_list["); + print_transition_number(); + s4o.print("] = "); symbol->transition_condition_st->accept(*generate_cc_st); - s4o.print(") {\n"); - } - - s4o.indent_right(); - print_reset_steps((steps_c *)symbol->from_steps); - print_set_steps((steps_c *)symbol->to_steps); - s4o.indent_left(); - - s4o.print(s4o.indent_spaces + "}\n"); - s4o.indent_left(); - s4o.print(s4o.indent_spaces + "}\n\n"); + s4o.print(";\n"); + } + s4o.indent_left(); + s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n"); + s4o.indent_right(); + s4o.print(s4o.indent_spaces); + print_variable_prefix(); + s4o.print("transition_list["); + print_transition_number(); + s4o.print("] = 0;\n"); + s4o.indent_left(); + s4o.print(s4o.indent_spaces + "}\n"); + + transition_number++; + return NULL; + } + + void *visit(steps_c *symbol) { + if (symbol->step_name != NULL) { + print_step_argument(symbol->step_name, "state"); + } + if (symbol->step_name_list != NULL) { + symbol->step_name_list->accept(*this); + } + return NULL; + } + + void *visit(step_name_list_c *symbol) { + for(int i = 0; i < symbol->n; i++) { + print_step_argument(symbol->elements[i], "state"); + if (i < symbol->n - 1) { + s4o.print(" && "); + } + } return NULL; } @@ -187,6 +157,176 @@ /***********************************************************************/ /***********************************************************************/ +class generate_cc_sfc_transitionresetsteps_c: public generate_cc_base_c { + + private: + char transition_number; + + public: + generate_cc_sfc_transitionresetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) + : generate_cc_base_c(s4o_ptr) { + this->set_variable_prefix(variable_prefix); + } + + void reset_transition_number(void) {transition_number = 0;} + void print_transition_number(void) { + char str[10]; + sprintf(str, "%d", transition_number); + s4o.print(str); + } + + void print_step_argument(symbol_c *step_name, const char* argument) { + print_variable_prefix(); + s4o.print("step_list["); + s4o.print(SFC_STEP_ACTION_PREFIX); + step_name->accept(*this); + s4o.print("]."); + s4o.print(argument); + } + + void print_reset_step(symbol_c *step_name) { + s4o.print(s4o.indent_spaces); + print_step_argument(step_name, "state"); + s4o.print(" = 0;\n" + s4o.indent_spaces); + print_step_argument(step_name, "elapsed_time"); + s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); + } + +/*********************************************/ +/* B.1.6 Sequential function chart elements */ +/*********************************************/ + + void *visit(initial_step_c *symbol) {return NULL;} + + void *visit(step_c *symbol) {return NULL;} + + void *visit(transition_c *symbol) { + s4o.print(s4o.indent_spaces + "if ("); + print_variable_prefix(); + s4o.print("transition_list["); + print_transition_number(); + s4o.print("]) {\n"); + s4o.indent_right(); + symbol->from_steps->accept(*this); + s4o.indent_left(); + s4o.print(s4o.indent_spaces + "}\n"); + transition_number++; + return NULL; + } + + void *visit(steps_c *symbol) { + if (symbol->step_name != NULL) { + print_reset_step(symbol->step_name); + } + if (symbol->step_name_list != NULL) { + symbol->step_name_list->accept(*this); + } + return NULL; + } + + void *visit(step_name_list_c *symbol) { + for(int i = 0; i < symbol->n; i++) { + print_reset_step(symbol->elements[i]); + } + return NULL; + } + + void *visit(action_c *symbol) {return NULL;} + +}; /* generate_cc_sfc_transitionresetsteps_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfc_transitionsetsteps_c: public generate_cc_base_c { + + private: + char transition_number; + + public: + generate_cc_sfc_transitionsetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) + : generate_cc_base_c(s4o_ptr) { + this->set_variable_prefix(variable_prefix); + } + + void reset_transition_number(void) {transition_number = 0;} + void print_transition_number(void) { + char str[10]; + sprintf(str, "%d", transition_number); + s4o.print(str); + } + + void print_step_argument(symbol_c *step_name, const char* argument) { + print_variable_prefix(); + s4o.print("step_list["); + s4o.print(SFC_STEP_ACTION_PREFIX); + step_name->accept(*this); + s4o.print("]."); + s4o.print(argument); + } + + void print_set_step(symbol_c *step_name) { + s4o.print(s4o.indent_spaces); + print_step_argument(step_name, "state"); + s4o.print(" = 1;\n"); + } + +/*********************************************/ +/* B.1.6 Sequential function chart elements */ +/*********************************************/ + + void *visit(initial_step_c *symbol) {return NULL;} + + void *visit(step_c *symbol) {return NULL;} + + void *visit(transition_c *symbol) { + s4o.print(s4o.indent_spaces + "if ("); + print_variable_prefix(); + s4o.print("transition_list["); + print_transition_number(); + s4o.print("]) {\n"); + s4o.indent_right(); + symbol->to_steps->accept(*this); + s4o.indent_left(); + s4o.print(s4o.indent_spaces + "}\n"); + transition_number++; + return NULL; + } + + void *visit(steps_c *symbol) { + if (symbol->step_name != NULL) { + print_set_step(symbol->step_name); + } + if (symbol->step_name_list != NULL) { + symbol->step_name_list->accept(*this); + } + return NULL; + } + + void *visit(step_name_list_c *symbol) { + for(int i = 0; i < symbol->n; i++) { + print_set_step(symbol->elements[i]); + } + return NULL; + } + + void *visit(action_c *symbol) {return NULL;} + +}; /* generate_cc_sfc_transitionsetsteps_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + class generate_cc_sfc_stepassociation_c: public generate_cc_base_c { private: @@ -202,6 +342,7 @@ void print_step_argument(symbol_c *step_name, const char* argument) { print_variable_prefix(); s4o.print("step_list["); + s4o.print(SFC_STEP_ACTION_PREFIX); step_name->accept(*this); s4o.print("]."); s4o.print(argument); @@ -210,6 +351,7 @@ void print_action_argument(symbol_c *action_name, const char* argument) { print_variable_prefix(); s4o.print("action_list["); + s4o.print(SFC_STEP_ACTION_PREFIX); action_name->accept(*this); s4o.print("]."); s4o.print(argument); @@ -220,20 +362,58 @@ /*********************************************/ void *visit(initial_step_c *symbol) { - s4o.print(s4o.indent_spaces + "// "); - symbol->step_name->accept(*this); - s4o.print(" action associations\n"); - current_step = symbol->step_name; - symbol->action_association_list->accept(*this); + if (((list_c*)symbol->action_association_list)->n > 0) { + s4o.print(s4o.indent_spaces + "// "); + symbol->step_name->accept(*this); + s4o.print(" action associations\n"); + current_step = symbol->step_name; + s4o.print(s4o.indent_spaces + "{\n"); + s4o.indent_right(); + s4o.print(s4o.indent_spaces + "char activated = "); + print_step_argument(current_step, "state"); + s4o.print(" && !"); + print_step_argument(current_step, "prev_state"); + s4o.print(";\n"); + s4o.print(s4o.indent_spaces + "char desactivated = !"); + print_step_argument(current_step, "state"); + s4o.print(" && "); + print_step_argument(current_step, "prev_state"); + s4o.print(";\n"); + s4o.print(s4o.indent_spaces + "char active = "); + print_step_argument(current_step, "state"); + s4o.print(";\n"); + symbol->action_association_list->accept(*this); + s4o.indent_left(); + s4o.print(s4o.indent_spaces + "}\n\n"); + } return NULL; } void *visit(step_c *symbol) { - s4o.print(s4o.indent_spaces + "// "); - symbol->step_name->accept(*this); - s4o.print(" action associations\n"); - current_step = symbol->step_name; - symbol->action_association_list->accept(*this); + if (((list_c*)symbol->action_association_list)->n > 0) { + s4o.print(s4o.indent_spaces + "// "); + symbol->step_name->accept(*this); + s4o.print(" action associations\n"); + current_step = symbol->step_name; + s4o.print(s4o.indent_spaces + "{\n"); + s4o.indent_right(); + s4o.print(s4o.indent_spaces + "char activated = "); + print_step_argument(current_step, "state"); + s4o.print(" && !"); + print_step_argument(current_step, "prev_state"); + s4o.print(";\n"); + s4o.print(s4o.indent_spaces + "char desactivated = !"); + print_step_argument(current_step, "state"); + s4o.print(" && "); + print_step_argument(current_step, "prev_state"); + s4o.print(";\n"); + s4o.print(s4o.indent_spaces + "char active = "); + print_step_argument(current_step, "state"); + s4o.print(";\n"); + symbol->action_association_list->accept(*this); + s4o.indent_left(); + s4o.print(s4o.indent_spaces + "}\n\n"); + } return NULL; } @@ -242,7 +422,7 @@ void *visit(action_c *symbol) {return NULL;} void *visit(action_association_list_c* symbol) { - print_list(symbol, "", "\n", "\n\n"); + print_list(symbol, "", "\n", "\n"); return NULL; } @@ -270,16 +450,14 @@ s4o.print(s4o.indent_spaces + "if ("); if (strcmp(qualifier, "N") == 0) { - print_step_argument(current_step, "state"); + s4o.print("active"); } if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0) { - print_step_argument(current_step, "pulse"); - s4o.print(" == 1"); + s4o.print("activated"); } if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { - print_step_argument(current_step, "state"); - s4o.print(" && "); + s4o.print("active && "); print_step_argument(current_step, "elapsed_time"); if (strcmp(qualifier, "D") == 0) { s4o.print(" >= "); @@ -312,8 +490,7 @@ s4o.indent_left(); s4o.print(s4o.indent_spaces + "}"); if (strcmp(qualifier, "DS") == 0) { - print_step_argument(current_step, "pulse"); - s4o.print(" == 2) {\n"); + s4o.print("desactivated"); s4o.indent_right(); s4o.print(s4o.indent_spaces); print_action_argument(current_action, "set_remaining_time"); @@ -370,6 +547,7 @@ s4o.print(s4o.indent_spaces + "if("); print_variable_prefix(); s4o.print("action_list["); + s4o.print(SFC_STEP_ACTION_PREFIX); symbol->action_name->accept(*this); s4o.print("].state) {"); s4o.indent_right(); @@ -395,6 +573,8 @@ private: generate_cc_sfc_transitiontest_c *generate_cc_sfc_transitiontest; + generate_cc_sfc_transitionresetsteps_c *generate_cc_sfc_transitionresetsteps; + generate_cc_sfc_transitionsetsteps_c *generate_cc_sfc_transitionsetsteps; generate_cc_sfc_stepassociation_c *generate_cc_sfc_stepassociation; generate_cc_sfc_actionexecution_c *generate_cc_sfc_actionexecution; @@ -402,6 +582,8 @@ generate_cc_sfc_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) : generate_cc_typedecl_c(s4o_ptr) { generate_cc_sfc_transitiontest = new generate_cc_sfc_transitiontest_c(s4o_ptr, scope, variable_prefix); + generate_cc_sfc_transitionresetsteps = new generate_cc_sfc_transitionresetsteps_c(s4o_ptr, scope, variable_prefix); + generate_cc_sfc_transitionsetsteps = new generate_cc_sfc_transitionsetsteps_c(s4o_ptr, scope, variable_prefix); generate_cc_sfc_stepassociation = new generate_cc_sfc_stepassociation_c(s4o_ptr, scope, variable_prefix); generate_cc_sfc_actionexecution = new generate_cc_sfc_actionexecution_c(s4o_ptr, scope, variable_prefix); this->set_variable_prefix(variable_prefix); @@ -409,6 +591,8 @@ virtual ~generate_cc_sfc_c(void) { delete generate_cc_sfc_transitiontest; + delete generate_cc_sfc_transitionresetsteps; + delete generate_cc_sfc_transitionsetsteps; delete generate_cc_sfc_stepassociation; delete generate_cc_sfc_actionexecution; } @@ -429,7 +613,9 @@ s4o.indent_right(); s4o.print(s4o.indent_spaces); print_variable_prefix(); - s4o.print("step_list[i].pulse = 0;\n"); + s4o.print("step_list[i].prev_state = "); + print_variable_prefix(); + s4o.print("step_list[i].state;\n"); s4o.print(s4o.indent_spaces + "if ("); print_variable_prefix(); s4o.print("step_list[i].state) {\n"); @@ -510,9 +696,22 @@ /* generate transition tests */ s4o.print(s4o.indent_spaces + "// Transitions fire test\n"); + generate_cc_sfc_transitiontest->reset_transition_number(); symbol->accept(*generate_cc_sfc_transitiontest); s4o.print("\n"); + /* generate transition reset steps */ + s4o.print(s4o.indent_spaces + "// Transitions reset steps\n"); + generate_cc_sfc_transitionresetsteps->reset_transition_number(); + symbol->accept(*generate_cc_sfc_transitionresetsteps); + s4o.print("\n"); + + /* generate transition set steps */ + s4o.print(s4o.indent_spaces + "// Transitions set steps\n"); + generate_cc_sfc_transitionsetsteps->reset_transition_number(); + symbol->accept(*generate_cc_sfc_transitionsetsteps); + s4o.print("\n"); + /* generate step association */ s4o.print(s4o.indent_spaces + "// Steps association\n"); symbol->accept(*generate_cc_sfc_stepassociation); diff -r 38754701ac41 -r e6af5eb5f546 stage4/generate_cc/generate_cc_sfcdecl.cc --- a/stage4/generate_cc/generate_cc_sfcdecl.cc Fri Feb 23 19:19:23 2007 +0100 +++ b/stage4/generate_cc/generate_cc_sfcdecl.cc Tue Feb 27 17:24:10 2007 +0100 @@ -39,45 +39,40 @@ /***********************************************************************/ /***********************************************************************/ -class generate_cc_sfc_stepdecl_c: public generate_cc_base_c { +class generate_cc_sfc_steptable_c: public generate_cc_base_c { private: char step_number; public: - generate_cc_sfc_stepdecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_stepdecl_c(void) {} + generate_cc_sfc_steptable_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} + ~generate_cc_sfc_steptable_c(void) {} void reset_step_number(void) {step_number = 0;} - char get_step_number(void) {return step_number;} - void increment_step_number(void) {step_number++;} void print_step_number(void) { char str[10]; sprintf(str, "%d", step_number); s4o.print(str); } - /*********************************************/ /* B.1.6 Sequential function chart elements */ /*********************************************/ void *visit(initial_step_c *symbol) { - s4o.print("#define "); - symbol->step_name->accept(*this); - s4o.print(" "); - print_step_number(); - s4o.print("\n"); - increment_step_number(); + if (step_number > 0) { + s4o.print(",\n"); + } + s4o.print(s4o.indent_spaces + "{1, 0, 0}"); + step_number++; return NULL; } void *visit(step_c *symbol) { - s4o.print("#define "); - symbol->step_name->accept(*this); - s4o.print(" "); - print_step_number(); - s4o.print("\n"); - increment_step_number(); + if (step_number > 0) { + s4o.print(",\n"); + } + s4o.print(s4o.indent_spaces + "{0, 0, 0}"); + step_number++; return NULL; } @@ -85,34 +80,31 @@ void *visit(action_c *symbol) {return NULL;} -}; /* generate_cc_sfc_stepdecl_c */ - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfc_actiondecl_c: public generate_cc_base_c { +}; /* generate_cc_sfc_steptable_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfc_actiontable_c: public generate_cc_base_c { private: char action_number; public: - generate_cc_sfc_actiondecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_actiondecl_c(void) {} + generate_cc_sfc_actiontable_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} + ~generate_cc_sfc_actiontable_c(void) {} void reset_action_number(void) {action_number = 0;} - char get_action_number(void) {return action_number;} - void increment_action_number(void) {action_number++;} void print_action_number(void) { char str[10]; sprintf(str, "%d", action_number); s4o.print(str); } - /*********************************************/ /* B.1.6 Sequential function chart elements */ /*********************************************/ @@ -124,95 +116,116 @@ void *visit(transition_c *symbol) {return NULL;} void *visit(action_c *symbol) { - s4o.print("#define "); - symbol->action_name->accept(*this); - s4o.print(" "); - print_action_number(); - s4o.print("\n"); - increment_action_number(); - return NULL; - } - -}; /* generate_cc_sfc_actiondecl_c */ - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfcdecl_c: public iterator_visitor_c { + if (action_number > 0) { + s4o.print(",\n"); + } + s4o.print(s4o.indent_spaces + "{0, 0, 0, 0, 0, 0}"); + action_number++; + return NULL; + } + +}; /* generate_cc_sfc_actiontable_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfc_transitiontable_c: public generate_cc_base_c { + + private: + char transition_number; + + public: + generate_cc_sfc_transitiontable_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} + ~generate_cc_sfc_transitiontable_c(void) {} + + void reset_transition_number(void) {transition_number = 0;} + void print_transition_number(void) { + char str[10]; + sprintf(str, "%d", transition_number); + s4o.print(str); + } +/*********************************************/ +/* B.1.6 Sequential function chart elements */ +/*********************************************/ + + void *visit(initial_step_c *symbol) {return NULL;} + + void *visit(step_c *symbol) {return NULL;} + + void *visit(transition_c *symbol) {return NULL;} + + void *visit(action_c *symbol) { + transition_number++; + return NULL; + } + +}; /* generate_cc_sfc_steptable_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfctables_c: public iterator_visitor_c { protected: stage4out_c &s4o; private: - generate_cc_sfc_stepdecl_c *generate_cc_sfc_stepdecl; - generate_cc_sfc_actiondecl_c *generate_cc_sfc_actiondecl; - - public: - generate_cc_sfcdecl_c(stage4out_c *s4o_ptr) : s4o(*s4o_ptr) { - generate_cc_sfc_stepdecl = new generate_cc_sfc_stepdecl_c(s4o_ptr); - generate_cc_sfc_actiondecl = new generate_cc_sfc_actiondecl_c(s4o_ptr); - } - - virtual ~generate_cc_sfcdecl_c(void) { - delete generate_cc_sfc_stepdecl; - delete generate_cc_sfc_actiondecl; - } - - public: - -/*********************************************/ -/* B.1.6 Sequential function chart elements */ -/*********************************************/ - - /*| sequential_function_chart sfc_network*/ - void *visit(sfc_network_c *symbol) { - char i; - - /* generate step number definitions */ - s4o.print(s4o.indent_spaces + "// Steps declaration\n"); - generate_cc_sfc_stepdecl->reset_step_number(); - symbol->accept(*generate_cc_sfc_stepdecl); - s4o.print("\n" + s4o.indent_spaces + "nb_steps = "); - generate_cc_sfc_stepdecl->print_step_number(); - s4o.print(";\n" + s4o.indent_spaces + "STEP step_list["); - generate_cc_sfc_stepdecl->print_step_number(); - s4o.print("] = {\n"); + generate_cc_sfc_steptable_c *generate_cc_sfc_steptable; + generate_cc_sfc_actiontable_c *generate_cc_sfc_actiontable; + generate_cc_sfc_transitiontable_c *generate_cc_sfc_transitiontable; + + public: + generate_cc_sfctables_c(stage4out_c *s4o_ptr) : s4o(*s4o_ptr) { + generate_cc_sfc_steptable = new generate_cc_sfc_steptable_c(s4o_ptr); + generate_cc_sfc_actiontable = new generate_cc_sfc_actiontable_c(s4o_ptr); + generate_cc_sfc_transitiontable = new generate_cc_sfc_transitiontable_c(s4o_ptr); + } + + virtual ~generate_cc_sfctables_c(void) { + delete generate_cc_sfc_steptable; + delete generate_cc_sfc_actiontable; + delete generate_cc_sfc_transitiontable; + } + + public: + + /* generate steps and actions tables */ + void *visit(sequential_function_chart_c *symbol) { + /* generate steps table */ + generate_cc_sfc_steptable->reset_step_number(); + s4o.print(s4o.indent_spaces + "STEP step_list[] = {\n"); s4o.indent_right(); - for (i = 0; i < generate_cc_sfc_stepdecl->get_step_number(); i++) { - if (i == 0) { - s4o.print(s4o.indent_spaces + "{1, 0, 0}"); - } - else { - s4o.print(",\n" + s4o.indent_spaces + "{0, 0, 0}"); - } - } - s4o.indent_left(); - s4o.print("\n" + s4o.indent_spaces + "};\n\n"); - - /* generate action number definitions */ - s4o.print(s4o.indent_spaces + "// Actions declaration\n"); - generate_cc_sfc_actiondecl->reset_action_number(); - symbol->accept(*generate_cc_sfc_actiondecl); - s4o.print("\n" + s4o.indent_spaces + "nb_actions = "); - generate_cc_sfc_actiondecl->print_action_number(); - s4o.print(";\n" + s4o.indent_spaces + "STEP step_list["); - generate_cc_sfc_actiondecl->print_action_number(); - s4o.print("] = {\n"); + symbol->accept(*generate_cc_sfc_steptable); + s4o.indent_left(); + s4o.print("\n" + s4o.indent_spaces + "};\n" + s4o.indent_spaces + "nb_steps = "); + generate_cc_sfc_steptable->print_step_number(); + s4o.print(";\n"); + + /* generate actions table */ + generate_cc_sfc_actiontable->reset_action_number(); + s4o.print(s4o.indent_spaces + "ACTION action_list[] = {\n"); s4o.indent_right(); - for (i = 0; i < generate_cc_sfc_actiondecl->get_action_number(); i++) { - if (i == 0) { - s4o.print(s4o.indent_spaces + "{0, 0, 0, 0, 0, 0}"); - } - else { - s4o.print(",\n" + s4o.indent_spaces + "{0, 0, 0, 0, 0, 0}"); - } - } - s4o.indent_left(); - s4o.print("\n" + s4o.indent_spaces + "};\n\n"); + symbol->accept(*generate_cc_sfc_actiontable); + s4o.indent_left(); + s4o.print("\n" + s4o.indent_spaces + "};\n" + s4o.indent_spaces + "nb_actions = "); + generate_cc_sfc_actiontable->print_action_number(); + s4o.print(";\n"); + + /* generate actions table */ + generate_cc_sfc_transitiontable->reset_transition_number(); + s4o.print(s4o.indent_spaces + "char transition_list["); + generate_cc_sfc_transitiontable->print_transition_number(); + s4o.print("];\n"); return NULL; } @@ -229,7 +242,314 @@ /********************/ /* B 3.2 Statements */ /********************/ -void *visit(statement_list_c *symbol) {return NULL;} + void *visit(statement_list_c *symbol) {return NULL;} /* Remainder implemented in generate_cc_sfcdecl_c... */ }; + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfc_stepdecl_c: public generate_cc_base_c { + + private: + char step_number; + + public: + generate_cc_sfc_stepdecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} + ~generate_cc_sfc_stepdecl_c(void) {} + + void reset_step_number(void) {step_number = 0;} + void print_step_number(void) { + char str[10]; + sprintf(str, "%d", step_number); + s4o.print(str); + } + +/*********************************************/ +/* B.1.6 Sequential function chart elements */ +/*********************************************/ + + void *visit(initial_step_c *symbol) { + s4o.print("#define "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->step_name->accept(*this); + s4o.print(" "); + print_step_number(); + s4o.print("\n"); + step_number++; + return NULL; + } + + void *visit(step_c *symbol) { + s4o.print("#define "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->step_name->accept(*this); + s4o.print(" "); + print_step_number(); + s4o.print("\n"); + step_number++; + return NULL; + } + + void *visit(transition_c *symbol) {return NULL;} + + void *visit(action_c *symbol) {return NULL;} + +}; /* generate_cc_sfc_stepdecl_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfc_actiondecl_c: public generate_cc_base_c { + + private: + char action_number; + + public: + generate_cc_sfc_actiondecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} + ~generate_cc_sfc_actiondecl_c(void) {} + + void reset_action_number(void) {action_number = 0;} + void print_action_number(void) { + char str[10]; + sprintf(str, "%d", action_number); + s4o.print(str); + } + +/*********************************************/ +/* B.1.6 Sequential function chart elements */ +/*********************************************/ + + void *visit(initial_step_c *symbol) {return NULL;} + + void *visit(step_c *symbol) {return NULL;} + + void *visit(transition_c *symbol) {return NULL;} + + void *visit(action_c *symbol) { + s4o.print("#define "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->action_name->accept(*this); + s4o.print(" "); + print_action_number(); + s4o.print("\n"); + action_number++; + return NULL; + } + +}; /* generate_cc_sfc_actiondecl_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfcdecl_c: public iterator_visitor_c { + + protected: + stage4out_c &s4o; + + private: + generate_cc_sfc_stepdecl_c *generate_cc_sfc_stepdecl; + generate_cc_sfc_actiondecl_c *generate_cc_sfc_actiondecl; + + public: + generate_cc_sfcdecl_c(stage4out_c *s4o_ptr) : s4o(*s4o_ptr) { + generate_cc_sfc_stepdecl = new generate_cc_sfc_stepdecl_c(s4o_ptr); + generate_cc_sfc_actiondecl = new generate_cc_sfc_actiondecl_c(s4o_ptr); + } + + virtual ~generate_cc_sfcdecl_c(void) { + delete generate_cc_sfc_stepdecl; + delete generate_cc_sfc_actiondecl; + } + + public: + + /* generate steps and actions tables */ + void *visit(sequential_function_chart_c *symbol) { + /* generate steps definitions */ + generate_cc_sfc_stepdecl->reset_step_number(); + s4o.print("// Steps definitions\n"); + symbol->accept(*generate_cc_sfc_stepdecl); + s4o.print("\n"); + + /* generate actions definitions */ + generate_cc_sfc_actiondecl->reset_action_number(); + s4o.print("// Actions definitions\n"); + symbol->accept(*generate_cc_sfc_actiondecl); + s4o.print("\n"); + + return NULL; + } + +/***********************************/ +/* B 2.1 Instructions and Operands */ +/***********************************/ +/*| instruction_list il_instruction */ + void *visit(instruction_list_c *symbol) {return NULL;} + +/***************************************/ +/* B.3 - Language ST (Structured Text) */ +/***************************************/ +/********************/ +/* B 3.2 Statements */ +/********************/ + void *visit(statement_list_c *symbol) {return NULL;} + +/* Remainder implemented in generate_cc_sfcdecl_c... */ +}; + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfc_stepundecl_c: public generate_cc_base_c { + + public: + generate_cc_sfc_stepundecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} + ~generate_cc_sfc_stepundecl_c(void) {} + +/*********************************************/ +/* B.1.6 Sequential function chart elements */ +/*********************************************/ + + void *visit(initial_step_c *symbol) { + s4o.print("#undef "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->step_name->accept(*this); + s4o.print("\n"); + return NULL; + } + + void *visit(step_c *symbol) { + s4o.print("#undef "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->step_name->accept(*this); + s4o.print("\n"); + return NULL; + } + + void *visit(transition_c *symbol) {return NULL;} + + void *visit(action_c *symbol) {return NULL;} + +}; /* generate_cc_sfc_stepdecl_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfc_actionundecl_c: public generate_cc_base_c { + + public: + generate_cc_sfc_actionundecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} + ~generate_cc_sfc_actionundecl_c(void) {} + +/*********************************************/ +/* B.1.6 Sequential function chart elements */ +/*********************************************/ + + void *visit(initial_step_c *symbol) {return NULL;} + + void *visit(step_c *symbol) {return NULL;} + + void *visit(transition_c *symbol) {return NULL;} + + void *visit(action_c *symbol) { + s4o.print("#undef "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->action_name->accept(*this); + s4o.print("\n"); + return NULL; + } + +}; /* generate_cc_sfc_stepdecl_c */ + + + + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +class generate_cc_sfcundecl_c: public iterator_visitor_c { + + protected: + stage4out_c &s4o; + + private: + generate_cc_sfc_stepundecl_c *generate_cc_sfc_stepundecl; + generate_cc_sfc_actionundecl_c *generate_cc_sfc_actionundecl; + + public: + generate_cc_sfcundecl_c(stage4out_c *s4o_ptr) : s4o(*s4o_ptr) { + generate_cc_sfc_stepundecl = new generate_cc_sfc_stepundecl_c(s4o_ptr); + generate_cc_sfc_actionundecl = new generate_cc_sfc_actionundecl_c(s4o_ptr); + } + + virtual ~generate_cc_sfcundecl_c(void) { + delete generate_cc_sfc_stepundecl; + delete generate_cc_sfc_actionundecl; + } + + public: + +/*********************************************/ +/* B.1.6 Sequential function chart elements */ +/*********************************************/ + + /* generate steps and actions tables */ + void *visit(sequential_function_chart_c *symbol) { + /* generate steps undefinitions */ + s4o.print("// Steps undefinitions\n"); + symbol->accept(*generate_cc_sfc_stepundecl); + s4o.print("\n"); + + /* generate actions table */ + s4o.print("// Actions undefinitions\n"); + symbol->accept(*generate_cc_sfc_actionundecl); + s4o.print("\n"); + + return NULL; + } + +/***********************************/ +/* B 2.1 Instructions and Operands */ +/***********************************/ +/*| instruction_list il_instruction */ + void *visit(instruction_list_c *symbol) {return NULL;} + +/***************************************/ +/* B.3 - Language ST (Structured Text) */ +/***************************************/ +/********************/ +/* B 3.2 Statements */ +/********************/ + void *visit(statement_list_c *symbol) {return NULL;} + +/* Remainder implemented in generate_cc_sfcdecl_c... */ +};