]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Handle delegate aliases
authorLuca Bruno <lucabru@src.gnome.org>
Fri, 3 Jan 2014 19:04:05 +0000 (20:04 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Sat, 4 Jan 2014 12:06:04 +0000 (13:06 +0100)
Fixes bug 667751

tests/Makefile.am
tests/gir/bug667751.test [new file with mode: 0644]
vala/valagirparser.vala
vala/valaparameter.vala

index f7dca48076488f4a2cc7069a3223d24864bd5b46..6a36a4dd39c051789df7b96e3e1b9df4ce87b4e8 100644 (file)
@@ -185,6 +185,7 @@ TESTS = \
        dbus/bug596862.vala \
        dbus/bug602003.test \
        gir/bug651773.test \
+       gir/bug667751.test \
        $(NULL)
 
 check-TESTS: $(TESTS)
diff --git a/tests/gir/bug667751.test b/tests/gir/bug667751.test
new file mode 100644 (file)
index 0000000..dfba916
--- /dev/null
@@ -0,0 +1,33 @@
+GIR
+
+Input:
+
+<alias name="RemoteConnectionCommitFunc"
+ c:type="NMRemoteConnectionCommitFunc">
+ <type name="RemoteConnectionResultFunc"
+  c:type="NMRemoteConnectionResultFunc"/>
+</alias>
+
+<callback name="RemoteConnectionResultFunc"
+ c:type="NMRemoteConnectionResultFunc">
+ <return-value transfer-ownership="none">
+  <type name="none" c:type="void"/>
+ </return-value>
+ <parameters>
+  <parameter name="error" transfer-ownership="none">
+   <doc xml:whitespace="preserve">on failure, a descriptive error</doc>
+   <type name="GLib.Error" c:type="GError*"/>
+  </parameter>
+  <parameter name="user_data" transfer-ownership="none" closure="1">
+   <doc xml:whitespace="preserve">user data passed to function which began the operation</doc>
+   <type name="gpointer" c:type="gpointer"/>
+  </parameter>
+ </parameters>
+</callback>
+
+Output:
+
+[CCode (cheader_filename = "test.h", cname = "NMRemoteConnectionResultFunc", instance_pos = 1.9)]
+public delegate void RemoteConnectionCommitFunc (GLib.Error error);
+[CCode (cheader_filename = "test.h", cname = "NMRemoteConnectionResultFunc", instance_pos = 1.9)]
+public delegate void RemoteConnectionResultFunc (GLib.Error error);
index 8a2fb1b21b12f4cb1dd9930202328d986434c03b..8956fa58c55731129e07c73ed0f0b3b1e97b7c9a 100644 (file)
@@ -1,7 +1,7 @@
 /* valagirparser.vala
  *
  * Copyright (C) 2008-2012  Jürg Billeter
- * Copyright (C) 2011  Luca Bruno
+ * Copyright (C) 2011-2014  Luca Bruno
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -524,7 +524,7 @@ public class Vala.GirParser : CodeVisitor {
                public Node (string? name) {
                        this.name = name;
                }
-
+                       
                public void add_member (Node node) {
                        var nodes = scope[node.name];
                        if (nodes == null) {
@@ -772,7 +772,7 @@ public class Vala.GirParser : CodeVisitor {
                                        }
                                }
                        }
-
+                       
                        if (symbol is Class && girdata != null) {
                                var class_struct = girdata["glib:type-struct"];
                                if (class_struct != null) {
@@ -3289,16 +3289,23 @@ public class Vala.GirParser : CodeVisitor {
                   to guess it from the base type */
                DataType base_type = null;
                Symbol type_sym = null;
+               Node base_node = null;
                bool simple_type = false;
                if (alias.base_type is UnresolvedType) {
                        base_type = alias.base_type;
-                       type_sym = resolve_symbol (alias.parent, ((UnresolvedType) base_type).unresolved_symbol);
+                       base_node = resolve_node (alias.parent, ((UnresolvedType) base_type).unresolved_symbol);
+                       if (base_node != null) {
+                               type_sym = base_node.symbol;
+                       }
                } else if (alias.base_type is PointerType && ((PointerType) alias.base_type).base_type is VoidType) {
                        // gpointer, if it's a struct make it a simpletype
                        simple_type = true;
                } else {
                        base_type = alias.base_type;
                        type_sym = base_type.data_type;
+                       if (type_sym != null) {
+                               base_node = resolve_node (alias.parent, parse_symbol_from_string (type_sym.get_full_name (), alias.source_reference));
+                       }
                }
 
                if (type_sym is Struct && ((Struct) type_sym).is_simple_type ()) {
@@ -3325,10 +3332,41 @@ public class Vala.GirParser : CodeVisitor {
                        cl.comment = alias.comment;
                        cl.external = true;
                        alias.symbol = cl;
+               } else if (type_sym is Delegate) {
+                       var orig = (Delegate) type_sym;
+                       if (base_node != null) {
+                               base_node.process (this);
+                               orig = (Delegate) base_node.symbol;
+                       }
+                       
+                       var deleg = new Delegate (alias.name, orig.return_type.copy (), alias.source_reference);
+                       deleg.access = orig.access;
+                       deleg.has_target = orig.has_target;
+                       
+                       foreach (var param in orig.get_parameters ()) {
+                               deleg.add_parameter (param.copy ());
+                       }
+                       
+                       foreach (var error_type in orig.get_error_types ()) {
+                               deleg.add_error_type (error_type.copy ());
+                       }
+                       
+                       foreach (var attribute in orig.attributes) {
+                               deleg.attributes.append (attribute);
+                       }
+                       
+                       deleg.external = true;
+                       
+                       alias.symbol = deleg;
                }
        }
 
        void process_callable (Node node) {
+               if (node.element_type == "alias" && node.symbol is Delegate) {
+                       // processed in parse_alias
+                       return;
+               }
+               
                var s = node.symbol;
                List<ParameterInfo> parameters = node.parameters;
 
index e65703dc282735023738fdec6345f8605e8ccebe..2a89e69912111d48a8f5386d7141bf857e9f5473 100644 (file)
@@ -102,7 +102,7 @@ public class Vala.Parameter : Variable {
 
        public Parameter copy () {
                if (!ellipsis) {
-                       var result = new Parameter (name, variable_type, source_reference);
+                       var result = new Parameter (name, variable_type.copy (), source_reference);
                        result.params_array = params_array;
                        result.direction = this.direction;
                        result.initializer = this.initializer;