diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-08-26 13:20:18 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-08-28 08:39:58 +0200 |
commit | 092485ea41d890a19668286ac6d712a03e26cb19 (patch) | |
tree | 5a81de4d8de17fd71f99aa942bfe3d8272d83229 | |
parent | fe187b5e285377875a105eeef795c288ebc4ecb4 (diff) | |
download | vala-092485ea41d890a19668286ac6d712a03e26cb19.tar.gz |
girparser: Improve evalution of instance-parameter information
See https://gitlab.gnome.org/GNOME/vala/issues/836
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/gir/instance-parameter-owned.test | 50 | ||||
-rw-r--r-- | vala/valagirparser.vala | 24 |
3 files changed, 70 insertions, 5 deletions
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: + +<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 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--; |