Moving get_var_name_c into its own file.
authorMario de Sousa <msousa@fe.up.pt>
Mon, 16 Apr 2012 15:10:31 +0100
changeset 511 b22ae67d8003
parent 510 9317e04c1dde
child 512 f915ab676d7e
Moving get_var_name_c into its own file.
absyntax_utils/Makefile.am
absyntax_utils/Makefile.in
absyntax_utils/absyntax_utils.hh
absyntax_utils/get_var_name.cc
absyntax_utils/get_var_name.hh
absyntax_utils/search_var_instance_decl.cc
--- a/absyntax_utils/Makefile.am	Mon Apr 16 14:41:07 2012 +0100
+++ b/absyntax_utils/Makefile.am	Mon Apr 16 15:10:31 2012 +0100
@@ -13,6 +13,7 @@
 	function_param_iterator.cc \
 	get_function_type.cc \
 	get_sizeof_datatype.cc \
+	get_var_name.cc \
 	search_il_label.cc \
 	search_base_type.cc \
 	search_constant_type.cc \
--- a/absyntax_utils/Makefile.in	Mon Apr 16 14:41:07 2012 +0100
+++ b/absyntax_utils/Makefile.in	Mon Apr 16 15:10:31 2012 +0100
@@ -78,8 +78,9 @@
 	function_call_iterator.$(OBJEXT) \
 	function_call_param_iterator.$(OBJEXT) \
 	function_param_iterator.$(OBJEXT) get_function_type.$(OBJEXT) \
-	get_sizeof_datatype.$(OBJEXT) search_il_label.$(OBJEXT) \
-	search_base_type.$(OBJEXT) search_constant_type.$(OBJEXT) \
+	get_sizeof_datatype.$(OBJEXT) get_var_name.$(OBJEXT) \
+	search_il_label.$(OBJEXT) search_base_type.$(OBJEXT) \
+	search_constant_type.$(OBJEXT) \
 	search_expression_type.$(OBJEXT) \
 	search_fb_instance_decl.$(OBJEXT) search_fb_typedecl.$(OBJEXT) \
 	search_varfb_instance_type.$(OBJEXT) \
@@ -213,6 +214,7 @@
 	function_param_iterator.cc \
 	get_function_type.cc \
 	get_sizeof_datatype.cc \
+	get_var_name.cc \
 	search_il_label.cc \
 	search_base_type.cc \
 	search_constant_type.cc \
@@ -315,6 +317,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/function_param_iterator.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get_function_type.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get_sizeof_datatype.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get_var_name.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/search_base_type.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/search_constant_type.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/search_expression_type.Po@am__quote@
--- a/absyntax_utils/absyntax_utils.hh	Mon Apr 16 14:41:07 2012 +0100
+++ b/absyntax_utils/absyntax_utils.hh	Mon Apr 16 15:10:31 2012 +0100
@@ -121,6 +121,7 @@
 #include "get_sizeof_datatype.hh"
 #include "get_function_type.h"
 #include "search_il_label.hh"
+#include "get_var_name.hh"
 
 /***********************************************************************/
 /***********************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/absyntax_utils/get_var_name.cc	Mon Apr 16 15:10:31 2012 +0100
@@ -0,0 +1,120 @@
+/*
+ *  matiec - a compiler for the programming languages defined in IEC 61131-3
+ *
+ *  Copyright (C) 2012  Mario de Sousa (msousa@fe.up.pt)
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * This code is made available on the understanding that it will not be
+ * used in safety-critical situations without a full and competent review.
+ */
+
+/*
+ * An IEC 61131-3 compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ */
+
+/*
+ *  A small helper visitor class, that will   
+ *  return the name (tokn_c *) of a variable, as it will
+ *  appear in the variable declaration.
+ */
+
+/*  For ex.:
+ *       VAR
+ *          A : int;
+ *          B : ARRAY [1..9] of int;
+ *          C : some_struct_t;
+ *       END_VAR
+ *
+ *          A    := 56;
+ *          B[8] := 99;
+ *          C.e  := 77;
+ *
+ *       Calling this visitor class with symbolic_variable_c instance referencing 'A' in
+ *       the line 'A := 56', will return the string "A".
+ *
+ *       Calling this visitor class with array_variable_c instance referencing 'B[8]' in
+ *       the line 'B[8] := 99', will return the string "B".
+ *
+ *       Calling this visitor class with array_variable_c instance referencing 'C.e' in
+ *       the line 'C.e := 77', will return the string "C".
+ */
+
+
+#include "absyntax_utils.hh"
+
+
+
+   
+    
+
+get_var_name_c *get_var_name_c::singleton_instance_ = NULL;
+
+
+
+
+token_c *get_var_name_c::get_name(symbol_c *symbol) {
+  if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c(); 
+  if (NULL == singleton_instance_) ERROR; 
+  
+  return (token_c *)(symbol->accept(*singleton_instance_));
+}
+
+
+/*************************/
+/* B.1 - Common elements */
+/*************************/
+/*******************************************/
+/* B 1.1 - Letters, digits and identifiers */
+/*******************************************/
+// SYM_TOKEN(identifier_c)
+void *get_var_name_c::visit(identifier_c *symbol) {return (void *)symbol;}
+
+/*********************/
+/* B 1.4 - Variables */
+/*********************/
+// SYM_REF2(symbolic_variable_c, var_name, unused)
+void *get_var_name_c::visit(symbolic_variable_c *symbol) {return symbol->var_name->accept(*this);}
+
+/********************************************/
+/* B.1.4.1   Directly Represented Variables */
+/********************************************/
+// SYM_TOKEN(direct_variable_c)
+
+/*************************************/
+/* B.1.4.2   Multi-element Variables */
+/*************************************/
+/*  subscripted_variable '[' subscript_list ']' */
+// SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
+void *get_var_name_c::visit(array_variable_c *symbol) {return symbol->subscripted_variable->accept(*this);}
+
+/* subscript_list ',' subscript */
+// SYM_LIST(subscript_list_c)
+
+/*  record_variable '.' field_selector */
+/*  WARNING: input and/or output variables of function blocks
+ *           may be accessed as fields of a tructured variable!
+ *           Code handling a structured_variable_c must take
+ *           this into account!
+ */
+// SYM_REF2(structured_variable_c, record_variable, field_selector)
+void *get_var_name_c::visit(structured_variable_c *symbol) {return symbol->record_variable->accept(*this);}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/absyntax_utils/get_var_name.hh	Mon Apr 16 15:10:31 2012 +0100
@@ -0,0 +1,115 @@
+/*
+ *  matiec - a compiler for the programming languages defined in IEC 61131-3
+ *
+ *  Copyright (C) 2012  Mario de Sousa (msousa@fe.up.pt)
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * This code is made available on the understanding that it will not be
+ * used in safety-critical situations without a full and competent review.
+ */
+
+/*
+ * An IEC 61131-3 compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ */
+
+/*
+ *  A small helper visitor class, that will   
+ *  return the name (tokn_c *) of a variable, as it will
+ *  appear in the variable declaration.
+ */
+
+/*  For ex.:
+ *       VAR
+ *          A : int;
+ *          B : ARRAY [1..9] of int;
+ *          C : some_struct_t;
+ *       END_VAR
+ *
+ *          A    := 56;
+ *          B[8] := 99;
+ *          C.e  := 77;
+ *
+ *       Calling this visitor class with symbolic_variable_c instance referencing 'A' in
+ *       the line 'A := 56', will return the string "A".
+ *
+ *       Calling this visitor class with array_variable_c instance referencing 'B[8]' in
+ *       the line 'B[8] := 99', will return the string "B".
+ *
+ *       Calling this visitor class with array_variable_c instance referencing 'C.e' in
+ *       the line 'C.e := 77', will return the string "C".
+ */
+
+
+
+
+class get_var_name_c : public search_visitor_c {    
+  public:
+    get_var_name_c(void)  {};
+    ~get_var_name_c(void) {};  
+    static token_c *get_name(symbol_c *symbol);
+
+  private:
+    static get_var_name_c *singleton_instance_;
+    
+  private:  
+    /*************************/
+    /* B.1 - Common elements */
+    /*************************/
+    /*******************************************/
+    /* B 1.1 - Letters, digits and identifiers */
+    /*******************************************/
+    // SYM_TOKEN(identifier_c)
+    void *visit(identifier_c *symbol);
+
+    /*********************/
+    /* B 1.4 - Variables */
+    /*********************/
+    // SYM_REF2(symbolic_variable_c, var_name, unused)
+    void *visit(symbolic_variable_c *symbol);
+
+    /********************************************/
+    /* B.1.4.1   Directly Represented Variables */
+    /********************************************/
+    // SYM_TOKEN(direct_variable_c)
+    // void *visit(direct_variable_c *symbol);
+
+    /*************************************/
+    /* B.1.4.2   Multi-element Variables */
+    /*************************************/
+    /*  subscripted_variable '[' subscript_list ']' */
+    // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
+    void *visit(array_variable_c *symbol);
+
+    /* subscript_list ',' subscript */
+    // SYM_LIST(subscript_list_c)
+    // void *visit(subscript_list_c *symbol);
+
+    /*  record_variable '.' field_selector */
+    /*  WARNING: input and/or output variables of function blocks
+     *           may be accessed as fields of a tructured variable!
+     *           Code handling a structured_variable_c must take
+     *           this into account!
+     */
+    // SYM_REF2(structured_variable_c, record_variable, field_selector)
+    void *visit(structured_variable_c *symbol);
+};
+
+
+
--- a/absyntax_utils/search_var_instance_decl.cc	Mon Apr 16 14:41:07 2012 +0100
+++ b/absyntax_utils/search_var_instance_decl.cc	Mon Apr 16 15:10:31 2012 +0100
@@ -92,140 +92,6 @@
 
 
 
-/**********************************************/
-/*  A small helper visitor class, that will   */
-/*  return the name of a variable, as it will */
-/*  appear in the variable declaration.       */
-/**********************************************/
-/*  For ex.:
- *       VAR
- *          A : int;
- *          B : ARRAY [1..9] of int;
- *          C : some_struct_t;
- *       END_VAR
- *
- *          A    := 56;
- *          B[8] := 99;
- *          C.e  := 77;
- *
- *       Calling this visitor class with symbolic_variable_c instance referencing 'A' in
- *       the line 'A := 56', will return the string "A".
- *
- *       Calling this visitor class with array_variable_c instance referencing 'B[8]' in
- *       the line 'B[8] := 99', will return the string "B".
- *
- *       Calling this visitor class with array_variable_c instance referencing 'C.e' in
- *       the line 'C.e := 77', will return the string "C".
- */
-class get_var_name_c : public search_visitor_c {
-  private:
-    static get_var_name_c *singleton_instance_;
-  public:
-    get_var_name_c(void)  {};
-    ~get_var_name_c(void) {};
-    
-    static token_c *get_name(symbol_c *symbol) {
-      if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c(); 
-      if (NULL == singleton_instance_) ERROR; 
-      
-      return (token_c *)(symbol->accept(*singleton_instance_));
-    }
-    
-  private:  
-    /*************************/
-    /* B.1 - Common elements */
-    /*************************/
-    /*******************************************/
-    /* B 1.1 - Letters, digits and identifiers */
-    /*******************************************/
-    // SYM_TOKEN(identifier_c)
-    void *visit(identifier_c *symbol);
-
-    /*********************/
-    /* B 1.4 - Variables */
-    /*********************/
-    // SYM_REF2(symbolic_variable_c, var_name, unused)
-    void *visit(symbolic_variable_c *symbol);
-
-    /********************************************/
-    /* B.1.4.1   Directly Represented Variables */
-    /********************************************/
-    // SYM_TOKEN(direct_variable_c)
-    // void *visit(direct_variable_c *symbol);
-
-    /*************************************/
-    /* B.1.4.2   Multi-element Variables */
-    /*************************************/
-    /*  subscripted_variable '[' subscript_list ']' */
-    // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
-    void *visit(array_variable_c *symbol);
-
-    /* subscript_list ',' subscript */
-    // SYM_LIST(subscript_list_c)
-    // void *visit(subscript_list_c *symbol);
-
-    /*  record_variable '.' field_selector */
-    /*  WARNING: input and/or output variables of function blocks
-     *           may be accessed as fields of a tructured variable!
-     *           Code handling a structured_variable_c must take
-     *           this into account!
-     */
-    // SYM_REF2(structured_variable_c, record_variable, field_selector)
-    void *visit(structured_variable_c *symbol);
-};
-
-get_var_name_c *get_var_name_c::singleton_instance_ = NULL;
-
-
-
-/*************************/
-/* B.1 - Common elements */
-/*************************/
-/*******************************************/
-/* B 1.1 - Letters, digits and identifiers */
-/*******************************************/
-// SYM_TOKEN(identifier_c)
-void *get_var_name_c::visit(identifier_c *symbol) {return (void *)symbol;}
-
-/*********************/
-/* B 1.4 - Variables */
-/*********************/
-// SYM_REF2(symbolic_variable_c, var_name, unused)
-void *get_var_name_c::visit(symbolic_variable_c *symbol) {return symbol->var_name->accept(*this);}
-
-/********************************************/
-/* B.1.4.1   Directly Represented Variables */
-/********************************************/
-// SYM_TOKEN(direct_variable_c)
-
-/*************************************/
-/* B.1.4.2   Multi-element Variables */
-/*************************************/
-/*  subscripted_variable '[' subscript_list ']' */
-// SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
-void *get_var_name_c::visit(array_variable_c *symbol) {return symbol->subscripted_variable->accept(*this);}
-
-/* subscript_list ',' subscript */
-// SYM_LIST(subscript_list_c)
-
-/*  record_variable '.' field_selector */
-/*  WARNING: input and/or output variables of function blocks
- *           may be accessed as fields of a tructured variable!
- *           Code handling a structured_variable_c must take
- *           this into account!
- */
-// SYM_REF2(structured_variable_c, record_variable, field_selector)
-void *get_var_name_c::visit(structured_variable_c *symbol) {return symbol->record_variable->accept(*this);}
-
-
-
-
-
-
-
-
-
-
 
 search_var_instance_decl_c::search_var_instance_decl_c(symbol_c *search_scope) {
   this->current_vartype = none_vt;