From a46ba4fa4d8f729d340dc4048eb0e19f09876014 Mon Sep 17 00:00:00 2001 From: Michal Hruby Date: Wed, 28 Apr 2010 14:23:30 +0200 Subject: [PATCH] vapigen: Support finish_name attribute for async methods --- vala/valacodewriter.vala | 4 ++++ vala/valamethod.vala | 37 +++++++++++++++++++++++-------------- vapigen/valagidlparser.vala | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index f75691f03..cb9c70cf5 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -928,6 +928,10 @@ public class Vala.CodeWriter : CodeVisitor { ccode_params.append_printf ("%svfunc_name = \"%s\"", separator, m.vfunc_name); separator = ", "; } + if (m.coroutine && m.get_finish_cname () != m.get_default_finish_cname ()) { + ccode_params.append_printf ("%sfinish_name = \"%s\"", separator, m.get_finish_cname ()); + separator = ", "; + } if (m.sentinel != m.DEFAULT_SENTINEL) { ccode_params.append_printf ("%ssentinel = \"%s\"", separator, m.sentinel); separator = ", "; diff --git a/vala/valamethod.vala b/vala/valamethod.vala index e91008a8e..36196385e 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -233,6 +233,7 @@ public class Vala.Method : Member { private List parameters = new ArrayList (); private string cname; + private string finish_name; private string _vfunc_name; private string _sentinel; private List preconditions = new ArrayList (); @@ -351,12 +352,14 @@ public class Vala.Method : Member { public string get_finish_cname () { assert (coroutine); - string result = get_cname (); - if (result.has_suffix ("_async")) { - result = result.substring (0, result.length - "_async".length); + if (finish_name == null) { + finish_name = get_default_finish_cname (); } - result += "_finish"; - return result; + return finish_name; + } + + public void set_finish_cname (string name) { + finish_name = name; } /** @@ -390,9 +393,8 @@ public class Vala.Method : Member { } } - public string get_finish_real_cname () { - assert (coroutine); - string result = get_real_cname (); + protected string get_finish_name_for_basename (string basename) { + string result = basename; if (result.has_suffix ("_async")) { result = result.substring (0, result.length - "_async".length); } @@ -400,14 +402,18 @@ public class Vala.Method : Member { return result; } + public string get_finish_real_cname () { + assert (coroutine); + return get_finish_name_for_basename (get_real_cname ()); + } + public string get_finish_vfunc_name () { assert (coroutine); - string result = vfunc_name; - if (result.has_suffix ("_async")) { - result = result.substring (0, result.length - "_async".length); - } - result += "_finish"; - return result; + return get_finish_name_for_basename (vfunc_name); + } + + public string get_default_finish_cname () { + return get_finish_name_for_basename (get_cname ()); } /** @@ -432,6 +438,9 @@ public class Vala.Method : Member { if (a.has_argument ("vfunc_name")) { this.vfunc_name = a.get_string ("vfunc_name"); } + if (a.has_argument ("finish_name")) { + this.finish_name = a.get_string ("finish_name"); + } if (a.has_argument ("sentinel")) { this.sentinel = a.get_string ("sentinel"); } diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala index 87bed68f5..a4c5a92e4 100644 --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -1260,6 +1260,18 @@ public class Vala.GIdlParser : CodeVisitor { finish_method_base = m.name; } var finish_method = type_symbol.scope.lookup (finish_method_base + "_finish") as Method; + + // check if the method is using non-standard finish method name + if (finish_method == null) { + var method_cname = m.get_finish_cname (); + foreach (Method method in type_symbol.get_methods ()) { + if (method.get_cname () == method_cname) { + finish_method = method; + break; + } + } + } + if (finish_method != null) { m.return_type = finish_method.return_type.copy (); foreach (var param in finish_method.get_parameters ()) { @@ -1652,6 +1664,8 @@ public class Vala.GIdlParser : CodeVisitor { } } else if (nv[0] == "vfunc_name") { m.vfunc_name = eval (nv[1]); + } else if (nv[0] == "finish_name") { + m.set_finish_cname (eval (nv[1])); } else if (nv[0] == "async") { if (eval (nv[1]) == "1") { // force async function, even if it doesn't end in _async -- 2.47.3