Fix bug when generating initial value for function return type when it is a complex type
authorlaurent
Thu, 09 Jun 2011 17:51:00 +0200
changeset 318 746a357b8747
parent 317 5b687021c6e7
child 319 1669977e84f4
Fix bug when generating initial value for function return type when it is a complex type
stage4/generate_c/generate_c.cc
--- a/stage4/generate_c/generate_c.cc	Thu Jun 09 17:47:57 2011 +0200
+++ b/stage4/generate_c/generate_c.cc	Thu Jun 09 17:51:00 2011 +0200
@@ -612,7 +612,28 @@
     /* get the default value of this variable's type */
     symbol_c *default_value = (symbol_c *)symbol->type_name->accept(*type_initial_value_c::instance());
     if (default_value == NULL) ERROR;
-    default_value->accept(*this);
+    initialization_analyzer_c initialization_analyzer(default_value);
+    switch (initialization_analyzer.get_initialization_type()) {
+      case initialization_analyzer_c::struct_it:
+        {
+          generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o);
+          structure_initialization->init_structure_default(symbol->type_name);
+          structure_initialization->init_structure_values(default_value);
+          delete structure_initialization;
+        }
+    	break;
+      case initialization_analyzer_c::array_it:
+        {
+    	  generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
+    	  array_initialization->init_array_size(symbol->type_name);
+    	  array_initialization->init_array_values(default_value);
+    	  delete array_initialization;
+        }
+    	break;
+      default:
+        default_value->accept(*this);
+        break;
+    }
   }
   s4o.print(";\n\n");