]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc: Clean up Api.TypeReference constructor
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 12 Jun 2018 13:41:41 +0000 (15:41 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 25 Nov 2018 11:27:29 +0000 (12:27 +0100)
libvaladoc/api/typereference.vala
valadoc/treebuilder.vala

index 884b721bc244b2a6b536d50cefca908bce871411..47bf5efc4282df61bdbccfcde64de7f8007be994 100644 (file)
@@ -31,19 +31,112 @@ public class Valadoc.Api.TypeReference : Item {
        private string? dbus_type_signature;
        private Ownership ownership;
 
-       public TypeReference (Item parent, Ownership ownership, bool pass_ownership, bool is_dynamic,
+       public TypeReference (Item parent, bool is_dynamic,
                                                  bool is_nullable, string? dbus_type_signature, Vala.DataType? data)
        {
                base (data);
 
                this.dbus_type_signature = dbus_type_signature;
-               this.pass_ownership = pass_ownership;
+               this.pass_ownership = type_reference_pass_ownership (data);
                this.is_nullable = is_nullable;
                this.is_dynamic = is_dynamic;
-               this.ownership = ownership;
+               this.ownership = get_type_reference_ownership (data);
                this.parent = parent;
        }
 
+       bool is_reference_counting (Vala.TypeSymbol sym) {
+               return Vala.is_reference_counting (sym);
+       }
+
+       bool type_reference_pass_ownership (Vala.DataType? element) {
+               if (element == null) {
+                       return false;
+               }
+
+               weak Vala.CodeNode? node = element.parent_node;
+               if (node == null) {
+                       return false;
+               }
+               if (node is Vala.Parameter) {
+                       return (((Vala.Parameter)node).direction == Vala.ParameterDirection.IN &&
+                               ((Vala.Parameter)node).variable_type.value_owned);
+               }
+               if (node is Vala.Property) {
+                       return ((Vala.Property)node).property_type.value_owned;
+               }
+
+               return false;
+       }
+
+       bool is_type_reference_unowned (Vala.DataType? element) {
+                       if (element == null) {
+                               return false;
+                       }
+
+                       // non ref counted types are weak, not unowned
+                       if (element.data_type is Vala.TypeSymbol
+                               && is_reference_counting ((Vala.TypeSymbol) element.data_type) == true)
+                       {
+                               return false;
+                       }
+
+                       // FormalParameters are weak by default
+                       return (element.parent_node is Vala.Parameter == false)
+                               ? element.is_weak ()
+                               : false;
+       }
+
+       bool is_type_reference_owned (Vala.DataType? element) {
+               if (element == null) {
+                       return false;
+               }
+
+               weak Vala.CodeNode parent = element.parent_node;
+
+               // parameter:
+               if (parent is Vala.Parameter) {
+                       if (((Vala.Parameter)parent).direction != Vala.ParameterDirection.IN) {
+                               return false;
+                       }
+                       return ((Vala.Parameter)parent).variable_type.value_owned;
+               }
+
+               return false;
+       }
+
+       bool is_type_reference_weak (Vala.DataType? element) {
+               if (element == null) {
+                       return false;
+               }
+
+               // non ref counted types are unowned, not weak
+               if (element.data_type is Vala.TypeSymbol
+                       && is_reference_counting ((Vala.TypeSymbol) element.data_type) == false)
+               {
+                       return false;
+               }
+
+               // arrays are unowned, not weak
+               if (element is Vala.ArrayType) {
+                       return false;
+               }
+
+               // FormalParameters are weak by default
+               return (element.parent_node is Vala.Parameter == false)? element.is_weak () : false;
+       }
+
+       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;
+               }
+
+               return Ownership.DEFAULT;
+       }
+
        /**
         * Returns a copy of the list of generic type arguments.
         *
index 7c5d4d112d9dd287727f16d398b901fde5e20532..b0ef026e9b3dd8032697e0863189119d87dfe68d 100644 (file)
@@ -172,13 +172,9 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                        && !(vtyperef is Vala.PointerType);
                string? signature = (vtyperef != null
                        && vtyperef.data_type != null)? Vala.GVariantModule.get_dbus_signature (vtyperef.data_type) : null;
-               bool pass_ownership = type_reference_pass_ownership (vtyperef);
-               Ownership ownership = get_type_reference_ownership (vtyperef);
                bool is_dynamic = vtyperef != null && vtyperef.is_dynamic;
 
                TypeReference type_ref = new TypeReference (parent,
-                                                                                                       ownership,
-                                                                                                       pass_ownership,
                                                                                                        is_dynamic,
                                                                                                        is_nullable,
                                                                                                        signature,
@@ -223,10 +219,6 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                return Vala.get_ccode_type_id (node);
        }
 
-       private bool is_reference_counting (Vala.TypeSymbol sym) {
-               return Vala.is_reference_counting (sym);
-       }
-
        private string? get_ref_function (Vala.Class sym) {
                return Vala.get_ccode_ref_function (sym);
        }
@@ -496,95 +488,6 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                return meta_data.get_namespace ((Vala.Namespace) namespace_symbol, file);
        }
 
-       private bool type_reference_pass_ownership (Vala.DataType? element) {
-               if (element == null) {
-                       return false;
-               }
-
-               weak Vala.CodeNode? node = element.parent_node;
-               if (node == null) {
-                       return false;
-               }
-               if (node is Vala.Parameter) {
-                       return (((Vala.Parameter)node).direction == Vala.ParameterDirection.IN &&
-                               ((Vala.Parameter)node).variable_type.value_owned);
-               }
-               if (node is Vala.Property) {
-                       return ((Vala.Property)node).property_type.value_owned;
-               }
-
-               return false;
-       }
-
-       private bool is_type_reference_unowned (Vala.DataType? element) {
-                       if (element == null) {
-                               return false;
-                       }
-
-                       // non ref counted types are weak, not unowned
-                       if (element.data_type is Vala.TypeSymbol
-                               && is_reference_counting ((Vala.TypeSymbol) element.data_type) == true)
-                       {
-                               return false;
-                       }
-
-                       // FormalParameters are weak by default
-                       return (element.parent_node is Vala.Parameter == false)
-                               ? element.is_weak ()
-                               : false;
-       }
-
-       private bool is_type_reference_owned (Vala.DataType? element) {
-               if (element == null) {
-                       return false;
-               }
-
-               weak Vala.CodeNode parent = element.parent_node;
-
-               // parameter:
-               if (parent is Vala.Parameter) {
-                       if (((Vala.Parameter)parent).direction != Vala.ParameterDirection.IN) {
-                               return false;
-                       }
-                       return ((Vala.Parameter)parent).variable_type.value_owned;
-               }
-
-               return false;
-       }
-
-       private bool is_type_reference_weak (Vala.DataType? element) {
-               if (element == null) {
-                       return false;
-               }
-
-               // non ref counted types are unowned, not weak
-               if (element.data_type is Vala.TypeSymbol
-                       && is_reference_counting ((Vala.TypeSymbol) element.data_type) == false)
-               {
-                       return false;
-               }
-
-               // arrays are unowned, not weak
-               if (element is Vala.ArrayType) {
-                       return false;
-               }
-
-               // FormalParameters are weak by default
-               return (element.parent_node is Vala.Parameter == false)? element.is_weak () : false;
-       }
-
-       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;
-               }
-
-               return Ownership.DEFAULT;
-       }
-
        private Ownership get_property_ownership (Vala.PropertyAccessor element) {
                if (element.value_type.value_owned) {
                        return Ownership.OWNED;