]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vapigen: Support finish_name attribute for async methods
authorMichal Hruby <michal.mhr@gmail.com>
Wed, 28 Apr 2010 12:23:30 +0000 (14:23 +0200)
committerJürg Billeter <j@bitron.ch>
Wed, 28 Apr 2010 12:23:30 +0000 (14:23 +0200)
vala/valacodewriter.vala
vala/valamethod.vala
vapigen/valagidlparser.vala

index f75691f036d3fba8e9822cef98ec0f88f66b1067..cb9c70cf55c4269a4ffe7cfbbe26284a3592010a 100644 (file)
@@ -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 = ", ";
index e91008a8e8d387a2b3c3f1e8896e1ccb4878f746..36196385e0f73a3686ba4648c12ffc2d74554899 100644 (file)
@@ -233,6 +233,7 @@ public class Vala.Method : Member {
 
        private List<FormalParameter> parameters = new ArrayList<FormalParameter> ();
        private string cname;
+       private string finish_name;
        private string _vfunc_name;
        private string _sentinel;
        private List<Expression> preconditions = new ArrayList<Expression> ();
@@ -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");
                }
index 87bed68f56b58019f0bce7a7ad33b8a571fe7bde..a4c5a92e4eed342798af25c1ee0a3bafc1fa70d3 100644 (file)
@@ -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