A little code cleanup (reduce number of possible variable generation states)
authormjsousa
Mon, 31 Mar 2014 20:05:49 +0100
changeset 887 a5e2eedeef53
parent 886 111414d79ecd
child 888 4893e6b11b25
A little code cleanup (reduce number of possible variable generation states)
stage4/generate_c/generate_c_st.cc
--- a/stage4/generate_c/generate_c_st.cc	Sun Mar 30 09:41:06 2014 +0100
+++ b/stage4/generate_c/generate_c_st.cc	Mon Mar 31 20:05:49 2014 +0100
@@ -49,9 +49,7 @@
   public:
     typedef enum {
       expression_vg,
-      assignment_vg,
       complextype_base_vg,
-      complextype_base_assignment_vg,
       complextype_suffix_vg,
       fparam_output_vg
     } variablegeneration_t;
@@ -157,9 +155,10 @@
     else
       s4o.print(GET_VAR);
   }
+  
+  variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
   s4o.print("(");
-
-  variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
+  print_variable_prefix();  
   wanted_variablegeneration = complextype_base_vg;
   symbol->accept(*this);
   s4o.print(",");
@@ -203,30 +202,18 @@
   }
   s4o.print("(");
 
+  
   if (fb_symbol != NULL) {
     print_variable_prefix();
     fb_symbol->accept(*this);
     s4o.print(".,");
   }
-  else if (type_is_complex)
-    wanted_variablegeneration = complextype_base_assignment_vg;
-  else
-    wanted_variablegeneration = assignment_vg;
-  
-/*
-  symbol->accept(*this);
-  s4o.print(",");
-  wanted_variablegeneration = expression_vg;
-  print_check_function(type, value, fb_value);
-  if (type_is_complex) {
-    s4o.print(",");
-    wanted_variablegeneration = complextype_suffix_vg;
-    symbol->accept(*this);
-  }
-  s4o.print(")");
-  wanted_variablegeneration = expression_vg;
-  return NULL;
-*/
+  else {
+    wanted_variablegeneration = complextype_base_vg;
+    print_variable_prefix();
+    s4o.print(",");    
+  }  
+
   symbol->accept(*this);
   s4o.print(",");
   if (type_is_complex) {
@@ -278,14 +265,8 @@
 /*********************/
 void *visit(symbolic_variable_c *symbol) {
   switch (wanted_variablegeneration) {
-    case complextype_base_assignment_vg:
-    case assignment_vg:
-      this->print_variable_prefix();
-      s4o.print(",");
-      symbol->var_name->accept(*this);
-      break;
     case complextype_base_vg:
-      generate_c_base_c::visit(symbol);
+      symbol->var_name->accept(*this); //generate_c_base_c::visit(symbol);
       break;
     case complextype_suffix_vg:
       break;
@@ -335,8 +316,9 @@
   }
   this->print_variable_prefix();
   s4o.printlocation(symbol->value + 1);
-  if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) ||
-      wanted_variablegeneration != assignment_vg)
+  if (( this->is_variable_prefix_null() && (wanted_variablegeneration != fparam_output_vg)) ||
+      (!this->is_variable_prefix_null() && (wanted_variablegeneration == expression_vg   )) ||
+      (!this->is_variable_prefix_null() && (wanted_variablegeneration == fparam_output_vg)))
     s4o.print(")");
   return NULL;
 }
@@ -351,7 +333,6 @@
   bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable);
   switch (wanted_variablegeneration) {
     case complextype_base_vg:
-    case complextype_base_assignment_vg:
       symbol->record_variable->accept(*this);
       if (!type_is_complex) {
         s4o.print(".");
@@ -365,11 +346,6 @@
         symbol->field_selector->accept(*this);
       }
       break;
-    case assignment_vg:
-      symbol->record_variable->accept(*this);
-      s4o.print(".");
-      symbol->field_selector->accept(*this);
-      break;
     default:
       if (this->is_variable_prefix_null()) {
         symbol->record_variable->accept(*this);
@@ -388,7 +364,6 @@
 void *visit(array_variable_c *symbol) {
   switch (wanted_variablegeneration) {
     case complextype_base_vg:
-    case complextype_base_assignment_vg:
       symbol->subscripted_variable->accept(*this);
       break;
     case complextype_suffix_vg:
@@ -496,6 +471,7 @@
     variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; 
     s4o.print("(");
     wanted_variablegeneration = complextype_base_vg;
+    print_variable_prefix();
     symbol->exp->accept(*this);
     s4o.print(",");
     wanted_variablegeneration = complextype_suffix_vg;