]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Unify some delegate-type check patterns
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 6 Jun 2018 11:22:53 +0000 (13:22 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 6 Jun 2018 12:50:58 +0000 (14:50 +0200)
codegen/valaccodebasemodule.vala
codegen/valaccodedelegatemodule.vala
codegen/valaccodememberaccessmodule.vala
codegen/valaccodemethodcallmodule.vala
codegen/valaccodemethodmodule.vala
codegen/valagasyncmodule.vala

index 9147a5fa00f9f8278fbc8362af7eb43e0a3b35f3..71d5d5ae67b6779971fe3bae17a67af1c42af72b 100644 (file)
@@ -1100,7 +1100,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                }
                                decl_space.add_type_member_declaration (cdecl);
 
-                               if (delegate_type.value_owned && !delegate_type.is_called_once) {
+                               if (delegate_type.is_disposable ()) {
                                        cdecl = new CCodeDeclaration ("GDestroyNotify");
                                        cdecl.add_declarator (new CCodeVariableDeclarator (get_delegate_target_destroy_notify_cname  (get_ccode_name (f))));
                                        if (f.is_private_symbol ()) {
@@ -2006,7 +2006,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                                data.add_field ("gint", get_array_size_cname (get_local_cname (local)));
                                        } else if (local.variable_type is DelegateType && ((DelegateType) local.variable_type).delegate_symbol.has_target) {
                                                data.add_field ("gpointer", get_delegate_target_cname (get_local_cname (local)));
-                                               if (local.variable_type.value_owned) {
+                                               if (local.variable_type.is_disposable ()) {
                                                        data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_local_cname (local)));
                                                }
                                        }
@@ -2444,13 +2444,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                }
                        } else if (local.variable_type is DelegateType) {
                                var deleg_type = (DelegateType) local.variable_type;
-                               var d = deleg_type.delegate_symbol;
-                               if (d.has_target) {
+                               if (deleg_type.delegate_symbol.has_target) {
                                        // create variable to store delegate target
                                        var target_var = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (get_local_cname (local)));
                                        target_var.init = local.initializer == null;
                                        emit_temp_var (target_var);
-                                       if (deleg_type.value_owned) {
+                                       if (deleg_type.is_disposable ()) {
                                                var target_destroy_notify_var = new LocalVariable (gdestroynotify_type, get_delegate_target_destroy_notify_cname (get_local_cname (local)));
                                                target_destroy_notify_var.init = local.initializer == null;
                                                emit_temp_var (target_destroy_notify_var);
@@ -2498,7 +2497,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        var target_var = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (local.name), null, node_reference.source_reference);
                        target_var.init = init;
                        emit_temp_var (target_var);
-                       if (deleg_type.value_owned) {
+                       if (deleg_type.is_disposable ()) {
                                var target_destroy_notify_var = new LocalVariable (gdestroynotify_type.copy (), get_delegate_target_destroy_notify_cname (local.name), null, node_reference.source_reference);
                                target_destroy_notify_var.init = init;
                                emit_temp_var (target_destroy_notify_var);
index 82202c97a77713b020b4b1dac74ef89478dce36e..e3ab92ce78e19fb9fd68476d9d7500d63c87a53a 100644 (file)
@@ -489,11 +489,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
                if (param.variable_type is DelegateType) {
                        var deleg_type = (DelegateType) param.variable_type;
-                       var d = deleg_type.delegate_symbol;
 
-                       generate_delegate_declaration (d, decl_space);
+                       generate_delegate_declaration (deleg_type.delegate_symbol, decl_space);
 
-                       if (d.has_target) {
+                       if (deleg_type.delegate_symbol.has_target) {
                                var cparam = new CCodeParameter (get_ccode_delegate_target_name (param), target_ctypename);
                                cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), cparam);
                                if (carg_map != null) {
index 71702a9c10ec11fc1adf17feff5fc02c9d24cdfa..30aec9499501580b82f2f8c69395a93667d1703e 100644 (file)
@@ -402,12 +402,12 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                        } else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
                                if (is_in_coroutine ()) {
                                        result.delegate_target_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_delegate_target_cname (get_local_cname (local)));
-                                       if (local.variable_type.value_owned) {
+                                       if (local.variable_type.is_disposable ()) {
                                                result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_delegate_target_destroy_notify_cname (get_local_cname (local)));
                                        }
                                } else {
                                        result.delegate_target_cvalue = new CCodeIdentifier (get_delegate_target_cname (get_local_cname (local)));
-                                       if (local.variable_type.value_owned) {
+                                       if (local.variable_type.is_disposable ()) {
                                                result.delegate_target_destroy_notify_cvalue = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_local_cname (local)));
                                        }
                                }
index 6659442d18c956519cd2ecdbdb427c9775cc2d3d..efa067a9ab26fc5217392e504b50efe054eaba21 100644 (file)
@@ -377,8 +377,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                                        }
                                                } else if (param.variable_type is DelegateType) {
                                                        var deleg_type = (DelegateType) param.variable_type;
-                                                       var d = deleg_type.delegate_symbol;
-                                                       if (d.has_target) {
+                                                       if (deleg_type.delegate_symbol.has_target) {
                                                                CCodeExpression delegate_target_destroy_notify;
                                                                var delegate_target = get_delegate_target_cexpression (arg, out delegate_target_destroy_notify);
                                                                assert (delegate_target != null);
@@ -441,8 +440,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                                        }
                                                } else if (param.variable_type is DelegateType) {
                                                        var deleg_type = (DelegateType) param.variable_type;
-                                                       var d = deleg_type.delegate_symbol;
-                                                       if (d.has_target) {
+                                                       if (deleg_type.delegate_symbol.has_target) {
                                                                temp_var = get_temp_variable (new PointerType (new VoidType ()), true, null, true);
                                                                emit_temp_var (temp_var);
                                                                set_delegate_target (arg, get_variable_cexpression (temp_var.name));
@@ -532,8 +530,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                        }
                } else if (m != null && m.return_type is DelegateType && async_call != ccall) {
                        var deleg_type = (DelegateType) m.return_type;
-                       var d = deleg_type.delegate_symbol;
-                       if (d.has_target) {
+                       if (deleg_type.delegate_symbol.has_target) {
                                var temp_var = get_temp_variable (new PointerType (new VoidType ()));
                                var temp_ref = get_variable_cexpression (temp_var.name);
 
@@ -594,8 +591,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                        }
                } else if (deleg != null && deleg.return_type is DelegateType) {
                        var deleg_type = (DelegateType) deleg.return_type;
-                       var d = deleg_type.delegate_symbol;
-                       if (d.has_target) {
+                       if (deleg_type.delegate_symbol.has_target) {
                                var temp_var = get_temp_variable (new PointerType (new VoidType ()));
                                var temp_ref = get_variable_cexpression (temp_var.name);
 
index 66e3ad1a70513ceadf95560973debdfd73678c64..224f2d53a56d5a258d5dd7d7c59b40752c25b66a 100644 (file)
@@ -93,8 +93,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                } else if (m.return_type is DelegateType) {
                        // return delegate target if appropriate
                        var deleg_type = (DelegateType) m.return_type;
-                       var d = deleg_type.delegate_symbol;
-                       if (d.has_target) {
+                       if (deleg_type.delegate_symbol.has_target) {
                                var cparam = new CCodeParameter (get_delegate_target_cname ("result"), "void**");
                                cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), cparam);
                                if (carg_map != null) {
@@ -586,8 +585,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                                        }
                                                } else if (param.variable_type is DelegateType) {
                                                        var deleg_type = (DelegateType) param.variable_type;
-                                                       var d = deleg_type.delegate_symbol;
-                                                       if (d.has_target) {
+                                                       if (deleg_type.delegate_symbol.has_target) {
                                                                // create variable to store delegate target
                                                                vardecl = new CCodeVariableDeclarator.zero ("_vala_%s".printf (get_ccode_delegate_target_name (param)), new CCodeConstant ("NULL"));
                                                                ccode.add_declaration ("void *", vardecl);
index 715c35f56de7c7f8b519a93151cfa30d68bc75c1..9d63ab7adfc19e7cbb407826f60b22f237e78532 100644 (file)
@@ -51,8 +51,6 @@ public class Vala.GAsyncModule : GtkModule {
                }
 
                foreach (Parameter param in m.get_parameters ()) {
-                       bool is_unowned_delegate = param.variable_type is DelegateType && !param.variable_type.value_owned;
-
                        var param_type = param.variable_type.copy ();
                        param_type.value_owned = true;
                        data.add_field (get_ccode_name (param_type), get_variable_cname (param.name));
@@ -68,7 +66,7 @@ public class Vala.GAsyncModule : GtkModule {
                                var deleg_type = (DelegateType) param.variable_type;
                                if (deleg_type.delegate_symbol.has_target) {
                                        data.add_field ("gpointer", get_ccode_delegate_target_name (param));
-                                       if (!is_unowned_delegate) {
+                                       if (deleg_type.is_disposable ()) {
                                                data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
                                        }
                                }