[valadoc] libvaladoc/api: TypeReference: Improve is_weak & is_unowned
- From: Florian Brosch <flobrosch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [valadoc] libvaladoc/api: TypeReference: Improve is_weak & is_unowned
- Date: Thu, 24 Feb 2011 01:33:02 +0000 (UTC)
commit 1160c9528d03216e0c36a83c0fbd408b314f5e30
Author: Florian Brosch <flo brosch gmail com>
Date: Fri Feb 18 01:40:07 2011 +0100
libvaladoc/api: TypeReference: Improve is_weak & is_unowned
src/libvaladoc/api/typereference.vala | 45 +++++++++++----------------------
1 files changed, 15 insertions(+), 30 deletions(-)
---
diff --git a/src/libvaladoc/api/typereference.vala b/src/libvaladoc/api/typereference.vala
index e31b2f3..412da42 100644
--- a/src/libvaladoc/api/typereference.vala
+++ b/src/libvaladoc/api/typereference.vala
@@ -78,34 +78,25 @@ public class Valadoc.Api.TypeReference : Item {
}
return ((Vala.Parameter)parent).variable_type.value_owned;
}
+
return false;
}
}
public bool is_weak {
get {
- return false;
- }
- }
-
+ if (vtyperef == null) {
+ return false;
+ }
- // from vala/valacodewriter.vala
- private bool is_weak_helper (Vala.DataType type) {
- if (type.value_owned) {
- return false;
- } else if (type is Vala.VoidType || type is Vala.PointerType) {
- return false;
- } else if (type is Vala.ValueType) {
- if (type.nullable) {
- // nullable structs are heap allocated
- return true;
+ // non ref counted types are unowned, not weak
+ if (vtyperef.data_type is Vala.TypeSymbol && ((Vala.TypeSymbol) vtyperef.data_type).is_reference_counting () == false) {
+ return false;
}
- // TODO return true for structs with destroy
- return false;
+ // FormalParameters are weak by default
+ return (parent is FormalParameter == false)? vtyperef.is_weak () : false;
}
-
- return true;
}
public bool is_dynamic {
@@ -116,23 +107,17 @@ public class Valadoc.Api.TypeReference : Item {
public bool is_unowned {
get {
- Vala.CodeNode parent = this.vtyperef.parent_node;
-
- if (parent is Vala.Parameter) {
+ if (vtyperef == null) {
return false;
}
- if (parent is Vala.Method == true) {
- return this.is_weak_helper (((Vala.Method)parent).return_type);
- }
- else if (parent is Vala.Signal == true) {
- return this.is_weak_helper (((Vala.Signal)parent).return_type);
- }
- else if (parent is Vala.Delegate == true) {
- return this.is_weak_helper (((Vala.Delegate)parent).return_type);
+ // non ref counted types are weak, not unowned
+ if (vtyperef.data_type is Vala.TypeSymbol && ((Vala.TypeSymbol) vtyperef.data_type).is_reference_counting () == true) {
+ return false;
}
- return ( this.vtyperef.parent_node is Field )? this.is_weak_helper(this.vtyperef) : false;
+ // FormalParameters are weak by default
+ return (parent is FormalParameter == false)? vtyperef.is_weak () : false;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]