[vala/staging] codegen: Improve handling of recursive DelegateType
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Improve handling of recursive DelegateType
- Date: Mon, 1 Feb 2021 16:34:26 +0000 (UTC)
commit 5399297fb6d02fbb413ceb81b2e58683aec439a8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Feb 1 17:34:15 2021 +0100
codegen: Improve handling of recursive DelegateType
Move dedicated test case into a separate file
codegen/valaccodedelegatemodule.vala | 28 +++++++++++-----------------
tests/Makefile.am | 1 +
tests/delegates/delegate-recusive.vala | 4 ++++
tests/delegates/delegates.vala | 1 -
4 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index b2b553941..dd3e0fcf6 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -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) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a5b2ba5ab..bc5888bbe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..27a331bf3
--- /dev/null
+++ b/tests/delegates/delegate-recusive.vala
@@ -0,0 +1,4 @@
+public delegate Maman.SelfCallback Maman.SelfCallback (Maman.SelfCallback scb);
+
+void main () {
+}
diff --git a/tests/delegates/delegates.vala b/tests/delegates/delegates.vala
index eb68ebd06..8880fb9f3 100644
--- a/tests/delegates/delegates.vala
+++ b/tests/delegates/delegates.vala
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]