[vala/0.44] girparser: Improve evalution of instance-parameter information



commit f5c00237a00903625e725e8b0ad1e341699cee15
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Aug 26 13:20:18 2019 +0200

    girparser: Improve evalution of instance-parameter information
    
    See https://gitlab.gnome.org/GNOME/vala/issues/836

 tests/Makefile.am                       |  1 +
 tests/gir/instance-parameter-owned.test | 50 +++++++++++++++++++++++++++++++++
 vala/valagirparser.vala                 | 24 ++++++++++++----
 3 files changed, 70 insertions(+), 5 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 075666a1a..77afad93f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -510,6 +510,7 @@ TESTS = \
        gir/delegate-error-pos.test \
        gir/enum.test \
        gir/errordomain.test \
+       gir/instance-parameter-owned.test \
        gir/method-array-length-type.test \
        gir/parameter-array-length-type.test \
        gir/parameter-nullable-out-simple-type.test \
diff --git a/tests/gir/instance-parameter-owned.test b/tests/gir/instance-parameter-owned.test
new file mode 100644
index 000000000..27cf75dcb
--- /dev/null
+++ b/tests/gir/instance-parameter-owned.test
@@ -0,0 +1,50 @@
+GIR
+
+Input:
+
+<record name="Foo"
+        c:type="TestFoo"
+        glib:type-name="TestFoo"
+        glib:get-type="test_foo_get_type"
+        c:symbol-prefix="foo">
+  <constructor name="new" c:identifier="test_foo_new">
+    <return-value transfer-ownership="full">
+      <type name="Transform" c:type="TestFoo*"/>
+    </return-value>
+  </constructor>
+  <method name="bar" c:identifier="test_foo_bar">
+    <return-value transfer-ownership="full">
+      <type name="Foo" c:type="TestFoo*"/>
+    </return-value>
+    <parameters>
+      <instance-parameter name="self"
+                          transfer-ownership="full">
+        <type name="Foo" c:type="TestFoo*"/>
+      </instance-parameter>
+    </parameters>
+  </method>
+  <method name="baz" c:identifier="test_foo_baz">
+    <return-value transfer-ownership="full">
+      <type name="none"/>
+    </return-value>
+    <parameters>
+      <instance-parameter name="self"
+                          transfer-ownership="full">
+        <type name="Foo" c:type="TestFoo*"/>
+      </instance-parameter>
+    </parameters>
+  </method>
+</record>
+
+Output:
+
+[CCode (cheader_filename = "test.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id 
= "test_foo_get_type ()")]
+[Compact]
+public class Foo {
+       [CCode (has_construct_function = false)]
+       public Foo ();
+       [DestroysInstance]
+       public Test.Foo bar ();
+       [DestroysInstance]
+       public void baz ();
+}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 7c4ca6d01..7601485b6 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -3296,11 +3296,8 @@ public class Vala.GirParser : CodeVisitor {
                        while (current_token == MarkupTokenType.START_ELEMENT) {
                                current_parameter_idx++;
 
-                               if (reader.name == "instance-parameter" &&
-                                   !(symbol_type == "function" || symbol_type == "constructor")) {
-                                       skip_element ();
-                                       continue;
-                               }
+                               var is_instance_parameter = (reader.name == "instance-parameter"
+                                       && !(symbol_type == "function" || symbol_type == "constructor"));
 
                                if (instance_idx > -2 && instance_idx == current_parameter_idx) {
                                        skip_element ();
@@ -3318,6 +3315,23 @@ public class Vala.GirParser : CodeVisitor {
                                Comment? param_comment;
                                default_param_name = "arg%d".printf (parameters.size);
                                var param = parse_parameter (out array_length_idx, out closure_idx, out 
destroy_idx, out scope, out param_comment, default_param_name);
+
+                               if (is_instance_parameter) {
+                                       unowned Method? m = s as Method;
+                                       if (m != null) {
+                                               if (param.direction == ParameterDirection.IN) {
+                                                       if (param.variable_type.value_owned) {
+                                                               m.set_attribute ("DestroysInstance", true);
+                                                       }
+                                                       pop_metadata ();
+                                                       continue;
+                                               } else {
+                                                       //TODO can more be done here?
+                                                       m.binding = MemberBinding.STATIC;
+                                               }
+                                       }
+                               }
+
                                if (array_length_idx != -1) {
                                        if (instance_idx > -2 && instance_idx < array_length_idx) {
                                                array_length_idx--;


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