Adding init function on functionBlock
authoretisserant
Thu, 10 May 2007 17:39:50 +0200
changeset 23 d5b55ac4efe6
parent 22 08bcc40be1fa
child 24 7e830409f72a
Adding init function on functionBlock
stage4/generate_cc/generate_cc.cc
stage4/generate_cc/generate_cc_vardecl.cc
--- a/stage4/generate_cc/generate_cc.cc	Wed Apr 18 16:43:18 2007 +0200
+++ b/stage4/generate_cc/generate_cc.cc	Thu May 10 17:39:50 2007 +0200
@@ -146,6 +146,9 @@
 
 #define FB_FUNCTION_SUFFIX "_body__"
 
+/* Idem as body, but for initializer FB function */
+#define FB_INIT_SUFFIX "_init__"
+
 /* The FB body function is passed as the only parameter a pointer to the FB data
  * structure instance. The name of this parameter is given by the following constant.
  * In order not to clash with any variable in the IL and ST source codem the
@@ -524,9 +527,10 @@
   s4o.print(s4o.indent_spaces + "// FB private variables - TEMP, private and located variables\n");
   vardecl = new generate_cc_vardecl_c(&s4o,
   				      generate_cc_vardecl_c::local_vf,
-				        generate_cc_vardecl_c::temp_vt |
+				      generate_cc_vardecl_c::temp_vt |
   				      generate_cc_vardecl_c::private_vt |
-  				      generate_cc_vardecl_c::located_vt);
+  				      generate_cc_vardecl_c::located_vt |
+  				      generate_cc_vardecl_c::external_vt);
   vardecl->print(symbol->var_declarations);
   delete vardecl;
   s4o.print("\n");
@@ -538,6 +542,47 @@
   s4o.print(";\n\n");
 
 
+
+
+
+
+
+
+
+
+  /* (B) Constructor */
+  /* (B.1) Constructor name... */
+  s4o.print(s4o.indent_spaces + "void ");
+  symbol->fblock_name->accept(*this);
+  s4o.print(FB_INIT_SUFFIX);
+  s4o.print("(");
+
+  /* first and only parameter is a pointer to the data */
+  symbol->fblock_name->accept(*this);
+  s4o.print(" *");
+  s4o.print(FB_FUNCTION_PARAM);
+  s4o.print(") {\n");
+  s4o.indent_right();
+
+  /* (B.2) Member initializations... */
+  s4o.print(s4o.indent_spaces);
+  vardecl = new generate_cc_vardecl_c(&s4o,
+  				      generate_cc_vardecl_c::constructorinit_vf,
+  				      generate_cc_vardecl_c::input_vt |
+  				      generate_cc_vardecl_c::output_vt |
+  				      generate_cc_vardecl_c::inoutput_vt |
+  				      generate_cc_vardecl_c::private_vt |
+				      generate_cc_vardecl_c::external_vt);
+  vardecl->print(symbol->var_declarations, NULL,  FB_FUNCTION_PARAM"->");
+  delete vardecl;
+  s4o.indent_left();
+  s4o.print("\n" + s4o.indent_spaces + "}\n\n");
+
+  
+
+
+
+
   /* (B) Function with FB body */
   /* (B.1) Function declaration */
   s4o.print("// Code part\n");
--- a/stage4/generate_cc/generate_cc_vardecl.cc	Wed Apr 18 16:43:18 2007 +0200
+++ b/stage4/generate_cc/generate_cc_vardecl.cc	Thu May 10 17:39:50 2007 +0200
@@ -273,7 +273,7 @@
     /* Note that located variables are the exception, they
      * being declared in the located_var_decl_c visitor...
      */
-    void *declare_variables(symbol_c *symbol) {
+    void *declare_variables(symbol_c *symbol, bool is_fb = false) {
       list_c *list = dynamic_cast<list_c *>(symbol);
       /* should NEVER EVER occur!! */
       if (list == NULL) ERROR;
@@ -288,7 +288,7 @@
             this->current_var_type_symbol->accept(*this);
             s4o.print(" ");
           }
-          this->print_variable_prefix();
+          print_variable_prefix();
           list->elements[i]->accept(*this);
           if (wanted_varformat != local_vf) {
             if (this->current_var_init_symbol != NULL) {
@@ -323,12 +323,22 @@
 
       if (wanted_varformat == constructorinit_vf) {
         for(int i = 0; i < list->n; i++) {
-          if (this->current_var_init_symbol != NULL) {
+          if (is_fb) {
             s4o.print(nv->get());
+            this->current_var_type_symbol->accept(*this);
+            s4o.print(FB_INIT_SUFFIX);
+            s4o.print("(");
+            this->print_variable_prefix();
             list->elements[i]->accept(*this);
-            s4o.print("(");
+            s4o.print(");");
+          }
+          else if (this->current_var_init_symbol != NULL) {
+            s4o.print(nv->get());
+            this->print_variable_prefix();
+            list->elements[i]->accept(*this);
+            s4o.print(" = ");
             this->current_var_init_symbol->accept(*this);
-            s4o.print(")");
+            s4o.print(";");
           }
         }
       }
@@ -362,7 +372,7 @@
       finterface_var_count = 0;
 
       switch (wanted_varformat) {
-        case constructorinit_vf: nv = new next_var_c(": ", ", "); break;
+        case constructorinit_vf: nv = new next_var_c("", "\n"+s4o.indent_spaces); break;
         case finterface_vf:      /* fall through... */
         case localinit_vf:       /* fall through... */
         case local_vf:           nv = new next_var_c("", ", "); break;
@@ -562,7 +572,7 @@
 /* fb_name_list ',' fb_name */
 void *visit(fb_name_list_c *symbol) {
   TRACE("fb_name_list_c");
-  declare_variables(symbol);
+  declare_variables(symbol, true);
   return NULL;
 }
 
@@ -830,9 +840,8 @@
     case local_vf:
     case localinit_vf:
       s4o.print(s4o.indent_spaces);
-      s4o.print("__ext_ref_c<");
       this->current_var_type_symbol->accept(*this);
-      s4o.print("> &");
+      s4o.print(" *");
       symbol->global_var_name->accept(*this);
       if ((wanted_varformat == localinit_vf) &&
           (this->current_var_init_symbol != NULL)) {
@@ -844,18 +853,21 @@
 
     case constructorinit_vf:
       s4o.print(nv->get());
+      s4o.print("{extern ");
       symbol->global_var_name->accept(*this);
-      s4o.print("(*");
+      s4o.print(";");
+      print_variable_prefix();
       symbol->global_var_name->accept(*this);
-      s4o.print(")");
+      s4o.print(" = &");
+      symbol->global_var_name->accept(*this);
+      s4o.print(";}");
       break;
 
     case finterface_vf:
       finterface_var_count++;
       s4o.print(nv->get());
-      s4o.print("__ext_ref_c<");
       this->current_var_type_symbol->accept(*this);
-      s4o.print("> *");
+      s4o.print(" *");
       symbol->global_var_name->accept(*this);
       break;
 
@@ -1440,6 +1452,7 @@
         break;
 
       case function_param_iterator_c::direction_extref:
+#if 0
         if (param_value == NULL)
 	  /* This is illegal in ST and IL languages.
 	   * All variables declared in a VAR_EXTERNAL __must__
@@ -1452,6 +1465,7 @@
         s4o.print(nv->get());
         s4o.print("&");
         param_value->accept(*this);
+#endif
 	break;
 #if 0
         if (param_value == NULL) {