Using InOut variables in functions fixed
authorlaurent
Tue, 15 Dec 2009 11:18:19 +0100
changeset 236 c55b02ca2342
parent 235 ed66dc50f31a
child 237 cece842c7417
Using InOut variables in functions fixed
stage4/generate_c/generate_c_il.cc
stage4/generate_c/generate_c_st.cc
stage4/generate_c/generate_c_vardecl.cc
--- a/stage4/generate_c/generate_c_il.cc	Tue Dec 15 08:51:44 2009 +0100
+++ b/stage4/generate_c/generate_c_il.cc	Tue Dec 15 11:18:19 2009 +0100
@@ -573,23 +573,12 @@
   else if (this->is_variable_prefix_null()) {
 	vartype = search_varfb_instance_type->get_vartype(symbol);
     if (wanted_variablegeneration == fparam_output_vg) {
-      if (vartype == search_var_instance_decl_c::external_vt)
-    	s4o.print(GET_EXTERNAL);
-      else
-    	s4o.print("&");
-      s4o.print("(");
+      s4o.print("&(");
       generate_c_base_c::visit(symbol);
       s4o.print(")");
     }
     else {
-      if (vartype == search_var_instance_decl_c::external_vt) {
-        s4o.print(GET_EXTERNAL);
-        s4o.print("(");
-        generate_c_base_c::visit(symbol);
-        s4o.print(")");
-      }
-      else
-    	generate_c_base_c::visit(symbol);
+      generate_c_base_c::visit(symbol);
     }
   }
   else
--- a/stage4/generate_c/generate_c_st.cc	Tue Dec 15 08:51:44 2009 +0100
+++ b/stage4/generate_c/generate_c_st.cc	Tue Dec 15 11:18:19 2009 +0100
@@ -208,22 +208,12 @@
   else if (this->is_variable_prefix_null()) {
 	vartype = search_varfb_instance_type->get_vartype(symbol);
 	if (wanted_variablegeneration == fparam_output_vg) {
-	  if (vartype == search_var_instance_decl_c::inoutput_vt)
-		generate_c_base_c::visit(symbol);
-	  else {
-		s4o.print("&(");
-        generate_c_base_c::visit(symbol);
-        s4o.print(")");
-	  }
+	  s4o.print("&(");
+      generate_c_base_c::visit(symbol);
+      s4o.print(")");
     }
     else {
-      if (vartype == search_var_instance_decl_c::inoutput_vt) {
-        s4o.print("(*");
-        generate_c_base_c::visit(symbol);
-        s4o.print(")");
-      }
-      else
-    	generate_c_base_c::visit(symbol);
+      generate_c_base_c::visit(symbol);
     }
   }
   else
--- a/stage4/generate_c/generate_c_vardecl.cc	Tue Dec 15 08:51:44 2009 +0100
+++ b/stage4/generate_c/generate_c_vardecl.cc	Tue Dec 15 11:18:19 2009 +0100
@@ -955,7 +955,7 @@
       /* now to produce the c equivalent... */
       if ((wanted_varformat == local_vf) ||
           (wanted_varformat == init_vf) ||
-          (wanted_varformat == localinit_vf && (current_vartype & inoutput_vt) == 0)) {
+          (wanted_varformat == localinit_vf)) {
         for(int i = 0; i < list->n; i++) {
           s4o.print(s4o.indent_spaces);
           if (wanted_varformat == local_vf) {
@@ -976,11 +976,45 @@
           print_variable_prefix();
           list->elements[i]->accept(*this);
           if (wanted_varformat != local_vf) {
-            if (this->current_var_init_symbol != NULL) {
-              s4o.print(" = ");
+        	if (wanted_varformat == localinit_vf &&
+        		(current_vartype & inoutput_vt) != 0) {
+              s4o.print(";\n");
+              s4o.print(s4o.indent_spaces);
+              s4o.print("if (__");
+              list->elements[i]->accept(*this);
+              s4o.print(" != NULL) {\n");
+              s4o.indent_right();
+              s4o.print(s4o.indent_spaces);
+              list->elements[i]->accept(*this);
+              s4o.print(" = *__");
+              list->elements[i]->accept(*this);
+              s4o.print(";\n");
+              s4o.indent_left();
+              s4o.print(s4o.indent_spaces);
+              s4o.print("}\n");
+              s4o.print(s4o.indent_spaces);
+              s4o.print("else {\n");
+              s4o.indent_right();
+              s4o.print(s4o.indent_spaces);
+              s4o.print("static const ");
+              this->current_var_type_symbol->accept(*this);
+              s4o.print(" temp = ");
               this->current_var_init_symbol->accept(*this);
+              s4o.print(";\n");
+              s4o.print(s4o.indent_spaces);
+              list->elements[i]->accept(*this);
+              s4o.print(" = temp;\n");
+              s4o.indent_left();
+              s4o.print(s4o.indent_spaces);
+              s4o.print("}\n");
             }
-            s4o.print(";\n");
+        	else {
+        	  if (this->current_var_init_symbol != NULL) {
+                s4o.print(" = ");
+                this->current_var_init_symbol->accept(*this);
+              }
+              s4o.print(";\n");
+            }
           }
           else if (is_fb)
         	s4o.print(";\n");
@@ -995,10 +1029,8 @@
           s4o.print(nv->get());
           s4o.print("\n" + s4o.indent_spaces);
           this->current_var_type_symbol->accept(*this);
-          if ((current_vartype & output_vt) != 0)
+          if ((current_vartype & (output_vt | inoutput_vt)) != 0)
             s4o.print(" *__");
-          else if ((current_vartype & inoutput_vt) != 0)
-            s4o.print(" *");
           else
             s4o.print(" ");
           list->elements[i]->accept(*this);
@@ -1014,7 +1046,7 @@
 
       if (wanted_varformat == foutputassign_vf) {
         for(int i = 0; i < list->n; i++) {
-          if ((current_vartype & output_vt) != 0) {
+          if ((current_vartype & (output_vt | inoutput_vt)) != 0) {
             s4o.print(s4o.indent_spaces + "if (__");
             list->elements[i]->accept(*this);
             s4o.print(" != NULL) {\n");