[vala/staging] codegen: Respect finish[_vfunc]_name attributes defined in vala sources
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Respect finish[_vfunc]_name attributes defined in vala sources
- Date: Wed, 27 Feb 2019 13:31:59 +0000 (UTC)
commit b3b98372a8c0b091af46c43fff6df587efcf2299
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed Feb 27 14:29:47 2019 +0100
codegen: Respect finish[_vfunc]_name attributes defined in vala sources
codegen/valaccodeattribute.vala | 7 ++++-
codegen/valaccodemethodmodule.vala | 19 +++++++------
tests/Makefile.am | 1 +
tests/asynchronous/finish-name.vala | 56 +++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 9 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index d6399e459..e41a75ca0 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -503,7 +503,12 @@ public class Vala.CCodeAttribute : AttributeCache {
public string finish_real_name {
get {
if (_finish_real_name == null) {
- _finish_real_name = get_finish_name_for_basename (real_name);
+ unowned Method? m = node as Method;
+ if (m != null && !(m is CreationMethod) && !(m.is_abstract || m.is_virtual)) {
+ _finish_real_name = finish_name;
+ } else {
+ _finish_real_name = get_finish_name_for_basename (real_name);
+ }
}
return _finish_real_name;
}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index bc7a3b2a1..2269742e9 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -1094,11 +1094,12 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
public void generate_vfunc (Method m, DataType return_type, Map<int,CCodeParameter> cparam_map,
Map<int,CCodeExpression> carg_map, string suffix = "", int direction = 3) {
push_context (new EmitContext ());
- string cname = get_ccode_name (m);
- if (suffix == "_finish" && cname.has_suffix ("_async")) {
- cname = cname.substring (0, cname.length - "_async".length);
+ CCodeFunction vfunc;
+ if (suffix == "_finish") {
+ vfunc = new CCodeFunction (get_ccode_finish_name (m));
+ } else {
+ vfunc = new CCodeFunction (get_ccode_name (m));
}
- var vfunc = new CCodeFunction (cname + suffix);
CCodeExpression vcast;
if (m.parent_symbol is Interface) {
@@ -1116,11 +1117,13 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
}
- cname = get_ccode_vfunc_name (m);
- if (suffix == "_finish" && cname.has_suffix ("_async")) {
- cname = cname.substring (0, cname.length - "_async".length);
+ CCodeFunctionCall vcall;
+ if (suffix == "_finish") {
+ vcall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast,
get_ccode_finish_vfunc_name (m)));
+ } else {
+ vcall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast,
get_ccode_vfunc_name (m)));
}
- var vcall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, cname + suffix));
+
carg_map.set (get_param_pos (get_ccode_instance_pos (m)), new CCodeIdentifier ("self"));
generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall, direction);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a33342403..76b93f2c3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -426,6 +426,7 @@ TESTS = \
asynchronous/catch-error-scope.vala \
asynchronous/catch-in-finally.vala \
asynchronous/closures.vala \
+ asynchronous/finish-name.vala \
asynchronous/generator.vala \
asynchronous/out-parameter-invalid.test \
asynchronous/result-pos.vala \
diff --git a/tests/asynchronous/finish-name.vala b/tests/asynchronous/finish-name.vala
new file mode 100644
index 000000000..bea4c3f40
--- /dev/null
+++ b/tests/asynchronous/finish-name.vala
@@ -0,0 +1,56 @@
+public class Foo {
+ [CCode (finish_name = "foo_new_end")]
+ public async Foo.async () {
+ }
+
+ [CCode (finish_name = "foo_bar_end")]
+ public async string bar () {
+ return "bar";
+ }
+ [CCode (finish_name = "foo_baz_end", finish_vfunc_name = "baz_end")]
+ public virtual async string baz () {
+ return "baz";
+ }
+}
+
+public class Bar : Foo {
+ [CCode (finish_name = "bar_baz_end")]
+ public override async string baz () {
+ return "baz_bar";
+ }
+}
+
+[CCode (finish_name = "manam_end")]
+public async string manam () {
+ return "manam";
+}
+
+MainLoop loop;
+
+void main () {
+ loop = new MainLoop ();
+
+ var foo = new Foo ();
+ foo.bar.begin ((o,r) => {
+ var res = foo.bar.end (r);
+ assert (res == "bar");
+ });
+ foo.baz.begin ((o,r) => {
+ var res = foo.baz.end (r);
+ assert (res == "baz");
+ });
+
+ var bar = new Bar ();
+ bar.baz.begin ((o,r) => {
+ var res = bar.baz.end (r);
+ assert (res == "baz_bar");
+ });
+
+ manam.begin ((o,r) => {
+ var res = manam.end (r);
+ assert (res == "manam");
+ loop.quit ();
+ });
+
+ loop.run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]