From 092485ea41d890a19668286ac6d712a03e26cb19 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Mon, 26 Aug 2019 13:20:18 +0200 Subject: [PATCH] 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(-) create mode 100644 tests/gir/instance-parameter-owned.test diff --git a/tests/Makefile.am b/tests/Makefile.am index 877e71a30..a5bf21ec8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -514,6 +514,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: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +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 0392a59f0..57931ee50 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -3289,11 +3289,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 (); @@ -3311,6 +3308,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--; -- 2.47.2