Code cleanup (part 2): generate_typedecl_c now only prints to POUS.h !
authormjsousa
Sat, 08 Feb 2014 23:10:12 +0000
changeset 860 7669a8d43c11
parent 859 41d11bacfc9b
child 861 443e8243f289
Code cleanup (part 2): generate_typedecl_c now only prints to POUS.h !
stage4/generate_c/generate_c.cc
stage4/generate_c/generate_c_base.cc
stage4/generate_c/generate_c_typedecl.cc
--- a/stage4/generate_c/generate_c.cc	Sat Feb 08 20:38:19 2014 +0000
+++ b/stage4/generate_c/generate_c.cc	Sat Feb 08 23:10:12 2014 +0000
@@ -661,15 +661,13 @@
     } inlinearray_mode_t;
 
   private:
-    stage4out_c *s4o_ptr;
     std::map<std::string, int> inline_array_defined;
     std::string current_array_name;
     inlinearray_mode_t current_mode;
 
   public:
     generate_c_datatypes_c(stage4out_c *s4o_ptr, stage4out_c *s4o_incl_ptr)
-      : generate_c_typedecl_c(s4o_ptr, s4o_incl_ptr) {
-      generate_c_datatypes_c::s4o_ptr = s4o_ptr;
+      : generate_c_typedecl_c(s4o_incl_ptr) {
       current_mode = none_im;
     };
     virtual ~generate_c_datatypes_c(void) {
@@ -1095,14 +1093,13 @@
 /***********************************************************************/
 
 
-class generate_c_pous_c: public generate_c_typedecl_c {
+class generate_c_pous_c: public generate_c_base_c {
   private:
-    stage4out_c *s4o_ptr;
+    stage4out_c &s4o_incl;
     
   public:
     generate_c_pous_c(stage4out_c *s4o_ptr, stage4out_c *s4o_incl_ptr)
-      : generate_c_typedecl_c(s4o_ptr, s4o_incl_ptr) {
-      generate_c_pous_c::s4o_ptr = s4o_ptr;
+      : generate_c_base_c(s4o_ptr), s4o_incl(*s4o_incl_ptr) {
     };
     virtual ~generate_c_pous_c(void) {}
 
@@ -1136,8 +1133,8 @@
 /********************/
 /* 2.1.6 - Pragmas  */
 /********************/
-void *visit(enable_code_generation_pragma_c * symbol)   {s4o_ptr->enable_output();  return NULL;}
-void *visit(disable_code_generation_pragma_c * symbol)  {s4o_ptr->disable_output(); return NULL;} 
+void *visit(enable_code_generation_pragma_c * symbol)   {s4o.enable_output();  return NULL;}
+void *visit(disable_code_generation_pragma_c * symbol)  {s4o.disable_output(); return NULL;} 
 
 /*************************/
 /* B.1 - Common elements */
@@ -1699,16 +1696,13 @@
 /***********************************************************************/
 /***********************************************************************/
 
-class generate_c_config_c: public generate_c_typedecl_c {
+class generate_c_config_c: public generate_c_base_c {
     private:
-    stage4out_c *s4o_ptr;
-    stage4out_c *s4o_incl_ptr;
+    stage4out_c &s4o_incl;
     
     public:
     generate_c_config_c(stage4out_c *s4o_ptr, stage4out_c *s4o_incl_ptr)
-      : generate_c_typedecl_c(s4o_ptr, s4o_incl_ptr) {
-      generate_c_config_c::s4o_ptr = s4o_ptr;
-      generate_c_config_c::s4o_incl_ptr = s4o_incl_ptr;
+      : generate_c_base_c(s4o_ptr), s4o_incl(*s4o_incl_ptr) {
     };
 
     virtual ~generate_c_config_c(void) {}
@@ -1728,14 +1722,14 @@
 /* 2.1.6 - Pragmas  */
 /********************/
 void *visit(enable_code_generation_pragma_c * symbol)   {
-    s4o_ptr->enable_output();
-    s4o_incl_ptr->enable_output();
+    s4o.enable_output();
+    s4o_incl.enable_output();
     return NULL;
 }
 
 void *visit(disable_code_generation_pragma_c * symbol)  {
-    s4o_ptr->disable_output();
-    s4o_incl_ptr->disable_output();    
+    s4o.disable_output();
+    s4o_incl.disable_output();    
     return NULL;
 }
     
--- a/stage4/generate_c/generate_c_base.cc	Sat Feb 08 20:38:19 2014 +0000
+++ b/stage4/generate_c/generate_c_base.cc	Sat Feb 08 23:10:12 2014 +0000
@@ -583,6 +583,60 @@
 /********************************/
   /* leave for derived classes... */
 
+  
+/* enumerated_type_name '#' identifier */
+void *visit(enumerated_value_c *symbol) {
+  if (NULL == symbol->datatype) {
+    debug_c::print(symbol);
+    ERROR;
+  }
+  
+  symbol_c *type_name = get_datatype_info_c::get_id(symbol->datatype);
+  if (NULL == type_name) {
+    ERROR_MSG("C code generator does not currently support anonymous enumerated data types.");
+  }
+  
+  type_name->accept(*this);
+  s4o.print("__");
+  symbol->value->accept(*this);
+  return NULL;
+}
+
+
+  
+/* NOTE:     visit(subrange_spec_init_c *)
+ *      and  visit(subrange_specification_c *)
+ *      together simply print out the integer datatype
+ *      on which the subrange is based.
+ *
+ *      Future code clean-ups should delete these two
+ *      visit mehotds, and make sure whoever calls them 
+ *      uses symbol->datatype instead!
+ */ 
+/* subrange_specification ASSIGN signed_integer */
+void *visit(subrange_spec_init_c *symbol) {
+  TRACE("subrange_spec_init_c");
+  symbol->subrange_specification->accept(*this);
+  return NULL;
+}
+
+/*  integer_type_name '(' subrange')' */
+void *visit(subrange_specification_c *symbol) {
+  TRACE("subrange_specification_c");
+  symbol->integer_type_name->accept(*this);
+  return NULL;
+}
+  
+  
+/* helper symbol for array_specification */
+/* array_subrange_list ',' subrange */
+void *visit(array_subrange_list_c *symbol) {
+  TRACE("array_subrange_list_c");
+  print_list(symbol);
+  return NULL;
+}  
+  
+  
 /*********************/
 /* B 1.4 - Variables */
 /*********************/
--- a/stage4/generate_c/generate_c_typedecl.cc	Sat Feb 08 20:38:19 2014 +0000
+++ b/stage4/generate_c/generate_c_typedecl.cc	Sat Feb 08 23:10:12 2014 +0000
@@ -31,16 +31,9 @@
   private:
     symbol_c* current_type_name;
     bool array_is_derived;
-
     generate_c_base_c *basedecl;
 
   public:
-    generate_c_typedecl_c(stage4out_c *s4o_ptr, stage4out_c *s4o_incl_ptr): generate_c_base_c(s4o_ptr), s4o_incl(*s4o_incl_ptr) {
-      current_typedefinition = none_td;
-      current_basetypedeclaration = none_bd;
-      current_type_name = NULL;
-      basedecl = new generate_c_base_c(&s4o_incl);
-    }
     generate_c_typedecl_c(stage4out_c *s4o_ptr): generate_c_base_c(s4o_ptr), s4o_incl(*s4o_ptr) {
       current_typedefinition = none_td;
       current_basetypedeclaration = none_bd;
@@ -237,11 +230,9 @@
         break;
     }
   }
-  else {
-    symbol->integer_type_name->accept(*basedecl);
-  }
-  return NULL;
-}
+  return NULL;
+}
+
 
 /*  signed_integer DOTDOT signed_integer */
 void *visit(subrange_c *symbol) {
@@ -324,25 +315,9 @@
 }
 
 /* enumerated_type_name '#' identifier */
-void *visit(enumerated_value_c *symbol) {
-  TRACE("enumerated_value_c");
-  if (current_typedefinition == enumerated_td)
-    current_type_name->accept(*basedecl);
-  else {
-    if (NULL == symbol->datatype) {
-      debug_c::print(symbol);
-      ERROR;
-    }
-    symbol_c *type_name = get_datatype_info_c::get_id(symbol->datatype);
-    if (NULL == type_name) {
-//       ERROR_MSG("generate_c does not support anonymous enumerated data types.");
-    } else
-    type_name->accept(*basedecl);
-  }
-  s4o_incl.print("__");
-  symbol->value->accept(*basedecl);
-  return NULL;
-}
+/* Handled by generate_c_base_c class!!
+void *visit(enumerated_value_c *symbol) {}
+*/
 
 /*  identifier ':' array_spec_init */
 void *visit(array_type_declaration_c *symbol) {
@@ -422,13 +397,6 @@
   return NULL;
 }
 
-/* helper symbol for array_specification */
-/* array_subrange_list ',' subrange */
-void *visit(array_subrange_list_c *symbol) {
-  TRACE("array_subrange_list_c");
-  print_list(symbol);
-  return NULL;
-}
 
 /*  TYPE type_declaration_list END_TYPE */
 void *visit(data_type_declaration_c *symbol) {