Bug on SFC transition parsing and generation fixed
authorlbessard
Thu, 15 Nov 2007 10:21:19 +0100
changeset 87 b97f9ad7b2c6
parent 86 1988bf1634da
child 88 dab799d3d4a6
Bug on SFC transition parsing and generation fixed
absyntax/absyntax.def
stage1_2/iec.y
stage4/generate_c/generate_c_sfc.cc
stage4/generate_iec/generate_iec.cc
--- a/absyntax/absyntax.def	Wed Nov 14 18:59:47 2007 +0100
+++ b/absyntax/absyntax.def	Thu Nov 15 10:21:19 2007 +0100
@@ -572,7 +572,9 @@
 
 SYM_REF2(action_qualifier_c, action_qualifier, action_time)
 
-SYM_REF6(transition_c, transition_name, integer, from_steps, to_steps, transition_condition_il, transition_condition_st)
+SYM_REF5(transition_c, transition_name, integer, from_steps, to_steps, transition_condition)
+
+SYM_REF2(transition_condition_c, transition_condition_il, transition_condition_st)
 
 SYM_REF2(steps_c, step_name, step_name_list)
 
--- a/stage1_2/iec.y	Wed Nov 14 18:59:47 2007 +0100
+++ b/stage1_2/iec.y	Thu Nov 15 10:21:19 2007 +0100
@@ -3782,33 +3782,33 @@
     FROM steps TO steps 
     {cmd_goto_body_state();} transition_condition 
   END_TRANSITION 
-	{$$ = new transition_c(NULL, NULL, $3, $5, $7, NULL, locloc(@$));}
+	{$$ = new transition_c(NULL, NULL, $3, $5, $7, locloc(@$));}
 //| TRANSITION identifier FROM steps TO steps ... 
 | TRANSITION transition_name 
     FROM steps TO steps 
     {cmd_goto_body_state();} transition_condition 
   END_TRANSITION 
-	{$$ = new transition_c($2, NULL, $4, $6, $8, NULL, locloc(@$));}
+	{$$ = new transition_c($2, NULL, $4, $6, $8, locloc(@$));}
 | TRANSITION '(' {cmd_goto_sfc_priority_state();} PRIORITY {cmd_pop_state();} ASSIGN integer ')' 
     FROM steps TO steps 
     {cmd_goto_body_state();} transition_condition 
   END_TRANSITION
-        {$$ = new transition_c(NULL, $7, $10, $12, $14, NULL, locloc(@$));}
+        {$$ = new transition_c(NULL, $7, $10, $12, $14, locloc(@$));}
 //| TRANSITION identifier '(' PRIORITY ASSIGN integer ')' FROM steps TO steps ...
 | TRANSITION transition_name '(' {cmd_goto_sfc_priority_state();} PRIORITY {cmd_pop_state();} ASSIGN integer ')' 
     FROM steps TO steps 
     {cmd_goto_body_state();} transition_condition 
   END_TRANSITION
-        {$$ = new transition_c($2, $8, $11, $13, $15, NULL, locloc(@$));}
+        {$$ = new transition_c($2, $8, $11, $13, $15, locloc(@$));}
 ;
 
 
 
 transition_condition:
   ':' eol_list simple_instr_list
-	{$$ = $3;}
+	{$$ = new transition_condition_c($3, NULL);}
 | ASSIGN expression ';'
-	{$$ = $2}
+	{$$ = new transition_condition_c(NULL, $2);}
 ;
 
 
--- a/stage4/generate_c/generate_c_sfc.cc	Wed Nov 14 18:59:47 2007 +0100
+++ b/stage4/generate_c/generate_c_sfc.cc	Thu Nov 15 10:21:19 2007 +0100
@@ -96,6 +96,7 @@
 
     void generate(symbol_c *symbol, sfcgeneration_t generation_type) {
       wanted_sfcgeneration = generation_type;
+      transition_number = 0;
       switch (wanted_sfcgeneration) {
         case transitiontest_sg:
           {
@@ -259,26 +260,8 @@
           s4o.indent_right();
           
           // Calculate transition value
-          if (symbol->transition_condition_il != NULL) {
-            generate_c_il->declare_backup_variable();
-            s4o.print(s4o.indent_spaces);
-            symbol->transition_condition_il->accept(*generate_c_il);
-            print_variable_prefix();
-            s4o.print("transition_list[");
-            print_transition_number();
-            s4o.print("] = ");
-            generate_c_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_c_st);
-            s4o.print(";\n");
-          }
+          symbol->transition_condition->accept(*this);
+          
           if (symbol->integer != NULL) {
             s4o.print(s4o.indent_spaces + "if (");
             print_variable_prefix();
@@ -335,6 +318,38 @@
       return NULL;
     }
     
+    void *visit(transition_condition_c *symbol) {
+      switch (wanted_sfcgeneration) {
+        case transitiontest_sg:
+          // Transition condition is in IL
+          if (symbol->transition_condition_il != NULL) {
+            generate_c_il->declare_backup_variable();
+            s4o.print(s4o.indent_spaces);
+            symbol->transition_condition_il->accept(*generate_c_il);
+            print_variable_prefix();
+            s4o.print("transition_list[");
+            print_transition_number();
+            s4o.print("] = ");
+            generate_c_il->print_backup_variable();
+            s4o.print(";\n");
+          }
+          // Transition condition is in ST
+          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_c_st);
+            s4o.print(";\n");
+          }
+          break;
+        default:
+          break;
+      }
+      return NULL;
+    }
+    
     void *visit(action_c *symbol) {
       switch (wanted_sfcgeneration) {
         case actionbody_sg:
--- a/stage4/generate_iec/generate_iec.cc	Wed Nov 14 18:59:47 2007 +0100
+++ b/stage4/generate_iec/generate_iec.cc	Thu Nov 15 10:21:19 2007 +0100
@@ -1140,20 +1140,25 @@
   s4o.print(" TO ");
   symbol->to_steps->accept(*this);
   s4o.indent_right();
+  symbol->transition_condition->accept(*this);
+  s4o.indent_left();
+  s4o.print(s4o.indent_spaces);
+  s4o.print("END_TRANSITION\n");
+  return NULL;
+}
+
+void *visit(transition_condition_c *symbol) {
   if (symbol->transition_condition_il != NULL) {
-  	s4o.print(":\n");
+    s4o.print(":\n");
     symbol->transition_condition_il->accept(*this);
   }
   if (symbol->transition_condition_st != NULL) {
-  	s4o.print("\n");
+    s4o.print("\n");
     s4o.print(s4o.indent_spaces);
     s4o.print(":= ");
     symbol->transition_condition_st->accept(*this);
     s4o.print(";\n");
   }
-  s4o.indent_left();
-  s4o.print(s4o.indent_spaces);
-  s4o.print("END_TRANSITION\n");
   return NULL;
 }