[vala] girparser: Handle delegate aliases



commit 23cc3054f8069da9679d50084be8262bc944c071
Author: Luca Bruno <lucabru src gnome org>
Date:   Fri Jan 3 20:04:05 2014 +0100

    girparser: Handle delegate aliases
    
    Fixes bug 667751

 tests/Makefile.am        |    1 +
 tests/gir/bug667751.test |   33 +++++++++++++++++++++++++++++++++
 vala/valagirparser.vala  |   46 ++++++++++++++++++++++++++++++++++++++++++----
 vala/valaparameter.vala  |    2 +-
 4 files changed, 77 insertions(+), 5 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f7dca48..6a36a4d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 0000000..dfba916
--- /dev/null
+++ b/tests/gir/bug667751.test
@@ -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);
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 8a2fb1b..8956fa5 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -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;
 
diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala
index e65703d..2a89e69 100644
--- a/vala/valaparameter.vala
+++ b/vala/valaparameter.vala
@@ -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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]