Adding SET (S) and RESET(R) to action qualifier
authorlbessard
Mon, 27 Aug 2007 14:52:15 +0200
changeset 52 f44458d1fa29
parent 51 d44158420983
child 53 7f0cea717342
Adding SET (S) and RESET(R) to action qualifier
generate_cc_sfc rewritten for better code clarity
stage1_2/iec.y
stage4/generate_cc/generate_cc.cc
stage4/generate_cc/generate_cc_sfc.cc
stage4/generate_cc/generate_cc_sfcdecl.cc
--- a/stage1_2/iec.y	Mon Aug 13 18:03:06 2007 +0200
+++ b/stage1_2/iec.y	Mon Aug 27 14:52:15 2007 +0200
@@ -3716,8 +3716,8 @@
 /* NOTE: the following two clash with the R and S IL operators.
  * It will have to be handled when we include parsing of SFC...
  */
-| R_operator		{$$ = new qualifier_c(strdup("R"));}
-| S_operator		{$$ = new qualifier_c(strdup("S"));}
+| R		{$$ = new qualifier_c(strdup("R"));}
+| S		{$$ = new qualifier_c(strdup("S"));}
 | P		{$$ = new qualifier_c(strdup("P"));}
 ;
 
--- a/stage4/generate_cc/generate_cc.cc	Mon Aug 13 18:03:06 2007 +0200
+++ b/stage4/generate_cc/generate_cc.cc	Mon Aug 27 14:52:15 2007 +0200
@@ -788,7 +788,7 @@
   vardecl->print(symbol->var_declarations);
   delete vardecl;
   /* (A.4) Generate private internal variables for SFC */
-  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcdecl_sg);
+  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcdecl_sd);
   sfcdecl->print(symbol->function_block_body);
   delete sfcdecl;
   
@@ -826,7 +826,7 @@
   delete vardecl;
   s4o.print("\n");
   /* (B.3) Generate private internal variables for SFC */
-  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcinit_sg);
+  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcinit_sd);
   sfcdecl->print(symbol->function_block_body,FB_FUNCTION_PARAM"->");
   delete sfcdecl;
 
@@ -835,12 +835,12 @@
 
   /* (C) Function with PROGRAM body */
   /* (C.1) Step definitions */
-  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepdef_sg);
+  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepdef_sd);
   sfcdecl->print(symbol->function_block_body);
   delete sfcdecl;
   
   /* (C.2) Action definitions */
-  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actiondef_sg);
+  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actiondef_sd);
   sfcdecl->print(symbol->function_block_body);
   delete sfcdecl;
 
@@ -878,12 +878,12 @@
   s4o.print(s4o.indent_spaces + "() \n\n");
 
   /* (C.6) Step undefinitions */
-  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepundef_sg);
+  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepundef_sd);
   sfcdecl->print(symbol->function_block_body);
   delete sfcdecl;
   
   /* (C.7) Action undefinitions */
-  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actionundef_sg);
+  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actionundef_sd);
   sfcdecl->print(symbol->function_block_body);
   delete sfcdecl;
   
--- a/stage4/generate_cc/generate_cc_sfc.cc	Mon Aug 13 18:03:06 2007 +0200
+++ b/stage4/generate_cc/generate_cc_sfc.cc	Mon Aug 27 14:52:15 2007 +0200
@@ -31,6 +31,17 @@
  * code.
  */
 
+#include <list>
+
+typedef struct
+{
+  transition_c *symbol;
+  int priority;
+  int index;
+} TRANSITION;
+
+
+
 
 
 /***********************************************************************/
@@ -38,60 +49,66 @@
 /***********************************************************************/
 /***********************************************************************/
 
-class transition_element {
-  
-  private:
-    transition_c *transition;
-    char priority;
-    char index;
-    transition_element *prev;
-    transition_element *next;
-
-  public:
-    transition_element(transition_c *tr, char pr, char idx) {
-      prev = NULL;
-      next = NULL;
-      transition = tr;
-      priority = pr;
-      index = idx;
-    }
-
-    void set_prev(transition_element *tr) {prev = tr;}
-    void set_next(transition_element *tr) {next = tr;}
-    transition_element *get_prev(void) {return prev;}
-    transition_element *get_next(void) {return next;}
-    transition_c *get_transition(void) {return transition;}
-    char get_priority(void) {return priority;}
-    char get_index(void) {return index;}
-};
-
-
-
-
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-
-class generate_cc_sfc_transitionresetsteps_c: public generate_cc_base_c {
-  
-  private:
-    char transition_number;
+class generate_cc_sfc_elements_c: public generate_cc_base_c {
   
   public:
-    generate_cc_sfc_transitionresetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
+    typedef enum {
+      transitionlist_sg,
+      transitiontest_sg,
+      stepset_sg,
+      stepreset_sg,
+      actionassociation_sg,
+      actionbody_sg
+    } sfcgeneration_t;
+
+  private:
+    generate_cc_il_c *generate_cc_il;
+    generate_cc_st_c *generate_cc_st;
+    generate_cc_SFC_IL_ST_c *generate_cc_code;
+    
+    int transition_number;
+    std::list<TRANSITION> transition_list;
+    
+    symbol_c *current_step;
+    symbol_c *current_action;
+
+    sfcgeneration_t wanted_sfcgeneration;
+    
+  public:
+    generate_cc_sfc_elements_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
     : generate_cc_base_c(s4o_ptr) {
+      generate_cc_il = new generate_cc_il_c(s4o_ptr, scope, variable_prefix);
+      generate_cc_st = new generate_cc_st_c(s4o_ptr, scope, variable_prefix);
+      generate_cc_code = new generate_cc_SFC_IL_ST_c(s4o_ptr, scope, variable_prefix);
       this->set_variable_prefix(variable_prefix);
     }
     
-    void set_transition_number(char number) {transition_number = number;}
+    ~generate_cc_sfc_elements_c(void) {
+      delete generate_cc_il;
+      delete generate_cc_st;
+      delete generate_cc_code;
+    }
+
     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 generate(symbol_c *symbol, sfcgeneration_t generation_type) {
+      wanted_sfcgeneration = generation_type;
+      switch (wanted_sfcgeneration) {
+        case transitiontest_sg:
+          {
+            std::list<TRANSITION>::iterator pt;
+            for(pt = transition_list.begin(); pt != transition_list.end(); pt++) {
+              transition_number = pt->index;
+              pt->symbol->accept(*this);
+            }
+          }
+          break;
+        default:
+          symbol->accept(*this);
+          break;
+      }
+    }
+
     void print_step_argument(symbol_c *step_name, const char* argument) {
       print_variable_prefix();
       s4o.print("step_list[");
@@ -101,416 +118,6 @@
       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");
-    }
-
-/*********************************************/
-/* 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) {
-      if (symbol->integer == NULL) {
-        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" + 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->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_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;
-    generate_cc_sfc_transitionresetsteps_c *generate_cc_sfc_transitionresetsteps;
-    
-  public:
-    generate_cc_sfc_transitiontest_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
-    : generate_cc_base_c(s4o_ptr) {
-      generate_cc_il = new generate_cc_il_c(s4o_ptr, scope, variable_prefix);
-      generate_cc_st = new generate_cc_st_c(s4o_ptr, scope, variable_prefix);
-      generate_cc_sfc_transitionresetsteps = new generate_cc_sfc_transitionresetsteps_c(s4o_ptr, scope, variable_prefix);
-      this->set_variable_prefix(variable_prefix);
-    }
-    
-    ~generate_cc_sfc_transitiontest_c(void) {
-      delete generate_cc_il;
-      delete generate_cc_st;
-      delete generate_cc_sfc_transitionresetsteps;
-    }
-
-    void set_transition_number(char number) {transition_number = number;}
-    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");
-    }
-
-/*********************************************/
-/* B.1.6  Sequential function chart elements */
-/*********************************************/
-    
-    void *visit(transition_c *symbol) {
-      s4o.print(s4o.indent_spaces + "if (");
-      symbol->from_steps->accept(*this);
-      s4o.print(") {\n");
-      s4o.indent_right();
-      
-      // Calculate transition value
-      if (symbol->transition_condition_il != NULL) {
-        generate_cc_il->declare_backup_variable();
-        s4o.print(s4o.indent_spaces);
-        symbol->transition_condition_il->accept(*generate_cc_il);
-        print_variable_prefix();
-        s4o.print("transition_list[");
-        print_transition_number();
-        s4o.print("] = ");
-        generate_cc_il->print_backup_variable();
-        s4o.print(";\n");
-      }
-      if (symbol->transition_condition_st != NULL) {
-        s4o.print(s4o.indent_spaces);
-        print_variable_prefix();
-        s4o.print("transition_list[");
-        print_transition_number();
-        s4o.print("] = ");
-        symbol->transition_condition_st->accept(*generate_cc_st);
-        s4o.print(";\n");
-      }
-      if (symbol->integer != NULL) {
-        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(*generate_cc_sfc_transitionresetsteps);
-        s4o.indent_left();
-        s4o.print(s4o.indent_spaces + "}\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;
-    }
-
-}; /* generate_cc_sfc_transitiontest_c */
-
-
-
-
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-
-class generate_cc_sfc_transitionsort_c: public iterator_visitor_c {
-  
-  private:
-    char transition_number;
-    transition_element *first_transition;
-    transition_element *last_transition;
-  
-  private:
-    generate_cc_sfc_transitiontest_c *generate_cc_sfc_transitiontest;
-    
-  public:
-    generate_cc_sfc_transitionsort_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) {
-      generate_cc_sfc_transitiontest = new generate_cc_sfc_transitiontest_c(s4o_ptr, scope, variable_prefix);
-      first_transition = NULL;
-      last_transition = NULL;
-    }
-
-    ~generate_cc_sfc_transitionsort_c(void) {
-      delete generate_cc_sfc_transitiontest;
-    }
-    
-    void append_transition(transition_c *transition, char priority, char index) {
-      transition_element *new_transition = new transition_element(transition, priority, index);
-      new_transition->set_prev(last_transition);
-      if (last_transition != NULL) {
-        last_transition->set_next(new_transition);
-      }
-      else {
-        first_transition = new_transition;
-      }
-      last_transition = new_transition;
-      transition_number++;
-    }
-    
-    void sort_transitions(void) {
-      int i, j;
-      transition_element *current_transition;
-      transition_element *next_transition;
-      for (i = transition_number; i > 1; i--) {
-        current_transition = first_transition;
-        for (j = 0; j < i - 1; j++) {
-          next_transition = current_transition->get_next();
-          if (current_transition->get_priority() > next_transition->get_priority()) {
-            if (current_transition->get_prev() != NULL) {
-              current_transition->get_prev()->set_next(next_transition);
-            }
-            else {
-              first_transition = next_transition;
-            }
-            if (next_transition->get_next() != NULL) {
-              next_transition->get_next()->set_prev(current_transition);
-            }
-            else {
-              last_transition = current_transition;
-            }
-            current_transition->set_next(next_transition->get_next());
-            next_transition->set_prev(current_transition->get_prev());
-            current_transition->set_prev(next_transition);
-            next_transition->set_next(current_transition);
-          }
-          else {
-            current_transition = next_transition;
-          }
-        }
-      }
-    }
-    
-    void reset_transition_number(void) {transition_number = 0;}
-    
-    void generate(symbol_c *symbol) {
-      symbol->accept(*this);
-      sort_transitions();
-      transition_element *next_transition = first_transition;
-      while (next_transition != NULL) {
-        generate_cc_sfc_transitiontest->set_transition_number(next_transition->get_index());
-        next_transition->get_transition()->accept(*generate_cc_sfc_transitiontest);
-        next_transition = next_transition->get_next();
-      }
-    }
-
-/*********************************************/
-/* 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) {
-      if (symbol->integer != NULL) {
-        append_transition(symbol, atoi(((token_c *)symbol->integer)->value), transition_number);
-      }
-      else {
-        append_transition(symbol, 0, transition_number);
-      }
-      return NULL;
-    }
-    
-    void *visit(action_c *symbol) {return NULL;}
-
-};/* generate_cc_sfc_transitionsort_c */
-
-
-
-
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-
-class generate_cc_sfc_stepassociation_c: public generate_cc_base_c {
-  
-  private:
-    symbol_c *current_step;
-    symbol_c *current_action;
-  
-  public:
-    generate_cc_sfc_stepassociation_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 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_action_argument(symbol_c *action_name, const char* argument) {
       print_variable_prefix();
       s4o.print("action_list[");
@@ -518,146 +125,380 @@
       action_name->accept(*this);
       s4o.print("].");
       s4o.print(argument);
-    }
+    }      
+
+    void print_transition_number(void) {
+      char str[10];
+      sprintf(str, "%d", transition_number);
+      s4o.print(str);
+    }
+
+    void print_reset_step(symbol_c *step_name) {
+      s4o.print(s4o.indent_spaces);
+      print_step_argument(step_name, "state");
+      s4o.print(" = 0;\n");
+    }
+    
+    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, "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) {
-      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");
+      switch (wanted_sfcgeneration) {
+        case actionassociation_sg:
+          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");
+          }
+          break;
+        default:
+          break;
       }
       return NULL;
     }
     
     void *visit(step_c *symbol) {
-      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(transition_c *symbol) {return NULL;}
-    
-    void *visit(action_c *symbol) {return NULL;}
+      switch (wanted_sfcgeneration) {
+        case actionassociation_sg:
+          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");
+          }
+          break;
+        default:
+          break;
+      }
+      return NULL;
+    }
+
+    void *visit(transition_c *symbol) {
+      switch (wanted_sfcgeneration) {
+        case transitionlist_sg:
+          {
+            TRANSITION *transition;
+            transition = new TRANSITION;
+            transition->symbol = symbol;
+            transition->index = transition_number;
+            if (symbol->integer != NULL) {
+              transition->priority = atoi(((token_c *)symbol->integer)->value);
+              std::list<TRANSITION>::iterator pt = transition_list.begin();
+              while (pt != transition_list.end() && pt->priority > transition->priority) {
+                pt++;
+              } 
+              transition_list.insert(pt, *transition);
+            } 
+            else {
+              transition->priority = 0;
+              transition_list.push_back(*transition);
+            }
+            transition_number++;
+          }
+          break;
+        case transitiontest_sg:
+          s4o.print(s4o.indent_spaces + "if (");
+          symbol->from_steps->accept(*this);
+          s4o.print(") {\n");
+          s4o.indent_right();
+          
+          // Calculate transition value
+          if (symbol->transition_condition_il != NULL) {
+            generate_cc_il->declare_backup_variable();
+            s4o.print(s4o.indent_spaces);
+            symbol->transition_condition_il->accept(*generate_cc_il);
+            print_variable_prefix();
+            s4o.print("transition_list[");
+            print_transition_number();
+            s4o.print("] = ");
+            generate_cc_il->print_backup_variable();
+            s4o.print(";\n");
+          }
+          if (symbol->transition_condition_st != NULL) {
+            s4o.print(s4o.indent_spaces);
+            print_variable_prefix();
+            s4o.print("transition_list[");
+            print_transition_number();
+            s4o.print("] = ");
+            symbol->transition_condition_st->accept(*generate_cc_st);
+            s4o.print(";\n");
+          }
+          if (symbol->integer != NULL) {
+            s4o.print(s4o.indent_spaces + "if (");
+            print_variable_prefix();
+            s4o.print("transition_list[");
+            print_transition_number();
+            s4o.print("]) {\n");
+            s4o.indent_right();
+            wanted_sfcgeneration = stepreset_sg;
+            symbol->from_steps->accept(*this);
+            wanted_sfcgeneration = transitiontest_sg;
+            s4o.indent_left();
+            s4o.print(s4o.indent_spaces + "}\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");
+          break;
+        case stepset_sg:
+          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++;
+          break;
+        case stepreset_sg:
+          if (symbol->integer == NULL) {
+            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++;
+          break;
+        default:
+          break;
+      }
+      return NULL;
+    }
+    
+    void *visit(action_c *symbol) {
+      switch (wanted_sfcgeneration) {
+        case actionbody_sg:
+          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();
+          
+          // generate action code
+          symbol->function_block_body->accept(*generate_cc_code);
+          
+          s4o.indent_left();
+          s4o.print(s4o.indent_spaces + "}\n\n");
+          break;
+        default:
+          break;
+      }
+      return NULL;
+    }
+
+    void *visit(steps_c *symbol) {
+      if (symbol->step_name != NULL) {
+        switch (wanted_sfcgeneration) {
+          case transitiontest_sg:
+            print_step_argument(symbol->step_name, "state");
+            break;
+          case stepset_sg:
+            print_set_step(symbol->step_name);
+            break;
+          case stepreset_sg:
+            print_reset_step(symbol->step_name);
+            break;
+          default:
+            break;
+        }
+      }
+      else if (symbol->step_name_list != NULL) {
+        symbol->step_name_list->accept(*this);
+      }  
+      return NULL;
+    }
+    
+    void *visit(step_name_list_c *symbol) {
+      switch (wanted_sfcgeneration) {
+        case transitiontest_sg:
+          for(int i = 0; i < symbol->n; i++) {
+            print_step_argument(symbol->elements[i], "state");
+            if (i < symbol->n - 1) {
+              s4o.print(" && ");
+            }
+          }
+          break;
+        case stepset_sg:
+          for(int i = 0; i < symbol->n; i++) {
+            print_set_step(symbol->elements[i]);
+          }
+          break;
+        case stepreset_sg:
+          for(int i = 0; i < symbol->n; i++) {
+            print_reset_step(symbol->elements[i]);
+          }
+          break;
+        default:
+          break;
+      }
+      return NULL;
+    }
 
     void *visit(action_association_list_c* symbol) {
-      print_list(symbol, "", "\n", "\n");
+      switch (wanted_sfcgeneration) {
+        case actionassociation_sg:
+          print_list(symbol, "", "\n", "\n");
+          break;
+        default:
+          break;
+      }
       return NULL;
     }
 
     void *visit(action_association_c *symbol) {
-      if (symbol->action_qualifier != NULL) {
-        current_action = symbol->action_name;
-        symbol->action_qualifier->accept(*this);
-      }
-      else {
-        s4o.print(s4o.indent_spaces + "if (");
-        print_step_argument(current_step, "state");
-        s4o.print(") {\n");
-        s4o.indent_right();
-        s4o.print(s4o.indent_spaces);
-        print_action_argument(symbol->action_name, "state");
-        s4o.print(" = 1;\n");
-        s4o.indent_left();
-        s4o.print(s4o.indent_spaces + "}");
+      switch (wanted_sfcgeneration) {
+        case actionassociation_sg:
+          if (symbol->action_qualifier != NULL) {
+            current_action = symbol->action_name;
+            symbol->action_qualifier->accept(*this);
+          }
+          else {
+            s4o.print(s4o.indent_spaces + "if (");
+            print_step_argument(current_step, "state");
+            s4o.print(") {\n");
+            s4o.indent_right();
+            s4o.print(s4o.indent_spaces);
+            print_action_argument(symbol->action_name, "state");
+            s4o.print(" = 1;\n");
+            s4o.indent_left();
+            s4o.print(s4o.indent_spaces + "}");
+          }
+          break;
+        default:
+          break;
       }
       return NULL;
     }
 
     void *visit(action_qualifier_c *symbol) {
-      char *qualifier = (char *)symbol->action_qualifier->accept(*this);
-      
-      s4o.print(s4o.indent_spaces + "if (");
-      if (strcmp(qualifier, "N") == 0) {
-        s4o.print("active");
-      }
-      if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || 
-          strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0) {
-        s4o.print("activated");
-      }
-      if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) {
-        s4o.print("active && ");
-        print_step_argument(current_step, "elapsed_time");
-        if (strcmp(qualifier, "D") == 0) {
-          s4o.print(" >= ");
-        }
-        else {
-          s4o.print(" < ");
-        }
-        symbol->action_time->accept(*this);  
-      }
-      s4o.print(") {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 ||
-          strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) {
-        print_action_argument(current_action, "state");
-        s4o.print(" = 1;\n");  
-      }
-      if (strcmp(qualifier, "SD") == 0 || strcmp(qualifier, "DS") == 0 || 
-          strcmp(qualifier, "SL") == 0) {
-        if (strcmp(qualifier, "SL") == 0) {
-          print_action_argument(current_action, "reset_remaining_time");  
-        }
-        else {
-          print_action_argument(current_action, "set_remaining_time");
-        }
-        s4o.print(" = ");
-        symbol->action_time->accept(*this);
-        s4o.print(";\n");
-      }
-      s4o.indent_left();
-      s4o.print(s4o.indent_spaces + "}");
-      if (strcmp(qualifier, "DS") == 0) {
-        s4o.print("desactivated");
-        s4o.indent_right();
-        s4o.print(s4o.indent_spaces);
-        print_action_argument(current_action, "set_remaining_time");
-        s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
+      switch (wanted_sfcgeneration) {
+        case actionassociation_sg:
+          {
+            char *qualifier = (char *)symbol->action_qualifier->accept(*this);
+            s4o.print(s4o.indent_spaces + "if (");
+            if (strcmp(qualifier, "N") == 0) {
+              s4o.print("active");
+            }
+            if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || 
+                strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0 || 
+                strcmp(qualifier, "S") == 0 || strcmp(qualifier, "R") == 0) {
+              s4o.print("activated");
+            }
+            if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) {
+              s4o.print("active && ");
+              print_step_argument(current_step, "elapsed_time");
+              if (strcmp(qualifier, "D") == 0) {
+                s4o.print(" >= ");
+              }
+              else {
+                s4o.print(" < ");
+              }
+              symbol->action_time->accept(*this);  
+            }
+            s4o.print(") {\n");
+            s4o.indent_right();
+            s4o.print(s4o.indent_spaces);
+            if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 ||
+                strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) {
+              print_action_argument(current_action, "state");
+              s4o.print(" = 1;\n");  
+            }
+            if (strcmp(qualifier, "S") == 0) {
+              print_action_argument(current_action, "set");
+              s4o.print(" = 1;\n");
+            }
+            if (strcmp(qualifier, "R") == 0) {
+              print_action_argument(current_action, "reset");
+              s4o.print(" = 1;\n");
+            }
+            if (strcmp(qualifier, "SD") == 0 || strcmp(qualifier, "DS") == 0 || 
+                strcmp(qualifier, "SL") == 0) {
+              if (strcmp(qualifier, "SL") == 0) {
+                print_action_argument(current_action, "reset_remaining_time");  
+              }
+              else {
+                print_action_argument(current_action, "set_remaining_time");
+              }
+              s4o.print(" = ");
+              symbol->action_time->accept(*this);
+              s4o.print(";\n");
+            }
+            s4o.indent_left();
+            s4o.print(s4o.indent_spaces + "}");
+            if (strcmp(qualifier, "DS") == 0) {
+              s4o.print("desactivated");
+              s4o.indent_right();
+              s4o.print(s4o.indent_spaces);
+              print_action_argument(current_action, "set_remaining_time");
+              s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
+            }
+          }
+          break;
+        default:
+          break;
       }
       return NULL;
     }
@@ -671,59 +512,6 @@
     }
 
 }; /* generate_cc_sfc_actiondecl_c */
-
-
-
-
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-/***********************************************************************/
-
-class generate_cc_sfc_actionexecution_c: public generate_cc_base_c {
-  
-  private:
-    generate_cc_SFC_IL_ST_c *generate_cc_code;
-    
-  public:
-    generate_cc_sfc_actionexecution_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
-    : generate_cc_base_c(s4o_ptr) {
-      generate_cc_code = new generate_cc_SFC_IL_ST_c(s4o_ptr, scope, variable_prefix);
-      this->set_variable_prefix(variable_prefix);
-    }
-    
-    ~generate_cc_sfc_actionexecution_c(void) {
-      delete generate_cc_code;
-    }
-
-/*********************************************/
-/* 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(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();
-      
-      // generate action code
-      symbol->function_block_body->accept(*generate_cc_code);
-      
-      s4o.indent_left();
-      s4o.print(s4o.indent_spaces + "}\n\n");
-      return NULL;
-    }
-
-}; /* generate_cc_sfc_actiondecl_c */
  
  
  
@@ -735,29 +523,17 @@
 class generate_cc_sfc_c: public generate_cc_typedecl_c {
   
   private:
-    generate_cc_sfc_transitionsort_c *generate_cc_sfc_transitionsort;
-    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;
-  
+    generate_cc_sfc_elements_c *generate_cc_sfc_elements;
+    
   public:
     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_transitionsort = new generate_cc_sfc_transitionsort_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);
+      generate_cc_sfc_elements = new generate_cc_sfc_elements_c(s4o_ptr, scope, variable_prefix);
       this->set_variable_prefix(variable_prefix);
     }
   
     virtual ~generate_cc_sfc_c(void) {
-      delete generate_cc_sfc_transitionsort;
-      delete generate_cc_sfc_transitionresetsteps;
-      delete generate_cc_sfc_transitionsetsteps;
-      delete generate_cc_sfc_stepassociation;
-      delete generate_cc_sfc_actionexecution;
+      delete generate_cc_sfc_elements;
     }
 
 /*********************************************/
@@ -765,6 +541,7 @@
 /*********************************************/
 
     void *visit(sfc_network_c *symbol) {
+      generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::transitionlist_sg);
       s4o.print(s4o.indent_spaces +"INT i;\n\n");
       s4o.print(s4o.indent_spaces +"BOOL transition;\n\n");
             
@@ -859,25 +636,22 @@
       
       /* generate transition tests */
       s4o.print(s4o.indent_spaces + "// Transitions fire test\n");
-      generate_cc_sfc_transitionsort->reset_transition_number();
-      generate_cc_sfc_transitionsort->generate(symbol);
+      generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::transitiontest_sg);
       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);
+      generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::stepreset_sg);
       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);
+      generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::stepset_sg);
       s4o.print("\n");
       
        /* generate step association */
       s4o.print(s4o.indent_spaces + "// Steps association\n");
-      symbol->accept(*generate_cc_sfc_stepassociation);
+      generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::actionassociation_sg);
       s4o.print("\n");
       
       /* generate action state evaluation */
@@ -896,7 +670,7 @@
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "if (");
       print_variable_prefix();
-      s4o.print("action_list[i].set) {\n");
+      s4o.print("action_list[i].reset) {\n");
       s4o.indent_right();
       s4o.print(s4o.indent_spaces);
       print_variable_prefix();
@@ -916,7 +690,7 @@
       
       /* generate action execution */
       s4o.print(s4o.indent_spaces + "// Actions execution\n");
-      symbol->accept(*generate_cc_sfc_actionexecution);
+      generate_cc_sfc_elements->generate((symbol_c *) symbol, generate_cc_sfc_elements_c::actionbody_sg);
       s4o.print("\n");
       
       return NULL;
--- a/stage4/generate_cc/generate_cc_sfcdecl.cc	Mon Aug 13 18:03:06 2007 +0200
+++ b/stage4/generate_cc/generate_cc_sfcdecl.cc	Mon Aug 27 14:52:15 2007 +0200
@@ -43,25 +43,25 @@
   
   public:
       typedef enum {
-        sfcdecl_sg,
-        sfcinit_sg,
-        stepdef_sg,
-        stepundef_sg,
-        actiondef_sg,
-        actionundef_sg
-       } sfcgeneration_t;
+        sfcdecl_sd,
+        sfcinit_sd,
+        stepdef_sd,
+        stepundef_sd,
+        actiondef_sd,
+        actionundef_sd
+       } sfcdeclaration_t;
   
   private:
     char step_number;
     char action_number;
     char transition_number;
     
-    sfcgeneration_t wanted_sfcgeneration;
+    sfcdeclaration_t wanted_sfcdeclaration;
     
   public:
-    generate_cc_sfcdecl_c(stage4out_c *s4o_ptr, sfcgeneration_t sfcgeneration)
+    generate_cc_sfcdecl_c(stage4out_c *s4o_ptr, sfcdeclaration_t sfcdeclaration)
     : generate_cc_typedecl_c(s4o_ptr) {
-      wanted_sfcgeneration = sfcgeneration;
+      wanted_sfcdeclaration = sfcdeclaration;
     }
     ~generate_cc_sfcdecl_c(void) {}
     
@@ -79,8 +79,8 @@
       step_number = 0;
       action_number = 0;
       transition_number = 0;
-      switch (wanted_sfcgeneration) {
-        case sfcdecl_sg:
+      switch (wanted_sfcdeclaration) {
+        case sfcdecl_sd:
           for(int i = 0; i < symbol->n; i++)
             symbol->elements[i]->accept(*this);
           
@@ -105,7 +105,7 @@
           s4o.print_integer(transition_number);
           s4o.print("];\n");
           break;
-        case sfcinit_sg:
+        case sfcinit_sd:
           /* steps table initialisation */
           s4o.print(s4o.indent_spaces + "STEP temp_step = {0, 0, 0};\n");
           s4o.print(s4o.indent_spaces + "for(UINT i = 0; i < ");
@@ -132,25 +132,25 @@
           s4o.indent_left();
           s4o.print(s4o.indent_spaces + "}\n");
           break;
-        case stepdef_sg:
+        case stepdef_sd:
           s4o.print("// Steps definitions\n");
           for(int i = 0; i < symbol->n; i++)
             symbol->elements[i]->accept(*this);
           s4o.print("\n");
           break;
-        case actiondef_sg:
+        case actiondef_sd:
           s4o.print("// Actions definitions\n");
           for(int i = 0; i < symbol->n; i++)
             symbol->elements[i]->accept(*this);
           s4o.print("\n");
           break;
-        case stepundef_sg:
+        case stepundef_sd:
           s4o.print("// Steps undefinitions\n");
           for(int i = 0; i < symbol->n; i++)
             symbol->elements[i]->accept(*this);
           s4o.print("\n");
           break;
-        case actionundef_sg:
+        case actionundef_sd:
           s4o.print("// Actions undefinitions\n");
           for(int i = 0; i < symbol->n; i++)
             symbol->elements[i]->accept(*this);
@@ -161,11 +161,11 @@
     }
     
     void *visit(initial_step_c *symbol) {
-      switch (wanted_sfcgeneration) {
-        case sfcdecl_sg:
-          step_number++;
-          break;
-        case sfcinit_sg:
+      switch (wanted_sfcdeclaration) {
+        case sfcdecl_sd:
+          step_number++;
+          break;
+        case sfcinit_sd:
           s4o.print(s4o.indent_spaces);
           print_variable_prefix();
           s4o.print("action_list[");
@@ -173,7 +173,7 @@
           s4o.print("].state = 1;\n");
           step_number++;
           break;
-        case stepdef_sg:
+        case stepdef_sd:
           s4o.print("#define ");
           s4o.print(SFC_STEP_ACTION_PREFIX);
           symbol->step_name->accept(*this);
@@ -182,7 +182,7 @@
           s4o.print("\n");
           step_number++;
           break;
-        case stepundef_sg:
+        case stepundef_sd:
           s4o.print("#undef ");
           s4o.print(SFC_STEP_ACTION_PREFIX);
           symbol->step_name->accept(*this);
@@ -195,11 +195,11 @@
     }
     
     void *visit(step_c *symbol) {
-      switch (wanted_sfcgeneration) {
-        case sfcdecl_sg:
-          step_number++;
-          break;
-        case stepdef_sg:
+      switch (wanted_sfcdeclaration) {
+        case sfcdecl_sd:
+          step_number++;
+          break;
+        case stepdef_sd:
           s4o.print("#define ");
           s4o.print(SFC_STEP_ACTION_PREFIX);
           symbol->step_name->accept(*this);
@@ -208,7 +208,7 @@
           s4o.print("\n");
           step_number++;
           break;
-        case stepundef_sg:
+        case stepundef_sd:
           s4o.print("#undef ");
           s4o.print(SFC_STEP_ACTION_PREFIX);
           symbol->step_name->accept(*this);
@@ -221,8 +221,8 @@
     }
 
     void *visit(transition_c *symbol) {
-      switch (wanted_sfcgeneration) {
-        case sfcdecl_sg:
+      switch (wanted_sfcdeclaration) {
+        case sfcdecl_sd:
           transition_number++;
           break;
         default:
@@ -232,8 +232,8 @@
     }
 
     void *visit(action_c *symbol) {
-      switch (wanted_sfcgeneration) {
-        case actiondef_sg:
+      switch (wanted_sfcdeclaration) {
+        case actiondef_sd:
           s4o.print("#define ");
           s4o.print(SFC_STEP_ACTION_PREFIX);
           symbol->action_name->accept(*this);
@@ -242,13 +242,13 @@
           s4o.print("\n");
           action_number++;
           break;
-        case actionundef_sg:
+        case actionundef_sd:
           s4o.print("#undef ");
           s4o.print(SFC_STEP_ACTION_PREFIX);
           symbol->action_name->accept(*this);
           s4o.print("\n");
           break;
-        case sfcdecl_sg:
+        case sfcdecl_sd:
           action_number++;
           break;
         default: