Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
authorMario de Sousa <msousa@fe.up.pt>
Wed, 13 Feb 2013 18:56:25 +0000
changeset 810 d9c48ad646f1
parent 809 9204559768f1
child 811 970c582885bf
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
absyntax/absyntax.def
absyntax_utils/function_param_iterator.cc
absyntax_utils/search_base_type.cc
absyntax_utils/search_base_type.hh
absyntax_utils/search_fb_instance_decl.cc
absyntax_utils/search_var_instance_decl.cc
absyntax_utils/spec_init_separator.cc
absyntax_utils/spec_init_separator.hh
stage1_2/iec_bison.yy
stage3/fill_candidate_datatypes.cc
stage3/fill_candidate_datatypes.hh
stage3/narrow_candidate_datatypes.cc
stage3/narrow_candidate_datatypes.hh
stage4/generate_c/generate_c.cc
stage4/generate_c/generate_c_vardecl.cc
stage4/generate_c/generate_var_list.cc
stage4/generate_iec/generate_iec.cc
--- a/absyntax/absyntax.def	Tue Feb 05 17:40:23 2013 +0000
+++ b/absyntax/absyntax.def	Wed Feb 13 18:56:25 2013 +0000
@@ -445,6 +445,29 @@
 					string_type_declaration_init) /* may be == NULL! */
 
 
+/* helper symbol for fb_name_decl_c */
+/* This symbol/leaf does not exist in the IEC standard syntax as an isolated symbol,
+ * as, for some reason, the standard syntax defines FB variable declarations in a slightly 
+ * different style as all other spec_init declarations. I.e., fr FBs variable declarations, 
+ * the standard defines a single leaf/node (fb_name_decl) that references:
+ *   a) the variable name list
+ *   b) the FB datatype
+ *   c) the FB intial value
+ *
+ * All other variable declarations break this out into two nodes:
+ *   1) references b) and c) above (usually named ***_spec_init)
+ *   2) references a), and node 1)
+ *
+ * In order to allow the datatype analyses to proceed without special cases, we will handle
+ * FB variable declarations in the same style. For this reason, we have added the
+ * following node to the Abstract Syntax Tree, even though it does not have a direct equivalent in 
+ * the standard syntax.
+ */
+/*  function_block_type_name ASSIGN structure_initialization */
+/* structure_initialization -> may be NULL ! */
+SYM_REF2(fb_spec_init_c, function_block_type_name, structure_initialization)
+
+
 /*********************/
 /* B 1.4 - Variables */
 /*********************/
@@ -569,8 +592,13 @@
 SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure)
 
 /* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
+/* NOTE: in order to allow datatype handling to proceed using the normal algorithm with no special cases,
+ * we will be storing the 
+ *    function_block_type_name ASSIGN structure_initialization
+ * componentes inside a new node, namely fb_spec_init_c
+ */
 /* structure_initialization -> may be NULL ! */
-SYM_REF3(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization)
+SYM_REF2(fb_name_decl_c, fb_name_list, fb_spec_init)
 
 /* fb_name_list ',' fb_name */
 SYM_LIST(fb_name_list_c)
--- a/absyntax_utils/function_param_iterator.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/absyntax_utils/function_param_iterator.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -467,8 +467,8 @@
 // SYM_REF3(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization)
 void *function_param_iterator_c::visit(fb_name_decl_c *symbol) {
   TRACE("structured_var_init_decl_c");
-  current_param_default_value = symbol->structure_initialization ; 
-  current_param_type          = symbol->function_block_type_name ;
+  current_param_default_value = spec_init_sperator_c::get_init(symbol->fb_spec_init); 
+  current_param_type          = spec_init_sperator_c::get_spec(symbol->fb_spec_init);
 
   return symbol->fb_name_list->accept(*this);
 }
--- a/absyntax_utils/search_base_type.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/absyntax_utils/search_base_type.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -373,19 +373,15 @@
 void *search_base_type_c::visit(string_type_declaration_c *symbol)	                {return (void *)symbol;}
 
 
-/******************************************/
-/* B 1.4.3 - Declaration & Initialisation */
-/******************************************/
-/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
+/*  function_block_type_name ASSIGN structure_initialization */
 /* structure_initialization -> may be NULL ! */
-// SYM_REF3(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization)
-// NOTE: Although the fb_name_decl_c is in section ( B 1.4.3 - Declaration & Initialisation), it is also acting
-//       as a datatype declaration, so we need to handle it here!
-void *search_base_type_c::visit(fb_name_decl_c *symbol)	{
+// SYM_REF2(fb_spec_init_c, function_block_type_name, structure_initialization)
+void *search_base_type_c::visit(fb_spec_init_c *symbol)	{
   return symbol->function_block_type_name->accept(*this);
 }
 
 
+
 /*****************************/
 /* B 1.5.2 - Function Blocks */
 /*****************************/
--- a/absyntax_utils/search_base_type.hh	Tue Feb 05 17:40:23 2013 +0000
+++ b/absyntax_utils/search_base_type.hh	Wed Feb 13 18:56:25 2013 +0000
@@ -234,12 +234,9 @@
   */
     void *visit(string_type_declaration_c *symbol);
 
-  /******************************************/
-  /* B 1.4.3 - Declaration & Initialisation */
-  /******************************************/
-  /* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
+  /* function_block_type_name ASSIGN structure_initialization */
   /* structure_initialization -> may be NULL ! */
-    void *visit(fb_name_decl_c *symbol);
+    void *visit(fb_spec_init_c *symbol);
     
   /*****************************/
   /* B 1.5.2 - Function Blocks */
--- a/absyntax_utils/search_fb_instance_decl.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/absyntax_utils/search_fb_instance_decl.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -87,7 +87,7 @@
 /* name_list ':' function_block_type_name ASSIGN structure_initialization */
 /* structure_initialization -> may be NULL ! */
 void *search_fb_instance_decl_c::visit(fb_name_decl_c *symbol) {
-  current_fb_type_name = symbol->function_block_type_name;
+  current_fb_type_name = spec_init_sperator_c::get_spec(symbol->fb_spec_init);
   return symbol->fb_name_list->accept(*this);
 }
 
--- a/absyntax_utils/search_var_instance_decl.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/absyntax_utils/search_var_instance_decl.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -340,7 +340,11 @@
 /* name_list ':' function_block_type_name ASSIGN structure_initialization */
 /* structure_initialization -> may be NULL ! */
 void *search_var_instance_decl_c::visit(fb_name_decl_c *symbol) {
-  current_type_decl = symbol->function_block_type_name;
+  // TODO: The following line is wrong! It should be
+  // current_type_decl = symbol->fb_spec_init;
+  //  However, this change will require a check of all callers, to see if they would handle this correctly.
+  //  For now, just keep what we have had historically, and seems to be working.
+  current_type_decl = spec_init_sperator_c::get_spec(symbol->fb_spec_init);
   return symbol->fb_name_list->accept(*this);
 }
 
--- a/absyntax_utils/spec_init_separator.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/absyntax_utils/spec_init_separator.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -158,24 +158,23 @@
   return NULL;
 }
 
+/*  function_block_type_name ASSIGN structure_initialization */
+/* structure_initialization -> may be NULL ! */
+//SYM_REF2(fb_spec_init_c, function_block_type_name, structure_initialization)
+void *spec_init_sperator_c::visit(fb_spec_init_c *symbol) {
+  TRACE("spec_init_sperator_c::fb_spec_init_c");
+  switch (search_what) {
+    case search_spec: return symbol->function_block_type_name;
+    case search_init: return symbol->structure_initialization;
+  }
+  ERROR; /* should never occur */
+  return NULL;
+}
 
 /******************************************/
 /* B 1.4.3 - Declaration & Initialisation */
 /******************************************/
 
-/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
-/* structure_initialization -> may be NULL ! */
-void *spec_init_sperator_c::visit(fb_name_decl_c *symbol) {
-  TRACE("spec_init_sperator_c::fb_name_decl_c");
-  switch (search_what) {
-    case search_spec: return symbol->function_block_type_name;
-    case search_init: return symbol->structure_initialization;
-  }
-  ERROR; /* should never occur */
-  return NULL;
-}
-
-
 /* STRING '[' integer ']' 
  * STRING ASSIGN single_byte_character_string
  * STRING '[' integer ']' ASSIGN single_byte_character_string
--- a/absyntax_utils/spec_init_separator.hh	Tue Feb 05 17:40:23 2013 +0000
+++ b/absyntax_utils/spec_init_separator.hh	Wed Feb 13 18:56:25 2013 +0000
@@ -93,15 +93,16 @@
   //SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
   void *visit(initialized_structure_c *symbol);
   
-  
+  /*  function_block_type_name ASSIGN structure_initialization */
+  /* structure_initialization -> may be NULL ! */
+  //SYM_REF2(fb_spec_init_c, function_block_type_name, structure_initialization)
+  void *visit(fb_spec_init_c *symbol);
+
+
   /******************************************/
   /* B 1.4.3 - Declaration & Initialisation */
   /******************************************/
   
-  /* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
-  /* structure_initialization -> may be NULL ! */
-  void *visit(fb_name_decl_c *symbol);
-  
   /* STRING '[' integer ']' 
    * STRING ASSIGN single_byte_character_string
    * STRING '[' integer ']' ASSIGN single_byte_character_string
--- a/stage1_2/iec_bison.yy	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage1_2/iec_bison.yy	Wed Feb 13 18:56:25 2013 +0000
@@ -3598,10 +3598,10 @@
 fb_name_decl:
 /*  fb_name_list ':' function_block_type_name */
   fb_name_list_with_colon function_block_type_name
-	{$$ = new fb_name_decl_c($1, $2, NULL, locloc(@$));}
+	{$$ = new fb_name_decl_c($1, new fb_spec_init_c($2, NULL,locloc(@2)), locloc(@$));}
 /*| fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
 | fb_name_list_with_colon function_block_type_name ASSIGN structure_initialization
-	{$$ = new fb_name_decl_c($1, $2, $4, locloc(@$));}
+	{$$ = new fb_name_decl_c($1, new fb_spec_init_c($2, $4, locf(@2), locl(@4)), locloc(@$));}
 /* ERROR_CHECK_BEGIN */
 | fb_name_list_with_colon ASSIGN structure_initialization
 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "no function block type name defined in function block declaration with initialization."); yynerrs++;}
@@ -4042,7 +4042,7 @@
 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
 	}
 | global_var_name ':' function_block_type_name
-	{$$ = new external_declaration_c($1, $3, locloc(@$));
+	{$$ = new external_declaration_c($1, new fb_spec_init_c($3, NULL, locloc(@3)), locloc(@$));
 	 variable_name_symtable.insert($1, prev_declared_fb_name_token);
 	}
 /* ERROR_CHECK_BEGIN */
@@ -4136,7 +4136,7 @@
   global_var_spec ':' located_var_spec_init
 	{$$ = new global_var_decl_c($1, $3, locloc(@$));}
 | global_var_spec ':' function_block_type_name
-	{$$ = new global_var_decl_c($1, $3, locloc(@$));}
+	{$$ = new global_var_decl_c($1, new fb_spec_init_c($3, NULL, locloc(@3)), locloc(@$));}
 /* ERROR_CHECK_BEGIN */
 | global_var_list located_var_spec_init
 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between global variable list and type specification."); yynerrs++;}
--- a/stage3/fill_candidate_datatypes.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage3/fill_candidate_datatypes.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -1061,6 +1061,11 @@
 // SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) 
 
 
+/*  function_block_type_name ASSIGN structure_initialization */
+/* structure_initialization -> may be NULL ! */
+// SYM_REF2(fb_spec_init_c, function_block_type_name, structure_initialization)
+void *fill_candidate_datatypes_c::visit(fb_spec_init_c *symbol) {return fill_spec_init(symbol, symbol->function_block_type_name, symbol->structure_initialization);}
+
 
 
 /*********************/
@@ -1255,15 +1260,6 @@
 
 
 
-/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
-/* structure_initialization -> may be NULL ! */
-// SYM_REF3(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization)
-// NOTE: Although the fb_name_decl_c is in section ( B 1.4.3 - Declaration & Initialisation), it is also acting
-//       as a datatype declaration, so we need to handle it here!
-void *fill_candidate_datatypes_c::visit(fb_name_decl_c *symbol) {return fill_spec_init(symbol, symbol->function_block_type_name, symbol->structure_initialization);}
-
-
-
 /************************************/
 /* B 1.5 Program organization units */
 /************************************/
--- a/stage3/fill_candidate_datatypes.hh	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage3/fill_candidate_datatypes.hh	Wed Feb 13 18:56:25 2013 +0000
@@ -194,6 +194,7 @@
 //  void *visit(structure_element_initialization_list_c *symbol);
 //  void *visit(structure_element_initialization_c *symbol);
 //  void *visit(string_type_declaration_c *symbol);
+    void *visit(fb_spec_init_c *symbol);
 
     
     /*********************/
@@ -218,7 +219,6 @@
     void *visit(var1_list_c *symbol);
     void *visit(location_c *symbol);
     void *visit(located_var_decl_c *symbol);
-    void *visit(fb_name_decl_c *symbol);
 
     /**************************************/
     /* B 1.5 - Program organization units */
--- a/stage3/narrow_candidate_datatypes.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage3/narrow_candidate_datatypes.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -640,6 +640,10 @@
 // SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) 
 
 
+/* structure_type_name ASSIGN structure_initialization */
+/* structure_initialization may be NULL ! */
+// SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
+void *narrow_candidate_datatypes_c::visit(fb_spec_init_c *symbol) {return narrow_spec_init(symbol, symbol->function_block_type_name, symbol->structure_initialization);}
 
 
 /*********************/
@@ -718,13 +722,6 @@
 }
 
 
-/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
-/* structure_initialization -> may be NULL ! */
-// SYM_REF3(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization)
-// NOTE: Although the fb_name_decl_c is in section ( B 1.4.3 - Declaration & Initialisation), it is also acting
-//       as a datatype declaration, so we need to handle it here!
-void *narrow_candidate_datatypes_c::visit(fb_name_decl_c *symbol) {return narrow_spec_init(symbol, symbol->function_block_type_name, symbol->structure_initialization);}
-
 
 /************************************/
 /* B 1.5 Program organization units */
--- a/stage3/narrow_candidate_datatypes.hh	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage3/narrow_candidate_datatypes.hh	Wed Feb 13 18:56:25 2013 +0000
@@ -176,6 +176,7 @@
 //  void *visit(structure_element_initialization_list_c *symbol);
 //  void *visit(structure_element_initialization_c *symbol);
 //  void *visit(string_type_declaration_c *symbol);
+    void *visit(fb_spec_init_c *symbol);
 
     /*********************/
     /* B 1.4 - Variables */
@@ -195,7 +196,6 @@
     void *visit(var1_list_c *symbol);
     void *visit(location_c *symbol);
     void *visit(located_var_decl_c *symbol);
-    void *visit(fb_name_decl_c *symbol);
 
     /**************************************/
     /* B 1.5 - Program organization units */
--- a/stage4/generate_c/generate_c.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage4/generate_c/generate_c.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -299,7 +299,7 @@
     //void *visit(var_declaration_list_c *symbol) {iterate through list}
 
     void *visit(fb_name_decl_c *symbol) {
-      print_list(symbol->fb_name_list, symbol->function_block_type_name); 
+      print_list(symbol->fb_name_list, spec_init_sperator_c::get_spec(symbol->fb_spec_init)); 
       return NULL;
     }
 
--- a/stage4/generate_c/generate_c_vardecl.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage4/generate_c/generate_c_vardecl.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -1483,7 +1483,7 @@
   /* Start off by setting the current_var_type_symbol and
    * current_var_init_symbol private variables...
    */
-  update_type_init(symbol);
+  update_type_init(symbol->fb_spec_init);
 
   /* now to produce the c equivalent... */
   symbol->fb_name_list->accept(*this);
--- a/stage4/generate_c/generate_var_list.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage4/generate_c/generate_var_list.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -603,7 +603,7 @@
       /* Start off by setting the current_var_type_symbol and
        * current_var_init_symbol private variables...
        */
-      update_var_type_symbol(symbol);
+      update_var_type_symbol(symbol->fb_spec_init);
     
       /* now to produce the c equivalent... */
       declare_variables(symbol->fb_name_list);
--- a/stage4/generate_iec/generate_iec.cc	Tue Feb 05 17:40:23 2013 +0000
+++ b/stage4/generate_iec/generate_iec.cc	Wed Feb 13 18:56:25 2013 +0000
@@ -633,7 +633,16 @@
   return NULL;
 }
 
-
+/*  function_block_type_name ASSIGN structure_initialization */
+/* structure_initialization -> may be NULL ! */
+void *visit(fb_spec_init_c *symbol) {
+  symbol->function_block_type_name->accept(*this);
+  if (symbol->structure_initialization != NULL) {
+    s4o.print(" := ");
+    symbol->structure_initialization->accept(*this);
+  }
+  return NULL;
+}
 
 
 
@@ -812,11 +821,7 @@
 void *visit(fb_name_decl_c *symbol) {
   symbol->fb_name_list->accept(*this);
   s4o.print(" : ");
-  symbol->function_block_type_name->accept(*this);
-  if (symbol->structure_initialization != NULL) {
-    s4o.print(" := ");
-    symbol->structure_initialization->accept(*this);
-  }
+  symbol->fb_spec_init->accept(*this);
   return NULL;
 }