]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Move main declaration to the beginning in visit_local_variable
authorJürg Billeter <j@bitron.ch>
Wed, 19 Jan 2011 20:36:00 +0000 (21:36 +0100)
committerJürg Billeter <j@bitron.ch>
Wed, 19 Jan 2011 21:04:23 +0000 (22:04 +0100)
codegen/valaccodebasemodule.vala

index 32ce1bfca9a0e52c796d7c1ab7edd7f072dfc841..09fc4e58c6c22c86240a6adcdf81711d8f533f8e 100644 (file)
@@ -2014,7 +2014,27 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                generate_type_declaration (local.variable_type, cfile);
 
+               CCodeExpression rhs = null;
+               if (local.initializer != null && get_cvalue (local.initializer) != null) {
+                       rhs = get_cvalue (local.initializer);
+               }
+
                if (!local.captured) {
+                       if (current_method != null && current_method.coroutine) {
+                               closure_struct.add_field (local.variable_type.get_cname (), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
+                       } else {
+                               var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), null, local.variable_type.get_cdeclarator_suffix ());
+
+                               // try to initialize uninitialized variables
+                               // initialization not necessary for variables stored in closure
+                               if (rhs == null || has_simple_struct_initializer (local)) {
+                                       cvar.initializer = default_value_for_type (local.variable_type, true);
+                                       cvar.init0 = true;
+                               }
+
+                               ccode.add_declaration (local.variable_type.get_cname (), cvar);
+                       }
+
                        if (local.variable_type is ArrayType) {
                                // create variables to store array dimensions
                                var array_type = (ArrayType) local.variable_type;
@@ -2045,12 +2065,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        }
                }
        
-               CCodeExpression rhs = null;
-               if (local.initializer != null && get_cvalue (local.initializer) != null) {
+               if (rhs != null) {
                        var target_value = get_variable_cvalue (local);
 
-                       rhs = get_cvalue (local.initializer);
-
                        if (local.variable_type is ArrayType) {
                                var array_type = (ArrayType) local.variable_type;
 
@@ -2095,8 +2112,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                }
                        }
                } else if (current_method != null && current_method.coroutine) {
-                       closure_struct.add_field (local.variable_type.get_cname (), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
-
                        if (local.initializer != null) {
                                if (has_simple_struct_initializer (local)) {
                                        ccode.add_expression (rhs);
@@ -2105,17 +2120,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                }
                        }
                } else {
-                       var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), null, local.variable_type.get_cdeclarator_suffix ());
-
-                       // try to initialize uninitialized variables
-                       // initialization not necessary for variables stored in closure
-                       if (rhs == null || has_simple_struct_initializer (local)) {
-                               cvar.initializer = default_value_for_type (local.variable_type, true);
-                               cvar.init0 = true;
-                       }
-
-                       ccode.add_declaration (local.variable_type.get_cname (), cvar);
-
                        if (rhs != null) {
                                if (has_simple_struct_initializer (local)) {
                                        ccode.add_expression (rhs);