Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
authorlbessard
Fri, 11 Apr 2008 10:53:38 +0200
changeset 119 4cbf71106b66
parent 118 d4cf7ea933a4
child 120 74640e3c7f53
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
stage4/generate_c/generate_c_sfc.cc
stage4/generate_c/generate_c_sfcdecl.cc
--- a/stage4/generate_c/generate_c_sfc.cc	Tue Apr 08 18:21:37 2008 +0200
+++ b/stage4/generate_c/generate_c_sfc.cc	Fri Apr 11 10:53:38 2008 +0200
@@ -94,7 +94,6 @@
 
     void generate(symbol_c *symbol, sfcgeneration_t generation_type) {
       wanted_sfcgeneration = generation_type;
-      transition_number = 0;
       switch (wanted_sfcgeneration) {
         case transitiontest_sg:
           {
@@ -573,13 +572,19 @@
 /*********************************************/
 /* B.1.6  Sequential function chart elements */
 /*********************************************/
-
-    void *visit(sfc_network_c *symbol) {
-      generate_c_sfc_elements->generate((symbol_c *) symbol, generate_c_sfc_elements_c::transitionlist_sg);
-      s4o.print(s4o.indent_spaces +"INT i;\n\n");
+    
+    void *visit(sequential_function_chart_c *symbol) {
+      int i;
+      
+      generate_c_sfc_elements->reset_transition_number();
+      for(i = 0; i < symbol->n; i++) {
+        generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::transitionlist_sg);
+      }
+      
+      s4o.print(s4o.indent_spaces +"INT i;\n");
       s4o.print(s4o.indent_spaces +"BOOL transition;\n\n");
-            
-      /* generate step initilizations */
+      
+      /* generate step initialisations */
       s4o.print(s4o.indent_spaces + "// Steps initialisation\n");
       s4o.print(s4o.indent_spaces + "for (i = 0; i < ");
       print_variable_prefix();
@@ -680,24 +685,30 @@
       
       /* generate transition tests */
       s4o.print(s4o.indent_spaces + "// Transitions fire test\n");
-      generate_c_sfc_elements->generate((symbol_c *) symbol, generate_c_sfc_elements_c::transitiontest_sg);
+      generate_c_sfc_elements->generate((symbol_c *)symbol, generate_c_sfc_elements_c::transitiontest_sg);
       s4o.print("\n");
       
       /* generate transition reset steps */
       s4o.print(s4o.indent_spaces + "// Transitions reset steps\n");
       generate_c_sfc_elements->reset_transition_number();
-      generate_c_sfc_elements->generate((symbol_c *) symbol, generate_c_sfc_elements_c::stepreset_sg);
+      for(i = 0; i < symbol->n; i++) {
+        generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::stepreset_sg);
+      }
       s4o.print("\n");
       
       /* generate transition set steps */
       s4o.print(s4o.indent_spaces + "// Transitions set steps\n");
       generate_c_sfc_elements->reset_transition_number();
-      generate_c_sfc_elements->generate((symbol_c *) symbol, generate_c_sfc_elements_c::stepset_sg);
+      for(i = 0; i < symbol->n; i++) {
+        generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::stepset_sg);
+      }
       s4o.print("\n");
       
-       /* generate step association */
+      /* generate step association */
       s4o.print(s4o.indent_spaces + "// Steps association\n");
-      generate_c_sfc_elements->generate((symbol_c *) symbol, generate_c_sfc_elements_c::actionassociation_sg);
+      for(i = 0; i < symbol->n; i++) {
+        generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::actionassociation_sg);
+      }
       s4o.print("\n");
       
       /* generate action state evaluation */
@@ -736,12 +747,14 @@
       
       /* generate action execution */
       s4o.print(s4o.indent_spaces + "// Actions execution\n");
-      generate_c_sfc_elements->generate((symbol_c *) symbol, generate_c_sfc_elements_c::actionbody_sg);
+      for(i = 0; i < symbol->n; i++) {
+        generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::actionbody_sg);
+      }
       s4o.print("\n");
       
       return NULL;
     }
-
+    
     void generate(sequential_function_chart_c *sfc) {
       sfc->accept(*this);
     }
--- a/stage4/generate_c/generate_c_sfcdecl.cc	Tue Apr 08 18:21:37 2008 +0200
+++ b/stage4/generate_c/generate_c_sfcdecl.cc	Fri Apr 11 10:53:38 2008 +0200
@@ -235,6 +235,7 @@
       switch (wanted_sfcdeclaration) {
         case stepcount_sd:
         case sfcdecl_sd:
+        case sfcinit_sd:
           step_number++;
           break;
         case stepdef_sd: