diff -r 0036357a990f -r 3a478229db8b stage4/generate_c/generate_c_sfcdecl.cc --- a/stage4/generate_c/generate_c_sfcdecl.cc Thu May 20 23:36:53 2010 +0200 +++ b/stage4/generate_c/generate_c_sfcdecl.cc Wed Jun 02 18:21:15 2010 +0200 @@ -31,8 +31,10 @@ * code. */ - - +typedef struct +{ + identifier_c *symbol; +} VARIABLE; /***********************************************************************/ /***********************************************************************/ @@ -55,25 +57,32 @@ } sfcdeclaration_t; private: - char step_number; - char action_number; - char transition_number; + int step_number; + int action_number; + int transition_number; + std::list variable_list; sfcdeclaration_t wanted_sfcdeclaration; + + search_var_instance_decl_c *search_var_instance_decl; public: - generate_c_sfcdecl_c(stage4out_c *s4o_ptr, sfcdeclaration_t sfcdeclaration) + generate_c_sfcdecl_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) : generate_c_typedecl_c(s4o_ptr) { - wanted_sfcdeclaration = sfcdeclaration; - } - ~generate_c_sfcdecl_c(void) {} - - void print(symbol_c *symbol, const char *variable_prefix = NULL) { this->set_variable_prefix(variable_prefix); - + search_var_instance_decl = new search_var_instance_decl_c(scope); + } + ~generate_c_sfcdecl_c(void) { + variable_list.clear(); + delete search_var_instance_decl; + } + + void generate(symbol_c *symbol, sfcdeclaration_t declaration_type) { + wanted_sfcdeclaration = declaration_type; + symbol->accept(*this); } - + /*********************************************/ /* B.1.6 Sequential function chart elements */ /*********************************************/ @@ -143,7 +152,7 @@ for(int i = 0; i < symbol->n; i++) symbol->elements[i]->accept(*this); - /* steps table count */ + /* actions table count */ wanted_sfcdeclaration = actioncount_sd; for(int i = 0; i < symbol->n; i++) symbol->elements[i]->accept(*this); @@ -192,6 +201,18 @@ break; case actiondef_sd: s4o.print("// Actions definitions\n"); + { + std::list::iterator pt; + for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { + s4o.print("#define "); + s4o.print(SFC_STEP_ACTION_PREFIX); + pt->symbol->accept(*this); + s4o.print(" "); + s4o.print_integer(action_number); + s4o.print("\n"); + action_number++; + } + } for(int i = 0; i < symbol->n; i++) symbol->elements[i]->accept(*this); s4o.print("\n"); @@ -204,6 +225,15 @@ break; case actionundef_sd: s4o.print("// Actions undefinitions\n"); + { + std::list::iterator pt; + for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { + s4o.print("#undef "); + s4o.print(SFC_STEP_ACTION_PREFIX); + pt->symbol->accept(*this); + s4o.print("\n"); + } + } for(int i = 0; i < symbol->n; i++) symbol->elements[i]->accept(*this); s4o.print("\n"); @@ -216,8 +246,12 @@ void *visit(initial_step_c *symbol) { switch (wanted_sfcdeclaration) { + case actioncount_sd: + symbol->action_association_list->accept(*this); + break; + case sfcdecl_sd: + symbol->action_association_list->accept(*this); case stepcount_sd: - case sfcdecl_sd: step_number++; break; case sfcinit_sd: @@ -253,8 +287,12 @@ void *visit(step_c *symbol) { switch (wanted_sfcdeclaration) { + case actioncount_sd: + symbol->action_association_list->accept(*this); + break; + case sfcdecl_sd: + symbol->action_association_list->accept(*this); case stepcount_sd: - case sfcdecl_sd: case sfcinit_sd: step_number++; break; @@ -279,6 +317,25 @@ return NULL; } + void *visit(action_association_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->action_name); + + if (var_decl != NULL) { + std::list::iterator pt; + for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { + if (!compare_identifiers(pt->symbol, symbol->action_name)) + return NULL; + } + VARIABLE *variable; + variable = new VARIABLE; + variable->symbol = (identifier_c*)(symbol->action_name); + variable_list.push_back(*variable); + action_number++; + } + return NULL; + } + void *visit(transition_c *symbol) { switch (wanted_sfcdeclaration) { case sfcdecl_sd: