Small code cleanup.
authorMario de Sousa <msousa@fe.up.pt>
Mon, 03 Dec 2012 14:06:49 +0000
changeset 762 a3d917474ae4
parent 761 7b52623a2f37
child 766 ffed675e79d8
Small code cleanup.
absyntax_utils/type_initial_value.cc
absyntax_utils/type_initial_value.hh
stage4/generate_c/generate_c.cc
stage4/generate_c/generate_c_il.cc
stage4/generate_c/generate_c_st.cc
stage4/generate_c/generate_c_vardecl.cc
--- a/absyntax_utils/type_initial_value.cc	Sat Dec 01 11:30:16 2012 +0000
+++ b/absyntax_utils/type_initial_value.cc	Mon Dec 03 14:06:49 2012 +0000
@@ -81,7 +81,7 @@
    * for the DATE data type. Untill we fix our implementation, we use 1970-01-01
    * as our default value!!
    */
-    date_literal_0 =  new date_literal_c(integer_1, integer_1, integer_1);
+//date_literal_0 =  new date_literal_c(integer_1, integer_1, integer_1);
   date_literal_0 =  new date_literal_c(new integer_c("1970"), integer_1, integer_1);
   daytime_literal_0 = new daytime_c(integer_0, integer_0, real_0);
   time_0 = new duration_c(new time_type_name_c(), NULL, new interval_c(NULL, NULL, NULL, integer_0, NULL));  // T#0s
@@ -98,9 +98,9 @@
 
 
 
-symbol_c *type_initial_value_c::get(identifier_c *type_name) {
+symbol_c *type_initial_value_c::get(symbol_c *type) {
   TRACE("type_initial_value_c::get(): called ");
-  return (symbol_c *)type_name->accept(*this);
+  return (symbol_c *)type->accept(*type_initial_value_c::instance());
 }
 
 
--- a/absyntax_utils/type_initial_value.hh	Sat Dec 01 11:30:16 2012 +0000
+++ b/absyntax_utils/type_initial_value.hh	Mon Dec 03 14:06:49 2012 +0000
@@ -59,8 +59,10 @@
 
 class type_initial_value_c : public null_visitor_c {
 
+  public:
+    static symbol_c *get(symbol_c *type);
+
   private:
-    static type_initial_value_c *_instance;
     /* constants for the default values of elementary data types... */
     static real_c		*real_0;
     static integer_c		*integer_0, *integer_1;
@@ -74,17 +76,12 @@
     static single_byte_character_string_c *string_0;
     static double_byte_character_string_c *wstring_0;
 
-  public:
-    static type_initial_value_c *instance(void);
-
   protected:
     type_initial_value_c(void);
 
-  public:
-    symbol_c *get(identifier_c *type_name);
-
-
   private:
+    static type_initial_value_c *_instance;
+    static type_initial_value_c *instance(void);
     void *handle_type_spec(symbol_c *base_type_name, symbol_c *type_spec_init);
 
   private:
--- a/stage4/generate_c/generate_c.cc	Sat Dec 01 11:30:16 2012 +0000
+++ b/stage4/generate_c/generate_c.cc	Mon Dec 03 14:06:49 2012 +0000
@@ -1124,7 +1124,7 @@
   s4o.print(" = ");
   {
     /* get the default value of this variable's type */
-    symbol_c *default_value = (symbol_c *)symbol->type_name->accept(*type_initial_value_c::instance());
+    symbol_c *default_value = type_initial_value_c::get(symbol->type_name);
     if (default_value == NULL) ERROR;
     initialization_analyzer_c initialization_analyzer(default_value);
     switch (initialization_analyzer.get_initialization_type()) {
--- a/stage4/generate_c/generate_c_il.cc	Sat Dec 01 11:30:16 2012 +0000
+++ b/stage4/generate_c/generate_c_il.cc	Mon Dec 03 14:06:49 2012 +0000
@@ -903,7 +903,7 @@
           s4o.print(",\n"+s4o.indent_spaces);
         if (param_value == NULL) {
           /* If not, get the default value of this variable's type */
-          param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance());
+          param_value = type_initial_value_c::get(current_param_type);
         }
         if (param_value == NULL) ERROR;
         s4o.print("(");
@@ -1292,7 +1292,7 @@
           s4o.print(",\n"+s4o.indent_spaces);
         if (param_value == NULL) {
           /* If not, get the default value of this variable's type */
-          param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance());
+          param_value = type_initial_value_c::get(current_param_type);
         }
         if (param_value == NULL) ERROR;
         s4o.print("(");
--- a/stage4/generate_c/generate_c_st.cc	Sat Dec 01 11:30:16 2012 +0000
+++ b/stage4/generate_c/generate_c_st.cc	Mon Dec 03 14:06:49 2012 +0000
@@ -752,7 +752,7 @@
           s4o.print(",\n"+s4o.indent_spaces);
         if (param_value == NULL) {
           /* If not, get the default value of this variable's type */
-          param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance());
+          param_value = type_initial_value_c::get(current_param_type);
         }
         if (param_value == NULL) ERROR;
         s4o.print("(");
--- a/stage4/generate_c/generate_c_vardecl.cc	Sat Dec 01 11:30:16 2012 +0000
+++ b/stage4/generate_c/generate_c_vardecl.cc	Mon Dec 03 14:06:49 2012 +0000
@@ -195,7 +195,7 @@
         case arraysize_am:
           symbol->array_subrange_list->accept(*this);
           array_base_type = symbol->non_generic_type_name;
-          array_default_value = (symbol_c *)symbol->non_generic_type_name->accept(*type_initial_value_c::instance());;
+          array_default_value = type_initial_value_c::get(symbol->non_generic_type_name);
           if (array_default_value == NULL) ERROR;
           break;
         case typedecl_am:
@@ -618,7 +618,7 @@
           if (current_element_type == NULL) ERROR;
           
           /* If not, get the default value of this variable's type */
-          element_value = (symbol_c *)current_element_type->accept(*type_initial_value_c::instance());
+          element_value = type_initial_value_c::get(current_element_type);
         }
         
         if (element_value == NULL) ERROR;
@@ -878,7 +878,7 @@
         ERROR;
       if (NULL == this->current_var_init_symbol) {
         /* We try to find the data type's default value... */
-        this->current_var_init_symbol = (symbol_c *)this->current_var_type_symbol->accept(*type_initial_value_c::instance());
+        this->current_var_init_symbol = type_initial_value_c::get(this->current_var_type_symbol);
       /* Note that Function Block 'data types' do not have a default value, so we cannot abort if no default value is found! */
       /*
       if (NULL == this->current_var_init_symbol)