stage4/generate_c/generate_c_sfc.cc
changeset 141 d2dc99c319b6
parent 125 7ec16536bc87
child 149 05ca171a3d57
--- a/stage4/generate_c/generate_c_sfc.cc	Sun Sep 07 10:08:11 2008 +0200
+++ b/stage4/generate_c/generate_c_sfc.cc	Mon Sep 08 10:33:37 2008 +0200
@@ -53,6 +53,7 @@
     typedef enum {
       transitionlist_sg,
       transitiontest_sg,
+      transitiontestdebug_sg,
       stepset_sg,
       stepreset_sg,
       actionassociation_sg,
@@ -112,7 +113,7 @@
 
     void print_step_argument(symbol_c *step_name, const char* argument) {
       print_variable_prefix();
-      s4o.print("step_list[");
+      s4o.print("__step_list[");
       s4o.print(SFC_STEP_ACTION_PREFIX);
       step_name->accept(*this);
       s4o.print("].");
@@ -121,7 +122,7 @@
 
     void print_action_argument(symbol_c *action_name, const char* argument) {
       print_variable_prefix();
-      s4o.print("action_list[");
+      s4o.print("__action_list[");
       s4o.print(SFC_STEP_ACTION_PREFIX);
       action_name->accept(*this);
       s4o.print("].");
@@ -262,7 +263,7 @@
           if (symbol->integer != NULL) {
             s4o.print(s4o.indent_spaces + "if (");
             print_variable_prefix();
-            s4o.print("transition_list[");
+            s4o.print("__transition_list[");
             print_transition_number();
             s4o.print("]) {\n");
             s4o.indent_right();
@@ -273,11 +274,20 @@
             s4o.print(s4o.indent_spaces + "}\n");
           }
           s4o.indent_left();
-          s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n");
+          s4o.print(s4o.indent_spaces + "}\n");
+          s4o.print(s4o.indent_spaces + "else {\n");
           s4o.indent_right();
+          // Calculate transition value for debug
+          s4o.print(s4o.indent_spaces + "if (__DEBUG) {\n");
+          s4o.indent_right();
+          wanted_sfcgeneration = transitiontestdebug_sg;
+          symbol->transition_condition->accept(*this);
+          wanted_sfcgeneration = transitiontest_sg;
+          s4o.indent_left();
+          s4o.print(s4o.indent_spaces + "}\n");
           s4o.print(s4o.indent_spaces);
           print_variable_prefix();
-          s4o.print("transition_list[");
+          s4o.print("__transition_list[");
           print_transition_number();
           s4o.print("] = 0;\n");
           s4o.indent_left();
@@ -286,7 +296,7 @@
         case stepset_sg:
           s4o.print(s4o.indent_spaces + "if (");
           print_variable_prefix();
-          s4o.print("transition_list[");
+          s4o.print("__transition_list[");
           print_transition_number();
           s4o.print("]) {\n");
           s4o.indent_right();
@@ -299,7 +309,7 @@
           if (symbol->integer == NULL) {
             s4o.print(s4o.indent_spaces + "if (");
             print_variable_prefix();
-            s4o.print("transition_list[");
+            s4o.print("__transition_list[");
             print_transition_number();
             s4o.print("]) {\n");
             s4o.indent_right();
@@ -318,12 +328,17 @@
     void *visit(transition_condition_c *symbol) {
       switch (wanted_sfcgeneration) {
         case transitiontest_sg:
+        case transitiontestdebug_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();
+            if (wanted_sfcgeneration == transitiontestdebug_sg)
+              s4o.print("__debug_");
+            else
+              s4o.print("__");
             s4o.print("transition_list[");
             print_transition_number();
             s4o.print("] = ");
@@ -334,12 +349,31 @@
           if (symbol->transition_condition_st != NULL) {
             s4o.print(s4o.indent_spaces);
             print_variable_prefix();
+            if (wanted_sfcgeneration == transitiontestdebug_sg)
+              s4o.print("__debug_");
+            else
+              s4o.print("__");
             s4o.print("transition_list[");
             print_transition_number();
             s4o.print("] = ");
             symbol->transition_condition_st->accept(*generate_c_st);
             s4o.print(";\n");
           }
+          if (wanted_sfcgeneration == transitiontest_sg) {
+            s4o.print(s4o.indent_spaces + "if (__DEBUG) {\n");
+            s4o.indent_right();
+            s4o.print(s4o.indent_spaces);
+            print_variable_prefix();
+            s4o.print("__debug_transition_list[");
+            print_transition_number();
+            s4o.print("] = ");
+            print_variable_prefix();
+            s4o.print("__transition_list[");
+            print_transition_number();
+            s4o.print("];\n");
+            s4o.indent_left();
+            s4o.print(s4o.indent_spaces + "}\n");
+          }
           break;
         default:
           break;
@@ -352,7 +386,7 @@
         case actionbody_sg:
           s4o.print(s4o.indent_spaces + "if(");
           print_variable_prefix();
-          s4o.print("action_list[");
+          s4o.print("__action_list[");
           s4o.print(SFC_STEP_ACTION_PREFIX);
           symbol->action_name->accept(*this);
           s4o.print("].state) {\n");
@@ -591,31 +625,31 @@
       s4o.print(s4o.indent_spaces +"current_time = __CURRENT_TIME;\n");
       s4o.print(s4o.indent_spaces +"elapsed_time = __time_sub(current_time, ");
       print_variable_prefix();
-      s4o.print("lasttick_time);\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("lasttick_time = current_time;\n");
+      s4o.print("__lasttick_time);\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__lasttick_time = current_time;\n");
       
       /* generate step initialisations */
       s4o.print(s4o.indent_spaces + "// Steps initialisation\n");
       s4o.print(s4o.indent_spaces + "for (i = 0; i < ");
       print_variable_prefix();
-      s4o.print("nb_steps; i++) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("step_list[i].prev_state = ");
-      print_variable_prefix();
-      s4o.print("step_list[i].state;\n");
+      s4o.print("__nb_steps; i++) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__step_list[i].prev_state = ");
+      print_variable_prefix();
+      s4o.print("__step_list[i].state;\n");
       s4o.print(s4o.indent_spaces + "if (");
       print_variable_prefix();
-      s4o.print("step_list[i].state) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("step_list[i].elapsed_time = __time_add(");
-      print_variable_prefix();
-      s4o.print("step_list[i].elapsed_time, elapsed_time);\n");
+      s4o.print("__step_list[i].state) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__step_list[i].elapsed_time = __time_add(");
+      print_variable_prefix();
+      s4o.print("__step_list[i].elapsed_time, elapsed_time);\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n");
       s4o.indent_left();
@@ -625,38 +659,38 @@
       s4o.print(s4o.indent_spaces + "// Actions initialisation\n");
       s4o.print(s4o.indent_spaces + "for (i = 0; i < ");
       print_variable_prefix();
-      s4o.print("nb_actions; i++) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].state = 0;\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set = 0;\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset = 0;\n");
+      s4o.print("__nb_actions; i++) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].state = 0;\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set = 0;\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset = 0;\n");
       s4o.print(s4o.indent_spaces + "if (");
       s4o.print("__gt_TIME(2, ");
       print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time = __time_sub(");
-      print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time, elapsed_time);\n");
+      s4o.print("__action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set_remaining_time = __time_sub(");
+      print_variable_prefix();
+      s4o.print("__action_list[i].set_remaining_time, elapsed_time);\n");
       s4o.print(s4o.indent_spaces + "if (");
       s4o.print("__le_TIME(2, ");
       print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set = 1;\n");
+      s4o.print("__action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set = 1;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n");
       s4o.indent_left();
@@ -664,24 +698,24 @@
       s4o.print(s4o.indent_spaces + "if (");
       s4o.print("__gt_TIME(2, ");
       print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time = __time_sub(");
-      print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time, elapsed_time);\n");
+      s4o.print("__action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset_remaining_time = __time_sub(");
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset_remaining_time, elapsed_time);\n");
       s4o.print(s4o.indent_spaces + "if (");
       s4o.print("__le_TIME(2, ");
       print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset = 1;\n");
+      s4o.print("__action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset = 1;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n");
       s4o.indent_left();
@@ -721,33 +755,33 @@
       s4o.print(s4o.indent_spaces + "// Actions state evaluation\n");
       s4o.print(s4o.indent_spaces + "for (i = 0; i < ");
       print_variable_prefix();
-      s4o.print("nb_actions; i++) {\n");
+      s4o.print("__nb_actions; i++) {\n");
       s4o.indent_right();
       s4o.print(s4o.indent_spaces + "if (");
       print_variable_prefix();
-      s4o.print("action_list[i].set) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].stored = 1;\n");
+      s4o.print("__action_list[i].set) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].stored = 1;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "if (");
       print_variable_prefix();
-      s4o.print("action_list[i].reset) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].stored = 0;\n");
+      s4o.print("__action_list[i].reset) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].stored = 0;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces);
       print_variable_prefix();
-      s4o.print("action_list[i].state |= ");
-      print_variable_prefix();
-      s4o.print("action_list[i].stored;\n");
+      s4o.print("__action_list[i].state |= ");
+      print_variable_prefix();
+      s4o.print("__action_list[i].stored;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n\n");