stage4/generate_cc/generate_cc_sfc.cc
changeset 18 e6af5eb5f546
parent 17 38754701ac41
child 19 cee3c4e5afe2
equal deleted inserted replaced
17:38754701ac41 18:e6af5eb5f546
    39 /***********************************************************************/
    39 /***********************************************************************/
    40 
    40 
    41 class generate_cc_sfc_transitiontest_c: public generate_cc_base_c {
    41 class generate_cc_sfc_transitiontest_c: public generate_cc_base_c {
    42   
    42   
    43   private:
    43   private:
       
    44     char transition_number;
       
    45   
       
    46   private:
    44     generate_cc_il_c *generate_cc_il;
    47     generate_cc_il_c *generate_cc_il;
    45     generate_cc_st_c *generate_cc_st;
    48     generate_cc_st_c *generate_cc_st;
    46     
    49     
    47   public:
    50   public:
    48     generate_cc_sfc_transitiontest_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
    51     generate_cc_sfc_transitiontest_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
    55     ~generate_cc_sfc_transitiontest_c(void) {
    58     ~generate_cc_sfc_transitiontest_c(void) {
    56       delete generate_cc_il;
    59       delete generate_cc_il;
    57       delete generate_cc_st;
    60       delete generate_cc_st;
    58     }
    61     }
    59 
    62 
       
    63     void reset_transition_number(void) {transition_number = 0;}
       
    64     void print_transition_number(void) {
       
    65       char str[10];
       
    66       sprintf(str, "%d", transition_number);
       
    67       s4o.print(str);
       
    68     }
       
    69 
    60     void print_step_argument(symbol_c *step_name, const char* argument) {
    70     void print_step_argument(symbol_c *step_name, const char* argument) {
    61       print_variable_prefix();
    71       print_variable_prefix();
    62       s4o.print("step_list[");
    72       s4o.print("step_list[");
       
    73       s4o.print(SFC_STEP_ACTION_PREFIX);
    63       step_name->accept(*this);
    74       step_name->accept(*this);
    64       s4o.print("].");
    75       s4o.print("].");
    65       s4o.print(argument);
    76       s4o.print(argument);
    66     }
    77     }
    67     
       
    68     void print_reset_step(symbol_c *step_name) {
       
    69       s4o.print(s4o.indent_spaces);
       
    70       print_step_argument(step_name, "state");
       
    71       s4o.print(" = 0;\n" + s4o.indent_spaces + "if (");
       
    72       print_step_argument(step_name, "pulse");
       
    73       s4o.print(" != 1 {\n");
       
    74       s4o.indent_right();
       
    75       s4o.print(s4o.indent_spaces);
       
    76       print_step_argument(step_name, "pulse");
       
    77       s4o.print(" = 2;\n");
       
    78       s4o.indent_left();
       
    79       s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n");
       
    80       s4o.indent_right();
       
    81       s4o.print(s4o.indent_spaces);
       
    82       print_step_argument(step_name, "pulse");
       
    83       s4o.print(" = 0;\n");
       
    84       s4o.indent_left();
       
    85       s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces);
       
    86       print_step_argument(step_name, "elapsed_time");
       
    87       s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);");
       
    88     }
       
    89     
       
    90     void print_set_step(symbol_c *step_name) {
       
    91       s4o.print(s4o.indent_spaces);
       
    92       print_step_argument(step_name, "state");
       
    93       s4o.print(" = 1;\n" + s4o.indent_spaces);
       
    94       print_step_argument(step_name, "pulse");
       
    95       s4o.print(" = 1;");
       
    96     } 
       
    97     
       
    98     void print_steps_state_test(steps_c *symbol) {
       
    99       if (symbol->step_name != NULL) {
       
   100         print_step_argument(symbol->step_name, "state");
       
   101       }
       
   102       if (symbol->step_name_list != NULL) {
       
   103         for(int i = 0; i < ((list_c*)symbol->step_name_list)->n; i++) {
       
   104           print_step_argument(((list_c*)symbol->step_name_list)->elements[i], "state");
       
   105           if (i < ((list_c*)symbol->step_name_list)->n - 1) {
       
   106             s4o.print(" && ");
       
   107           }
       
   108         }
       
   109       }
       
   110     }
       
   111       
       
   112     void print_reset_steps(steps_c *symbol) {
       
   113       if (symbol->step_name != NULL) {
       
   114         print_reset_step(symbol->step_name);
       
   115         s4o.print("\n");
       
   116       }
       
   117       if (symbol->step_name_list != NULL) {
       
   118         for(int i = 0; i < ((list_c*)symbol->step_name_list)->n; i++) {
       
   119           print_reset_step(((list_c*)symbol->step_name_list)->elements[i]);
       
   120           s4o.print("\n");
       
   121         }
       
   122       }
       
   123     }
       
   124 
       
   125     void print_set_steps(steps_c *symbol) {
       
   126       if (symbol->step_name != NULL) {
       
   127         print_set_step(symbol->step_name);
       
   128         s4o.print("\n");
       
   129       }
       
   130       if (symbol->step_name_list != NULL) {
       
   131         for(int i = 0; i < ((list_c*)symbol->step_name_list)->n; i++) {
       
   132           print_set_step(((list_c*)symbol->step_name_list)->elements[i]);
       
   133           s4o.print("\n");
       
   134         }
       
   135       }
       
   136     }
       
   137 
    78 
   138 /*********************************************/
    79 /*********************************************/
   139 /* B.1.6  Sequential function chart elements */
    80 /* B.1.6  Sequential function chart elements */
   140 /*********************************************/
    81 /*********************************************/
   141     
    82     
   143     
    84     
   144     void *visit(step_c *symbol) {return NULL;}
    85     void *visit(step_c *symbol) {return NULL;}
   145 
    86 
   146     void *visit(transition_c *symbol) {
    87     void *visit(transition_c *symbol) {
   147       s4o.print(s4o.indent_spaces + "if (");
    88       s4o.print(s4o.indent_spaces + "if (");
   148       print_steps_state_test((steps_c *)symbol->from_steps);
    89       symbol->from_steps->accept(*this);
   149       s4o.print(") {\n");
    90       s4o.print(") {\n");
   150       s4o.indent_right();
    91       s4o.indent_right();
   151       
    92       
   152       // Calculate transition value
    93       // Calculate transition value
   153       if (symbol->transition_condition_il != NULL) {
    94       if (symbol->transition_condition_il != NULL) {
   154         generate_cc_il->declare_backup_variable();
    95         generate_cc_il->declare_backup_variable();
   155         s4o.print(s4o.indent_spaces);
    96         s4o.print(s4o.indent_spaces);
   156         symbol->transition_condition_il->accept(*generate_cc_il);
    97         symbol->transition_condition_il->accept(*generate_cc_il);
   157         s4o.print("if (");
    98         print_variable_prefix();
       
    99         s4o.print("transition_list[");
       
   100         print_transition_number();
       
   101         s4o.print("] = ");
   158         generate_cc_il->print_backup_variable();
   102         generate_cc_il->print_backup_variable();
   159         s4o.print(") {\n");
   103         s4o.print(";\n");
   160       }
   104       }
   161       if (symbol->transition_condition_st != NULL) {
   105       if (symbol->transition_condition_st != NULL) {
   162         s4o.print(s4o.indent_spaces + "if (");
   106         print_variable_prefix();
       
   107         s4o.print("transition_list[");
       
   108         print_transition_number();
       
   109         s4o.print("] = ");
   163         symbol->transition_condition_st->accept(*generate_cc_st);
   110         symbol->transition_condition_st->accept(*generate_cc_st);
   164         s4o.print(") {\n");
   111         s4o.print(";\n");
   165       }
   112       }
   166       
   113       s4o.indent_left();
   167       s4o.indent_right();      
   114       s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n");
   168       print_reset_steps((steps_c *)symbol->from_steps);
   115       s4o.indent_right();
   169       print_set_steps((steps_c *)symbol->to_steps);      
   116       s4o.print(s4o.indent_spaces);
   170       s4o.indent_left();
   117       print_variable_prefix();
   171 
   118       s4o.print("transition_list[");
   172       s4o.print(s4o.indent_spaces + "}\n");
   119       print_transition_number();
   173       s4o.indent_left();
   120       s4o.print("] = 0;\n");
   174       s4o.print(s4o.indent_spaces + "}\n\n");
   121       s4o.indent_left();
       
   122       s4o.print(s4o.indent_spaces + "}\n");
       
   123       
       
   124       transition_number++;
       
   125       return NULL;
       
   126     }
       
   127     
       
   128     void *visit(steps_c *symbol) {
       
   129       if (symbol->step_name != NULL) {
       
   130         print_step_argument(symbol->step_name, "state");
       
   131       }
       
   132       if (symbol->step_name_list != NULL) {
       
   133         symbol->step_name_list->accept(*this);
       
   134       }
       
   135       return NULL;
       
   136     }
       
   137     
       
   138     void *visit(step_name_list_c *symbol) {
       
   139       for(int i = 0; i < symbol->n; i++) {
       
   140         print_step_argument(symbol->elements[i], "state");
       
   141         if (i < symbol->n - 1) {
       
   142           s4o.print(" && ");
       
   143         }
       
   144       }
   175       return NULL;
   145       return NULL;
   176     }
   146     }
   177     
   147     
   178     void *visit(action_c *symbol) {return NULL;}
   148     void *visit(action_c *symbol) {return NULL;}
   179 
   149 
   180 }; /* generate_cc_sfc_transitiontest_c */
   150 }; /* generate_cc_sfc_transitiontest_c */
       
   151 
       
   152 
       
   153 
       
   154 
       
   155 /***********************************************************************/
       
   156 /***********************************************************************/
       
   157 /***********************************************************************/
       
   158 /***********************************************************************/
       
   159 
       
   160 class generate_cc_sfc_transitionresetsteps_c: public generate_cc_base_c {
       
   161   
       
   162   private:
       
   163     char transition_number;
       
   164   
       
   165   public:
       
   166     generate_cc_sfc_transitionresetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
       
   167     : generate_cc_base_c(s4o_ptr) {
       
   168       this->set_variable_prefix(variable_prefix);
       
   169     }
       
   170     
       
   171     void reset_transition_number(void) {transition_number = 0;}
       
   172     void print_transition_number(void) {
       
   173       char str[10];
       
   174       sprintf(str, "%d", transition_number);
       
   175       s4o.print(str);
       
   176     }
       
   177     
       
   178     void print_step_argument(symbol_c *step_name, const char* argument) {
       
   179       print_variable_prefix();
       
   180       s4o.print("step_list[");
       
   181       s4o.print(SFC_STEP_ACTION_PREFIX);
       
   182       step_name->accept(*this);
       
   183       s4o.print("].");
       
   184       s4o.print(argument);
       
   185     }
       
   186 
       
   187     void print_reset_step(symbol_c *step_name) {
       
   188       s4o.print(s4o.indent_spaces);
       
   189       print_step_argument(step_name, "state");
       
   190       s4o.print(" = 0;\n" + s4o.indent_spaces);
       
   191       print_step_argument(step_name, "elapsed_time");
       
   192       s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
       
   193     }
       
   194 
       
   195 /*********************************************/
       
   196 /* B.1.6  Sequential function chart elements */
       
   197 /*********************************************/
       
   198     
       
   199     void *visit(initial_step_c *symbol) {return NULL;}
       
   200     
       
   201     void *visit(step_c *symbol) {return NULL;}
       
   202 
       
   203     void *visit(transition_c *symbol) {
       
   204       s4o.print(s4o.indent_spaces + "if (");
       
   205       print_variable_prefix();
       
   206       s4o.print("transition_list[");
       
   207       print_transition_number();
       
   208       s4o.print("]) {\n");
       
   209       s4o.indent_right();
       
   210       symbol->from_steps->accept(*this);
       
   211       s4o.indent_left();
       
   212       s4o.print(s4o.indent_spaces + "}\n");
       
   213       transition_number++;
       
   214       return NULL;
       
   215     }
       
   216     
       
   217     void *visit(steps_c *symbol) {
       
   218       if (symbol->step_name != NULL) {
       
   219         print_reset_step(symbol->step_name);
       
   220       }
       
   221       if (symbol->step_name_list != NULL) {
       
   222         symbol->step_name_list->accept(*this);
       
   223       }
       
   224       return NULL;
       
   225     }
       
   226     
       
   227     void *visit(step_name_list_c *symbol) {
       
   228       for(int i = 0; i < symbol->n; i++) {
       
   229         print_reset_step(symbol->elements[i]);
       
   230       }
       
   231       return NULL;
       
   232     }
       
   233     
       
   234     void *visit(action_c *symbol) {return NULL;}
       
   235 
       
   236 }; /* generate_cc_sfc_transitionresetsteps_c */
       
   237       
       
   238 
       
   239 
       
   240 
       
   241 /***********************************************************************/
       
   242 /***********************************************************************/
       
   243 /***********************************************************************/
       
   244 /***********************************************************************/
       
   245 
       
   246 class generate_cc_sfc_transitionsetsteps_c: public generate_cc_base_c {
       
   247   
       
   248   private:
       
   249     char transition_number;
       
   250   
       
   251   public:
       
   252     generate_cc_sfc_transitionsetsteps_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
       
   253     : generate_cc_base_c(s4o_ptr) {
       
   254       this->set_variable_prefix(variable_prefix);
       
   255     }
       
   256     
       
   257     void reset_transition_number(void) {transition_number = 0;}
       
   258     void print_transition_number(void) {
       
   259       char str[10];
       
   260       sprintf(str, "%d", transition_number);
       
   261       s4o.print(str);
       
   262     }
       
   263     
       
   264     void print_step_argument(symbol_c *step_name, const char* argument) {
       
   265       print_variable_prefix();
       
   266       s4o.print("step_list[");
       
   267       s4o.print(SFC_STEP_ACTION_PREFIX);
       
   268       step_name->accept(*this);
       
   269       s4o.print("].");
       
   270       s4o.print(argument);
       
   271     }
       
   272 
       
   273     void print_set_step(symbol_c *step_name) {
       
   274       s4o.print(s4o.indent_spaces);
       
   275       print_step_argument(step_name, "state");
       
   276       s4o.print(" = 1;\n");
       
   277     }
       
   278 
       
   279 /*********************************************/
       
   280 /* B.1.6  Sequential function chart elements */
       
   281 /*********************************************/
       
   282     
       
   283     void *visit(initial_step_c *symbol) {return NULL;}
       
   284     
       
   285     void *visit(step_c *symbol) {return NULL;}
       
   286 
       
   287     void *visit(transition_c *symbol) {
       
   288       s4o.print(s4o.indent_spaces + "if (");
       
   289       print_variable_prefix();
       
   290       s4o.print("transition_list[");
       
   291       print_transition_number();
       
   292       s4o.print("]) {\n");
       
   293       s4o.indent_right();
       
   294       symbol->to_steps->accept(*this);
       
   295       s4o.indent_left();
       
   296       s4o.print(s4o.indent_spaces + "}\n");
       
   297       transition_number++;
       
   298       return NULL;
       
   299     }
       
   300     
       
   301     void *visit(steps_c *symbol) {
       
   302       if (symbol->step_name != NULL) {
       
   303         print_set_step(symbol->step_name);
       
   304       }
       
   305       if (symbol->step_name_list != NULL) {
       
   306         symbol->step_name_list->accept(*this);
       
   307       }
       
   308       return NULL;
       
   309     }
       
   310     
       
   311     void *visit(step_name_list_c *symbol) {
       
   312       for(int i = 0; i < symbol->n; i++) {
       
   313         print_set_step(symbol->elements[i]);
       
   314       }
       
   315       return NULL;
       
   316     }
       
   317     
       
   318     void *visit(action_c *symbol) {return NULL;}
       
   319 
       
   320 }; /* generate_cc_sfc_transitionsetsteps_c */
   181 
   321 
   182 
   322 
   183 
   323 
   184 
   324 
   185 /***********************************************************************/
   325 /***********************************************************************/
   200     }
   340     }
   201 
   341 
   202     void print_step_argument(symbol_c *step_name, const char* argument) {
   342     void print_step_argument(symbol_c *step_name, const char* argument) {
   203       print_variable_prefix();
   343       print_variable_prefix();
   204       s4o.print("step_list[");
   344       s4o.print("step_list[");
       
   345       s4o.print(SFC_STEP_ACTION_PREFIX);
   205       step_name->accept(*this);
   346       step_name->accept(*this);
   206       s4o.print("].");
   347       s4o.print("].");
   207       s4o.print(argument);
   348       s4o.print(argument);
   208     }
   349     }
   209 
   350 
   210     void print_action_argument(symbol_c *action_name, const char* argument) {
   351     void print_action_argument(symbol_c *action_name, const char* argument) {
   211       print_variable_prefix();
   352       print_variable_prefix();
   212       s4o.print("action_list[");
   353       s4o.print("action_list[");
       
   354       s4o.print(SFC_STEP_ACTION_PREFIX);
   213       action_name->accept(*this);
   355       action_name->accept(*this);
   214       s4o.print("].");
   356       s4o.print("].");
   215       s4o.print(argument);
   357       s4o.print(argument);
   216     }
   358     }
   217 
   359 
   218 /*********************************************/
   360 /*********************************************/
   219 /* B.1.6  Sequential function chart elements */
   361 /* B.1.6  Sequential function chart elements */
   220 /*********************************************/
   362 /*********************************************/
   221     
   363     
   222     void *visit(initial_step_c *symbol) {
   364     void *visit(initial_step_c *symbol) {
   223       s4o.print(s4o.indent_spaces + "// ");
   365       if (((list_c*)symbol->action_association_list)->n > 0) {
   224       symbol->step_name->accept(*this);
   366         s4o.print(s4o.indent_spaces + "// ");
   225       s4o.print(" action associations\n");
   367         symbol->step_name->accept(*this);
   226       current_step = symbol->step_name;
   368         s4o.print(" action associations\n");
   227       symbol->action_association_list->accept(*this);
   369         current_step = symbol->step_name;
       
   370         s4o.print(s4o.indent_spaces + "{\n");
       
   371         s4o.indent_right();
       
   372         s4o.print(s4o.indent_spaces + "char activated = ");
       
   373         print_step_argument(current_step, "state");
       
   374         s4o.print(" && !");
       
   375         print_step_argument(current_step, "prev_state");
       
   376         s4o.print(";\n");
       
   377         s4o.print(s4o.indent_spaces + "char desactivated = !");
       
   378         print_step_argument(current_step, "state");
       
   379         s4o.print(" && ");
       
   380         print_step_argument(current_step, "prev_state");
       
   381         s4o.print(";\n");
       
   382         s4o.print(s4o.indent_spaces + "char active = ");
       
   383         print_step_argument(current_step, "state");
       
   384         s4o.print(";\n");
       
   385         symbol->action_association_list->accept(*this);
       
   386         s4o.indent_left();
       
   387         s4o.print(s4o.indent_spaces + "}\n\n");
       
   388       }
   228       return NULL;
   389       return NULL;
   229     }
   390     }
   230     
   391     
   231     void *visit(step_c *symbol) {
   392     void *visit(step_c *symbol) {
   232       s4o.print(s4o.indent_spaces + "// ");
   393       if (((list_c*)symbol->action_association_list)->n > 0) {
   233       symbol->step_name->accept(*this);
   394         s4o.print(s4o.indent_spaces + "// ");
   234       s4o.print(" action associations\n");
   395         symbol->step_name->accept(*this);
   235       current_step = symbol->step_name;
   396         s4o.print(" action associations\n");
   236       symbol->action_association_list->accept(*this);
   397         current_step = symbol->step_name;
       
   398         s4o.print(s4o.indent_spaces + "{\n");
       
   399         s4o.indent_right();
       
   400         s4o.print(s4o.indent_spaces + "char activated = ");
       
   401         print_step_argument(current_step, "state");
       
   402         s4o.print(" && !");
       
   403         print_step_argument(current_step, "prev_state");
       
   404         s4o.print(";\n");
       
   405         s4o.print(s4o.indent_spaces + "char desactivated = !");
       
   406         print_step_argument(current_step, "state");
       
   407         s4o.print(" && ");
       
   408         print_step_argument(current_step, "prev_state");
       
   409         s4o.print(";\n");
       
   410         s4o.print(s4o.indent_spaces + "char active = ");
       
   411         print_step_argument(current_step, "state");
       
   412         s4o.print(";\n");
       
   413         symbol->action_association_list->accept(*this);
       
   414         s4o.indent_left();
       
   415         s4o.print(s4o.indent_spaces + "}\n\n");
       
   416       }
   237       return NULL;
   417       return NULL;
   238     }
   418     }
   239 
   419 
   240     void *visit(transition_c *symbol) {return NULL;}
   420     void *visit(transition_c *symbol) {return NULL;}
   241     
   421     
   242     void *visit(action_c *symbol) {return NULL;}
   422     void *visit(action_c *symbol) {return NULL;}
   243 
   423 
   244     void *visit(action_association_list_c* symbol) {
   424     void *visit(action_association_list_c* symbol) {
   245       print_list(symbol, "", "\n", "\n\n");
   425       print_list(symbol, "", "\n", "\n");
   246       return NULL;
   426       return NULL;
   247     }
   427     }
   248 
   428 
   249     void *visit(action_association_c *symbol) {
   429     void *visit(action_association_c *symbol) {
   250       if (symbol->action_qualifier != NULL) {
   430       if (symbol->action_qualifier != NULL) {
   268     void *visit(action_qualifier_c *symbol) {
   448     void *visit(action_qualifier_c *symbol) {
   269       char *qualifier = (char *)symbol->action_qualifier->accept(*this);
   449       char *qualifier = (char *)symbol->action_qualifier->accept(*this);
   270       
   450       
   271       s4o.print(s4o.indent_spaces + "if (");
   451       s4o.print(s4o.indent_spaces + "if (");
   272       if (strcmp(qualifier, "N") == 0) {
   452       if (strcmp(qualifier, "N") == 0) {
   273         print_step_argument(current_step, "state");
   453         s4o.print("active");
   274       }
   454       }
   275       if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || 
   455       if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || 
   276           strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0) {
   456           strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0) {
   277         print_step_argument(current_step, "pulse");
   457         s4o.print("activated");
   278         s4o.print(" == 1");
       
   279       }
   458       }
   280       if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) {
   459       if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) {
   281         print_step_argument(current_step, "state");
   460         s4o.print("active && ");
   282         s4o.print(" && ");
       
   283         print_step_argument(current_step, "elapsed_time");
   461         print_step_argument(current_step, "elapsed_time");
   284         if (strcmp(qualifier, "D") == 0) {
   462         if (strcmp(qualifier, "D") == 0) {
   285           s4o.print(" >= ");
   463           s4o.print(" >= ");
   286         }
   464         }
   287         else {
   465         else {
   310         s4o.print(";\n");
   488         s4o.print(";\n");
   311       }
   489       }
   312       s4o.indent_left();
   490       s4o.indent_left();
   313       s4o.print(s4o.indent_spaces + "}");
   491       s4o.print(s4o.indent_spaces + "}");
   314       if (strcmp(qualifier, "DS") == 0) {
   492       if (strcmp(qualifier, "DS") == 0) {
   315         print_step_argument(current_step, "pulse");
   493         s4o.print("desactivated");
   316         s4o.print(" == 2) {\n");
       
   317         s4o.indent_right();
   494         s4o.indent_right();
   318         s4o.print(s4o.indent_spaces);
   495         s4o.print(s4o.indent_spaces);
   319         print_action_argument(current_action, "set_remaining_time");
   496         print_action_argument(current_action, "set_remaining_time");
   320         s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
   497         s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
   321       }
   498       }
   368     
   545     
   369     void *visit(action_c *symbol) {
   546     void *visit(action_c *symbol) {
   370       s4o.print(s4o.indent_spaces + "if(");
   547       s4o.print(s4o.indent_spaces + "if(");
   371       print_variable_prefix();
   548       print_variable_prefix();
   372       s4o.print("action_list[");
   549       s4o.print("action_list[");
       
   550       s4o.print(SFC_STEP_ACTION_PREFIX);
   373       symbol->action_name->accept(*this);
   551       symbol->action_name->accept(*this);
   374       s4o.print("].state) {");
   552       s4o.print("].state) {");
   375       s4o.indent_right();
   553       s4o.indent_right();
   376       
   554       
   377       // generate action code
   555       // generate action code
   393 
   571 
   394 class generate_cc_sfc_c: public generate_cc_typedecl_c {
   572 class generate_cc_sfc_c: public generate_cc_typedecl_c {
   395   
   573   
   396   private:
   574   private:
   397     generate_cc_sfc_transitiontest_c *generate_cc_sfc_transitiontest;
   575     generate_cc_sfc_transitiontest_c *generate_cc_sfc_transitiontest;
       
   576     generate_cc_sfc_transitionresetsteps_c *generate_cc_sfc_transitionresetsteps;
       
   577     generate_cc_sfc_transitionsetsteps_c *generate_cc_sfc_transitionsetsteps;
   398     generate_cc_sfc_stepassociation_c *generate_cc_sfc_stepassociation;
   578     generate_cc_sfc_stepassociation_c *generate_cc_sfc_stepassociation;
   399     generate_cc_sfc_actionexecution_c *generate_cc_sfc_actionexecution;
   579     generate_cc_sfc_actionexecution_c *generate_cc_sfc_actionexecution;
   400   
   580   
   401   public:
   581   public:
   402     generate_cc_sfc_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
   582     generate_cc_sfc_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
   403     : generate_cc_typedecl_c(s4o_ptr) {
   583     : generate_cc_typedecl_c(s4o_ptr) {
   404       generate_cc_sfc_transitiontest = new generate_cc_sfc_transitiontest_c(s4o_ptr, scope, variable_prefix);
   584       generate_cc_sfc_transitiontest = new generate_cc_sfc_transitiontest_c(s4o_ptr, scope, variable_prefix);
       
   585       generate_cc_sfc_transitionresetsteps = new generate_cc_sfc_transitionresetsteps_c(s4o_ptr, scope, variable_prefix);
       
   586       generate_cc_sfc_transitionsetsteps = new generate_cc_sfc_transitionsetsteps_c(s4o_ptr, scope, variable_prefix);
   405       generate_cc_sfc_stepassociation = new generate_cc_sfc_stepassociation_c(s4o_ptr, scope, variable_prefix);
   587       generate_cc_sfc_stepassociation = new generate_cc_sfc_stepassociation_c(s4o_ptr, scope, variable_prefix);
   406       generate_cc_sfc_actionexecution = new generate_cc_sfc_actionexecution_c(s4o_ptr, scope, variable_prefix);
   588       generate_cc_sfc_actionexecution = new generate_cc_sfc_actionexecution_c(s4o_ptr, scope, variable_prefix);
   407       this->set_variable_prefix(variable_prefix);
   589       this->set_variable_prefix(variable_prefix);
   408     }
   590     }
   409   
   591   
   410     virtual ~generate_cc_sfc_c(void) {
   592     virtual ~generate_cc_sfc_c(void) {
   411       delete generate_cc_sfc_transitiontest;
   593       delete generate_cc_sfc_transitiontest;
       
   594       delete generate_cc_sfc_transitionresetsteps;
       
   595       delete generate_cc_sfc_transitionsetsteps;
   412       delete generate_cc_sfc_stepassociation;
   596       delete generate_cc_sfc_stepassociation;
   413       delete generate_cc_sfc_actionexecution;
   597       delete generate_cc_sfc_actionexecution;
   414     }
   598     }
   415 
   599 
   416 /*********************************************/
   600 /*********************************************/
   427       print_variable_prefix();
   611       print_variable_prefix();
   428       s4o.print("nb_steps; i++) {\n");
   612       s4o.print("nb_steps; i++) {\n");
   429       s4o.indent_right();
   613       s4o.indent_right();
   430       s4o.print(s4o.indent_spaces);
   614       s4o.print(s4o.indent_spaces);
   431       print_variable_prefix();
   615       print_variable_prefix();
   432       s4o.print("step_list[i].pulse = 0;\n");
   616       s4o.print("step_list[i].prev_state = ");
       
   617       print_variable_prefix();
       
   618       s4o.print("step_list[i].state;\n");
   433       s4o.print(s4o.indent_spaces + "if (");
   619       s4o.print(s4o.indent_spaces + "if (");
   434       print_variable_prefix();
   620       print_variable_prefix();
   435       s4o.print("step_list[i].state) {\n");
   621       s4o.print("step_list[i].state) {\n");
   436       s4o.indent_right();
   622       s4o.indent_right();
   437       s4o.print(s4o.indent_spaces);
   623       s4o.print(s4o.indent_spaces);
   508       s4o.indent_left();
   694       s4o.indent_left();
   509       s4o.print(s4o.indent_spaces + "}\n\n");
   695       s4o.print(s4o.indent_spaces + "}\n\n");
   510       
   696       
   511       /* generate transition tests */
   697       /* generate transition tests */
   512       s4o.print(s4o.indent_spaces + "// Transitions fire test\n");
   698       s4o.print(s4o.indent_spaces + "// Transitions fire test\n");
       
   699       generate_cc_sfc_transitiontest->reset_transition_number();
   513       symbol->accept(*generate_cc_sfc_transitiontest);
   700       symbol->accept(*generate_cc_sfc_transitiontest);
       
   701       s4o.print("\n");
       
   702       
       
   703       /* generate transition reset steps */
       
   704       s4o.print(s4o.indent_spaces + "// Transitions reset steps\n");
       
   705       generate_cc_sfc_transitionresetsteps->reset_transition_number();
       
   706       symbol->accept(*generate_cc_sfc_transitionresetsteps);
       
   707       s4o.print("\n");
       
   708       
       
   709       /* generate transition set steps */
       
   710       s4o.print(s4o.indent_spaces + "// Transitions set steps\n");
       
   711       generate_cc_sfc_transitionsetsteps->reset_transition_number();
       
   712       symbol->accept(*generate_cc_sfc_transitionsetsteps);
   514       s4o.print("\n");
   713       s4o.print("\n");
   515       
   714       
   516        /* generate step association */
   715        /* generate step association */
   517       s4o.print(s4o.indent_spaces + "// Steps association\n");
   716       s4o.print(s4o.indent_spaces + "// Steps association\n");
   518       symbol->accept(*generate_cc_sfc_stepassociation);
   717       symbol->accept(*generate_cc_sfc_stepassociation);