]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Improve handling of recursive DelegateType
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 1 Feb 2021 16:34:15 +0000 (17:34 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 1 Feb 2021 16:34:15 +0000 (17:34 +0100)
Move dedicated test case into a separate file

codegen/valaccodedelegatemodule.vala
tests/Makefile.am
tests/delegates/delegate-recusive.vala [new file with mode: 0644]
tests/delegates/delegates.vala

index b2b553941ae24db8778aca94255172f958634505..dd3e0fcf6cd5227645565a5f690b499f078dfad7 100644 (file)
@@ -37,10 +37,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                        return;
                }
 
-               generate_type_declaration (new DelegateType (d), decl_space);
-
                var creturn_type = get_callable_creturn_type (d);
-
                if (creturn_type is DelegateType && ((DelegateType) creturn_type).delegate_symbol == d) {
                        // recursive delegate
                        creturn_type = new DelegateType ((Delegate) context.root.scope.lookup ("GLib").scope.lookup ("Callback"));
@@ -450,18 +447,18 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                        return base.generate_parameter (param, decl_space, cparam_map, carg_map);
                }
 
-               generate_type_declaration (param.variable_type, decl_space);
+               var param_type = param.variable_type;
+               if (param_type is DelegateType && ((DelegateType) param_type).delegate_symbol == param.parent_symbol) {
+                       // recursive delegate
+                       param_type = new DelegateType ((Delegate) context.root.scope.lookup ("GLib").scope.lookup ("Callback"));
+               }
+
+               generate_type_declaration (param_type, decl_space);
 
-               string ctypename = get_ccode_name (param.variable_type);
+               string ctypename = get_ccode_name (param_type);
                string target_ctypename = get_ccode_name (delegate_target_type);
                string target_destroy_notify_ctypename = get_ccode_name (delegate_target_destroy_type);
 
-               if (param.parent_symbol is Delegate
-                   && get_ccode_name (param.variable_type) == get_ccode_name (param.parent_symbol)) {
-                       // recursive delegate
-                       ctypename = "GCallback";
-               }
-
                if (param.direction != ParameterDirection.IN) {
                        ctypename += "*";
                        target_ctypename += "*";
@@ -475,11 +472,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                        carg_map.set (get_param_pos (get_ccode_pos (param)), get_parameter_cexpression (param));
                }
 
-               if (param.variable_type is DelegateType) {
-                       var deleg_type = (DelegateType) param.variable_type;
-
-                       generate_delegate_declaration (deleg_type.delegate_symbol, decl_space);
-
+               if (param_type is DelegateType) {
+                       unowned DelegateType deleg_type = (DelegateType) param_type;
                        if (get_ccode_delegate_target (param) && 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);
@@ -494,7 +488,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
                                        }
                                }
                        }
-               } else if (param.variable_type is MethodType) {
+               } else if (param_type is MethodType) {
                        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 a5b2ba5ab919b78b7b73090e09e3e3fc9057680b..bc5888bbec45b9893441da7edf192f3ad57d190b 100644 (file)
@@ -373,6 +373,7 @@ TESTS = \
        delegates/casting.vala \
        delegates/compatible.vala \
        delegates/delegate_only.vala \
+       delegates/delegate-recusive.vala \
        delegates/delegates.vala \
        delegates/delegates-error.test \
        delegates/error-pos.vala \
diff --git a/tests/delegates/delegate-recusive.vala b/tests/delegates/delegate-recusive.vala
new file mode 100644 (file)
index 0000000..27a331b
--- /dev/null
@@ -0,0 +1,4 @@
+public delegate Maman.SelfCallback Maman.SelfCallback (Maman.SelfCallback scb);
+
+void main () {
+}
index eb68ebd06e6efefa805dfefe9835fabb6ebcfc14..8880fb9f32ab17d1161eabb867bffed4bb3407f1 100644 (file)
@@ -7,7 +7,6 @@ public static delegate void Maman.VoidCallback ();
 public static delegate int Maman.ActionCallback ();
 
 public delegate void Maman.InstanceCallback (int i);
-public delegate Maman.SelfCallback Maman.SelfCallback (Maman.SelfCallback scb);
 
 public delegate ParameterEnum Maman.EnumDelegate (ParameterEnum pe);