]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Simplify visit_local_variable
authorJürg Billeter <j@bitron.ch>
Wed, 19 Jan 2011 20:31:14 +0000 (21:31 +0100)
committerJürg Billeter <j@bitron.ch>
Wed, 19 Jan 2011 21:04:23 +0000 (22:04 +0100)
codegen/valaccodebasemodule.vala

index 7f15e15c53b9a9a8c46f6950dfaf55ce7d17208f..32ce1bfca9a0e52c796d7c1ab7edd7f072dfc841 100644 (file)
@@ -2022,12 +2022,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                if (!array_type.fixed_length) {
                                        for (int dim = 1; dim <= array_type.rank; dim++) {
                                                var len_var = new LocalVariable (int_type.copy (), get_array_length_cname (get_variable_cname (local.name), dim));
-                                               emit_temp_var (len_var);
+                                               emit_temp_var (len_var, local.initializer == null);
                                        }
 
                                        if (array_type.rank == 1) {
                                                var size_var = new LocalVariable (int_type.copy (), get_array_size_cname (get_variable_cname (local.name)));
-                                               emit_temp_var (size_var);
+                                               emit_temp_var (size_var, local.initializer == null);
                                        }
                                }
                        } else if (local.variable_type is DelegateType) {
@@ -2036,10 +2036,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                if (d.has_target) {
                                        // create variable to store delegate target
                                        var target_var = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (get_variable_cname (local.name)));
-                                       emit_temp_var (target_var);
+                                       emit_temp_var (target_var, local.initializer == null);
                                        if (deleg_type.value_owned) {
                                                var target_destroy_notify_var = new LocalVariable (gdestroynotify_type, get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
-                                               emit_temp_var (target_destroy_notify_var);
+                                               emit_temp_var (target_destroy_notify_var, local.initializer == null);
                                        }
                                }
                        }
@@ -2084,21 +2084,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        }
                                }
                        }
-               } else if (local.variable_type.is_reference_type_or_type_parameter ()) {
-                       rhs = new CCodeConstant ("NULL");
-
-                       if (local.variable_type is ArrayType) {
-                               // initialize array length variables
-                               var array_type = (ArrayType) local.variable_type;
-
-                               if (array_type.fixed_length) {
-                                       rhs = null;
-                               } else {
-                                       for (int dim = 1; dim <= array_type.rank; dim++) {
-                                               ccode.add_assignment (get_variable_cexpression (get_array_length_cname (get_variable_cname (local.name), dim)), new CCodeConstant ("0"));
-                                       }
-                               }
-                       }
                }
 
                if (local.captured) {
@@ -3077,7 +3062,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                temp_ref_vars.clear ();
        }
        
-       public void emit_temp_var (LocalVariable local) {
+       public void emit_temp_var (LocalVariable local, bool always_init = false) {
                var vardecl = new CCodeVariableDeclarator (local.name, null, local.variable_type.get_cdeclarator_suffix ());
 
                var st = local.variable_type.data_type as Struct;
@@ -3105,6 +3090,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                           local.variable_type is DelegateType) {
                        vardecl.initializer = new CCodeConstant ("NULL");
                        vardecl.init0 = true;
+               } else if (always_init) {
+                       vardecl.initializer = default_value_for_type (local.variable_type, true);
+                       vardecl.init0 = true;
                }
 
                if (current_method != null && current_method.coroutine) {