Fix bug (introduced a few commits ago) when generating SFC actions that are mapped onto variables --> Make generate_sfcdecl_c stateless (i.e. does not depend on order by which it is called).
authormjsousa
Wed, 06 Aug 2014 10:43:15 +0100
changeset 920 4369ce5e687f
parent 919 8da635655f37
child 921 d228aaa4d616
Fix bug (introduced a few commits ago) when generating SFC actions that are mapped onto variables --> Make generate_sfcdecl_c stateless (i.e. does not depend on order by which it is called).
stage4/generate_c/generate_c.cc
stage4/generate_c/generate_c_sfcdecl.cc
--- a/stage4/generate_c/generate_c.cc	Thu Jul 31 17:49:44 2014 +0100
+++ b/stage4/generate_c/generate_c.cc	Wed Aug 06 10:43:15 2014 +0100
@@ -1214,16 +1214,12 @@
         /* (B.3) Generate private internal variables for SFC */
         sfcdecl = new generate_c_sfcdecl_c(&s4o, symbol, FB_FUNCTION_PARAM"->");
         sfcdecl->generate(symbol->fblock_body, generate_c_sfcdecl_c::sfcinit_sd);
-        delete sfcdecl;
       
         s4o.indent_left();
         s4o.print(s4o.indent_spaces + "}\n\n");
-      }    
-      
-      if (!print_declaration) {
+
         /* (C) Function with FB body */
         /* (C.1) Step definitions */
-        sfcdecl = new generate_c_sfcdecl_c(&s4o, symbol, FB_FUNCTION_PARAM"->");
         sfcdecl->generate(symbol->fblock_body, generate_c_sfcdecl_c::stepdef_sd);
       
         /* (C.2) Action definitions */
--- a/stage4/generate_c/generate_c_sfcdecl.cc	Thu Jul 31 17:49:44 2014 +0100
+++ b/stage4/generate_c/generate_c_sfcdecl.cc	Wed Aug 06 10:43:15 2014 +0100
@@ -195,6 +195,12 @@
           for(int i = 0; i < symbol->n; i++)
              symbol->elements[i]->accept(*this);
           {
+            // first fill up the this->variable_list variable!
+            wanted_sfcdeclaration = actioncount_sd;
+            for(int i = 0; i < symbol->n; i++)
+               symbol->elements[i]->accept(*this);
+            wanted_sfcdeclaration = actiondef_sd;
+            // Now do the defines for actions that reference a variable instead of an action block!
             std::list<VARIABLE>::iterator pt;
             for(pt = variable_list.begin(); pt != variable_list.end(); pt++) {
               s4o.print("#define ");
@@ -216,7 +222,14 @@
           break;
         case actionundef_sd:
           s4o.print("// Actions undefinitions\n");
+          for(int i = 0; i < symbol->n; i++)
+            symbol->elements[i]->accept(*this);
           {
+            // first fill up the this->variable_list variable!
+            wanted_sfcdeclaration = actioncount_sd;
+            for(int i = 0; i < symbol->n; i++)
+               symbol->elements[i]->accept(*this);
+            wanted_sfcdeclaration = actionundef_sd;
             std::list<VARIABLE>::iterator pt;
             for(pt = variable_list.begin(); pt != variable_list.end(); pt++) {
               s4o.print("#undef ");
@@ -225,8 +238,6 @@
               s4o.print("\n");
             }
           }
-          for(int i = 0; i < symbol->n; i++)
-            symbol->elements[i]->accept(*this);
           s4o.print("\n");
           break;
         default:
@@ -331,9 +342,8 @@
     void *visit(action_association_c *symbol) {
       /* we try to find the variable instance declaration, to determine if symbol is variable... */
       symbol_c *var_decl = search_var_instance_decl->get_decl(symbol->action_name);
-
       if (var_decl != NULL) {
-    	std::list<VARIABLE>::iterator pt;
+        std::list<VARIABLE>::iterator pt;
         for(pt = variable_list.begin(); pt != variable_list.end(); pt++) {
           if (!compare_identifiers(pt->symbol, symbol->action_name))
             return NULL;