[vala/0.40: 1/5] libvaladoc: Fix parameter and property ownership declarations
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40: 1/5] libvaladoc: Fix parameter and property ownership declarations
- Date: Mon, 14 Oct 2019 12:58:52 +0000 (UTC)
commit 1c87f1ac3a1031f9ab61fb011af58f096739a47d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Oct 10 17:40:44 2019 +0200
libvaladoc: Fix parameter and property ownership declarations
valadoc/tests/drivers/api-test.data.vapi | 2 +
valadoc/tests/drivers/generic-api-test.vala | 74 +++++++++++++++++++++++++++++
valadoc/treebuilder.vala | 28 ++++++++---
3 files changed, 98 insertions(+), 6 deletions(-)
---
diff --git a/valadoc/tests/drivers/api-test.data.vapi b/valadoc/tests/drivers/api-test.data.vapi
index ec791b462..516ae3fe5 100644
--- a/valadoc/tests/drivers/api-test.data.vapi
+++ b/valadoc/tests/drivers/api-test.data.vapi
@@ -95,7 +95,9 @@ namespace ParamTest {
public void test_function_param_1 ();
public void test_function_param_2 (int a);
public void test_function_param_3 (ref int a);
+ public void test_function_param_3a (ref unowned string? a);
public void test_function_param_4 (out int a);
+ public void test_function_param_4a (out unowned string? a);
public void test_function_param_5 (owned Object o);
public void test_function_param_6 (int? a);
public void test_function_param_7 (...);
diff --git a/valadoc/tests/drivers/generic-api-test.vala b/valadoc/tests/drivers/generic-api-test.vala
index 6448283ef..a5cb74887 100644
--- a/valadoc/tests/drivers/generic-api-test.vala
+++ b/valadoc/tests/drivers/generic-api-test.vala
@@ -1541,7 +1541,9 @@ public static void param_test (Api.Namespace ns, Api.Package pkg) {
bool func1 = false;
bool func2 = false;
bool func3 = false;
+ bool func3a = false;
bool func4 = false;
+ bool func4a = false;
bool func5 = false;
bool func6 = false;
bool func7 = false;
@@ -1663,6 +1665,41 @@ public static void param_test (Api.Namespace ns, Api.Package pkg) {
func3 = true;
break;
+ case "test_function_param_3a":
+ assert (params.size == 1);
+
+ Api.FormalParameter param = params.get (0) as Api.FormalParameter;
+ assert (param != null);
+ // (.FormalParameter)
+ assert (param.default_value == null);
+ assert (param.is_out == false);
+ assert (param.is_ref == true);
+ assert (param.has_default_value == false);
+ assert (param.parameter_type != null);
+ assert (param.ellipsis == false);
+ // (.Symbol check)
+ assert (param.is_deprecated == false);
+ assert (param.accessibility == Api.SymbolAccessibility.PUBLIC);
+ // (.Node)
+ assert (param.get_full_name () == "ParamTest.test_function_param_3a.a");
+ assert (param.get_filename () == "api-test.data.vapi");
+ assert (param.nspace == ns);
+ assert (param.package == pkg);
+ assert (param.name == "a");
+ // param type:
+ assert (param.parameter_type.data_type != null);
+ assert (param.parameter_type.data_type is Api.Class);
+ assert (((Api.Symbol) param.parameter_type.data_type).get_full_name () == "string");
+ assert (param.parameter_type.get_type_arguments ().size == 0);
+ assert (param.parameter_type.is_owned == false);
+ assert (param.parameter_type.is_unowned == true);
+ assert (param.parameter_type.is_weak == false);
+ assert (param.parameter_type.is_dynamic == false);
+ assert (param.parameter_type.is_nullable == true);
+
+ func3a = true;
+ break;
+
case "test_function_param_4":
assert (params.size == 1);
@@ -1699,6 +1736,41 @@ public static void param_test (Api.Namespace ns, Api.Package pkg) {
func4 = true;
break;
+ case "test_function_param_4a":
+ assert (params.size == 1);
+
+ Api.FormalParameter param = params.get (0) as Api.FormalParameter;
+ assert (param != null);
+ // (.FormalParameter)
+ assert (param.default_value == null);
+ assert (param.is_out == true);
+ assert (param.is_ref == false);
+ assert (param.has_default_value == false);
+ assert (param.parameter_type != null);
+ assert (param.ellipsis == false);
+ // (.Symbol check)
+ assert (param.is_deprecated == false);
+ assert (param.accessibility == Api.SymbolAccessibility.PUBLIC);
+ // (.Node)
+ assert (param.get_full_name () == "ParamTest.test_function_param_4a.a");
+ assert (param.get_filename () == "api-test.data.vapi");
+ assert (param.nspace == ns);
+ assert (param.package == pkg);
+ assert (param.name == "a");
+ // param type:
+ assert (param.parameter_type.data_type != null);
+ assert (param.parameter_type.data_type is Api.Class);
+ assert (((Api.Symbol) param.parameter_type.data_type).get_full_name () == "string");
+ assert (param.parameter_type.get_type_arguments ().size == 0);
+ assert (param.parameter_type.is_owned == false);
+ assert (param.parameter_type.is_unowned == true);
+ assert (param.parameter_type.is_weak == false);
+ assert (param.parameter_type.is_dynamic == false);
+ assert (param.parameter_type.is_nullable == true);
+
+ func4a = true;
+ break;
+
case "test_function_param_5":
assert (params.size == 1);
@@ -2257,7 +2329,9 @@ public static void param_test (Api.Namespace ns, Api.Package pkg) {
assert (func1 == true);
assert (func2 == true);
assert (func3 == true);
+ assert (func3a == true);
assert (func4 == true);
+ assert (func4a == true);
assert (func5 == true);
assert (func6 == true);
assert (func7 == true);
diff --git a/valadoc/treebuilder.vala b/valadoc/treebuilder.vala
index 2aafff78c..061cb0c79 100644
--- a/valadoc/treebuilder.vala
+++ b/valadoc/treebuilder.vala
@@ -687,12 +687,28 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
}
private Ownership get_type_reference_ownership (Vala.DataType? element) {
- if (is_type_reference_owned (element)) {
- return Ownership.OWNED;
- } else if (is_type_reference_weak (element)) {
- return Ownership.WEAK;
- } else if (is_type_reference_unowned (element)) {
- return Ownership.UNOWNED;
+ unowned Vala.DataType? type = element;
+ if (type != null) {
+ if (type.parent_node is Vala.Parameter) {
+ if (((Vala.Parameter) type.parent_node).direction ==
Vala.ParameterDirection.IN) {
+ if (type.value_owned) {
+ return Ownership.OWNED;
+ }
+ } else {
+ if (type.is_weak ()) {
+ return Ownership.UNOWNED;
+ }
+ }
+ return Ownership.DEFAULT;
+ } else if (type.parent_node is Vala.PropertyAccessor) {
+ if (((Vala.PropertyAccessor) type.parent_node).value_type.value_owned) {
+ return Ownership.OWNED;
+ }
+ return Ownership.DEFAULT;
+ }
+ if (type.is_weak ()) {
+ return Ownership.UNOWNED;
+ }
}
return Ownership.DEFAULT;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]