Create functionDataType array in derived_conversion_functions_c.
authorManuele Conti <conti.ma@alice.it>
Mon, 19 Nov 2012 22:53:43 +0100
changeset 747 d1c1a0254e4f
parent 746 c7219a37cc39
child 748 ad4265253528
Create functionDataType array in derived_conversion_functions_c.
absyntax_utils/add_en_eno_param_decl.hh
stage1_2/derived_conversion_functions.cc
stage1_2/derived_conversion_functions.hh
stage1_2/iec_bison.yy
--- a/absyntax_utils/add_en_eno_param_decl.hh	Fri Nov 16 10:26:23 2012 +0100
+++ b/absyntax_utils/add_en_eno_param_decl.hh	Mon Nov 19 22:53:43 2012 +0100
@@ -42,6 +42,9 @@
  * and eno_param_declaration_c objects.
  */
 
+#ifndef _ADD_EN_ENO_PARAM_DECL_HH
+#define _ADD_EN_ENO_PARAM_DECL_HH
+
 #include "../absyntax/visitor.hh"
 
 
@@ -96,9 +99,11 @@
 
 }; // function_param_iterator_c
 
+#endif /* _ADD_EN_ENO_PARAM_DECL_HH */
 
 
 
 
 
 
+
--- a/stage1_2/derived_conversion_functions.cc	Fri Nov 16 10:26:23 2012 +0100
+++ b/stage1_2/derived_conversion_functions.cc	Mon Nov 19 22:53:43 2012 +0100
@@ -37,6 +37,19 @@
 
 static const int debug = 0;
 
+const char *derived_conversion_functions_c::functionDataType[] = {
+		"STRING",
+		"SINT"  ,
+		"INT"   ,
+		"DINT"  ,
+		"LINT"  ,
+		"USINT" ,
+		"UNIT"  ,
+		"UDINT" ,
+		"ULINT" ,
+		NULL
+};
+
 derived_conversion_functions_c::derived_conversion_functions_c(symbol_c *ignore) {
 
 }
--- a/stage1_2/derived_conversion_functions.hh	Fri Nov 16 10:26:23 2012 +0100
+++ b/stage1_2/derived_conversion_functions.hh	Mon Nov 19 22:53:43 2012 +0100
@@ -39,12 +39,15 @@
 
 #include "../absyntax_utils/absyntax_utils.hh"
 
+
 class derived_conversion_functions_c: public iterator_visitor_c {
   public:
     explicit derived_conversion_functions_c(symbol_c *ignore);
     virtual ~derived_conversion_functions_c(void);
     std::string &get_declaration(symbol_c *root);
 
+    const static char *functionDataType [];
+
     void *visit(identifier_c *symbol);
     /**********************/
     /* B 1.3 - Data types */
--- a/stage1_2/iec_bison.yy	Fri Nov 16 10:26:23 2012 +0100
+++ b/stage1_2/iec_bison.yy	Mon Nov 19 22:53:43 2012 +0100
@@ -100,7 +100,7 @@
 
 /* The interface through which bison and flex interact. */
 #include "stage1_2_priv.hh"
-
+#include "derived_conversion_functions.hh"
 
 #include "../absyntax_utils/add_en_eno_param_decl.hh"	/* required for  add_en_eno_param_decl_c */
 
@@ -240,7 +240,7 @@
                    const char *additional_error_msg);
                    
 /* Create entry in symbol table for function conversion data type*/
-void make_derived_conversion_functions(const char * dname);
+void add_enumtype_conversion_functions(const char * dname);
 %}
 
 
@@ -2716,7 +2716,7 @@
       $$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, NULL, locloc(@3)), locloc(@$));
       if (conversion_functions_) {
         const char *name = ((identifier_c *)$1)->value;
-	    make_derived_conversion_functions(name);
+	    add_enumtype_conversion_functions(name);
 	  }
     }
 | identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} ASSIGN enumerated_value
@@ -8406,51 +8406,18 @@
 }
 
 
-
 /* Create entry in symbol table for function conversion data type*/
-void make_derived_conversion_functions(const char * dname) {
+void add_enumtype_conversion_functions(const char * dname) {
   std::string strname;
   std::string tmp;
   
-  strname = dname;
-  tmp = strname + "_TO_STRING";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = strname + "_TO_SINT";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = strname + "_TO_INT";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = strname + "_TO_DINT";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = strname + "_TO_LINT";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = strname + "_TO_USINT";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = strname + "_TO_UINT";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = strname + "_TO_UDINT";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = strname + "_TO_ULINT";
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  /* ... */      
-  tmp = "STRING_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = "SINT_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = "INT_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = "DINT_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = "LINT_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = "USINT_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = "UINT_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = "UDINT_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  tmp = "ULINT_TO_" + strname;
-  library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
-  /* ... */
+  strname = dname; 
+  for (int i = 0; derived_conversion_functions_c::functionDataType[i] != NULL; i++) {
+    tmp = strname + std::string("_TO_") + derived_conversion_functions_c::functionDataType[i];
+    library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+    tmp = derived_conversion_functions_c::functionDataType[i] + std::string("_TO_") + strname;
+    library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+  }  
 }