]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Add Delegate/Method/ObjectTypeSymbol.has_type_parameters() and use them
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 21 Nov 2018 12:18:46 +0000 (13:18 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 21 Nov 2018 18:14:10 +0000 (19:14 +0100)
codegen/valaccodemethodcallmodule.vala
codegen/valaccodemethodmodule.vala
codegen/valagobjectmodule.vala
codegen/valagtypemodule.vala
codegen/valatyperegisterfunction.vala
vala/valadelegate.vala
vala/valamemberaccess.vala
vala/valamethod.vala
vala/valamethodcall.vala
vala/valaobjecttypesymbol.vala
vala/valasignaltype.vala

index 0a9fea272ba7420267536bd6be1c5389bb4a6c8b..18505c247a8d005122aa503601b8835ac9a97a15 100644 (file)
@@ -185,7 +185,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                        }
                } else if (m is CreationMethod && m.parent_symbol is Struct) {
                        ccall.add_argument (get_this_cexpression ());
-               } else if (m != null && m.get_type_parameters ().size > 0 && !get_ccode_has_generic_type_parameter (m) && !get_ccode_simple_generics (m) && (ccall != finish_call || expr.is_yield_expression)) {
+               } else if (m != null && m.has_type_parameters () && !get_ccode_has_generic_type_parameter (m) && !get_ccode_simple_generics (m) && (ccall != finish_call || expr.is_yield_expression)) {
                        // generic method
                        // don't add generic arguments for .end() calls
                        add_generic_type_arguments (in_arg_map, ma.get_type_arguments (), expr);
@@ -270,7 +270,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
                if (m != null && get_ccode_has_generic_type_parameter (m)) {
                        // insert type argument for macros
-                       if (m.get_type_parameters ().size > 0) {
+                       if (m.has_type_parameters ()) {
                                // generic method
                                int type_param_index = 0;
                                foreach (var type_arg in ma.get_type_arguments ()) {
@@ -328,7 +328,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (current_method.body))), "self"), ref_call);
                        }
 
-                       if (!current_class.is_compact && current_class.get_type_parameters ().size > 0) {
+                       if (!current_class.is_compact && current_class.has_type_parameters ()) {
                                /* type, dup func, and destroy func fields for generic types */
                                var suffices = new string[] {"type", "dup_func", "destroy_func"};
                                foreach (TypeParameter type_param in current_class.get_type_parameters ()) {
index c9731a1cad89302261476cf7a434b0d90dca533b..361fb00652d02661ffa9a42776ef65be4f67fb23 100644 (file)
@@ -779,7 +779,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 
 
                                        if (current_type_symbol is Class && gobject_type != null && current_class.is_subtype_of (gobject_type)
-                                           && current_class.get_type_parameters ().size > 0
+                                           && current_class.has_type_parameters ()
                                            && !((CreationMethod) m).chain_up) {
                                                var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN, new CCodeIdentifier ("__params_it"), new CCodeIdentifier ("__params"));
                                                ccode.open_while (ccond);
index 8370467426ccac04f0143470732017370f95b189..05e45e35d12cc4b1e5f86bea1c17923570df152f 100644 (file)
@@ -35,10 +35,10 @@ public class Vala.GObjectModule : GTypeModule {
                }
 
                push_line (cl.source_reference);
-               if (class_has_readable_properties (cl) || cl.get_type_parameters ().size > 0) {
+               if (class_has_readable_properties (cl) || cl.has_type_parameters ()) {
                        add_get_property_function (cl);
                }
-               if (class_has_writable_properties (cl) || cl.get_type_parameters ().size > 0) {
+               if (class_has_writable_properties (cl) || cl.has_type_parameters ()) {
                        add_set_property_function (cl);
                }
                pop_line ();
@@ -52,10 +52,10 @@ public class Vala.GObjectModule : GTypeModule {
                /* set property handlers */
                var ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_CLASS"));
                ccall.add_argument (new CCodeIdentifier ("klass"));
-               if (class_has_readable_properties (cl) || cl.get_type_parameters ().size > 0) {
+               if (class_has_readable_properties (cl) || cl.has_type_parameters ()) {
                        ccode.add_assignment (new CCodeMemberAccess.pointer (ccall, "get_property"), new CCodeIdentifier ("_vala_%s_get_property".printf (get_ccode_lower_case_name (cl, null))));
                }
-               if (class_has_writable_properties (cl) || cl.get_type_parameters ().size > 0) {
+               if (class_has_writable_properties (cl) || cl.has_type_parameters ()) {
                        ccode.add_assignment (new CCodeMemberAccess.pointer (ccall, "set_property"), new CCodeIdentifier ("_vala_%s_set_property".printf (get_ccode_lower_case_name (cl, null))));
                }
 
index d81c530b8a8e756399c7712d7926098236e877b4..32e7bf07c5290a2ea7afe792657c645db78cdecf 100644 (file)
@@ -585,7 +585,7 @@ public class Vala.GTypeModule : GErrorModule {
                        }
 
                        /* only add the *Private struct if it is not empty, i.e. we actually have private data */
-                       if (cl.has_private_fields || cl.get_type_parameters ().size > 0) {
+                       if (cl.has_private_fields || cl.has_type_parameters ()) {
                                decl_space.add_type_definition (instance_priv_struct);
 
                                var parent_decl = new CCodeDeclaration ("gint");
@@ -1296,7 +1296,7 @@ public class Vala.GTypeModule : GErrorModule {
                }
 
                /* add struct for private fields */
-               if (cl.has_private_fields || cl.get_type_parameters ().size > 0) {
+               if (cl.has_private_fields || cl.has_type_parameters ()) {
                        ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_adjust_private_offset"));
                        ccall.add_argument (new CCodeIdentifier ("klass"));
                        ccall.add_argument (new CCodeIdentifier ("&%s_private_offset".printf (get_ccode_name (cl))));
@@ -1702,7 +1702,7 @@ public class Vala.GTypeModule : GErrorModule {
                        }
                }
 
-               if (!cl.is_compact && (cl.has_private_fields || cl.get_type_parameters ().size > 0)) {
+               if (!cl.is_compact && (cl.has_private_fields || cl.has_type_parameters ())) {
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_get_instance_private".printf (get_ccode_lower_case_name (cl, null))));
                        ccall.add_argument (new CCodeIdentifier ("self"));
                        func.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), ccall);
index b78f4d2172d12baa013cd1291903cac182a3f726..394295f9b38f76714af9a1630787fe9da3ff6ec4 100644 (file)
@@ -221,7 +221,7 @@ public abstract class Vala.TypeRegisterFunction {
                        get_type_interface_init_statements (context, type_init, plugin);
                }
 
-               if (cl != null && (cl.has_private_fields || cl.get_type_parameters ().size > 0)) {
+               if (cl != null && (cl.has_private_fields || cl.has_type_parameters ())) {
                        if (!plugin) {
                                var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_add_instance_private"));
                                ccall.add_argument (new CCodeIdentifier (type_id_name));
index 16db6f1b89645062c7d75649d856e8dcd88621fb..4b4e7074ab4ea0a4f436f98ce42e68a6eaa75a58 100644 (file)
@@ -97,6 +97,10 @@ public class Vala.Delegate : TypeSymbol, Callable {
                return type_parameters;
        }
 
+       public bool has_type_parameters () {
+               return (type_parameters != null && type_parameters.size > 0);
+       }
+
        public override int get_type_parameter_index (string name) {
                int i = 0;
                foreach (TypeParameter parameter in type_parameters) {
index d2005f6884ca7fe6e6bf438a7753a377ff00af26..ab6d6a9dc095abec8ba6400292caee036c11fd07 100644 (file)
@@ -769,8 +769,8 @@ public class Vala.MemberAccess : Expression {
                        // instance type might be a subtype of the parent symbol of the member
                        // that subtype might not be generic, so do not report an error in that case
                        var object_type = instance_type as ObjectType;
-                       if (object_type != null && object_type.type_symbol.get_type_parameters ().size > 0 &&
-                           instance_type.get_type_arguments ().size == 0) {
+                       if (object_type != null && object_type.type_symbol.has_type_parameters ()
+                           && !instance_type.has_type_arguments ()) {
                                error = true;
                                Report.error (inner.source_reference, "missing generic type arguments");
                                return false;
index 955de7e000e271c968b9836e254dd8dccf1f3786..7ec91729da96ca2d0ee2b47667684fa25494d940 100644 (file)
@@ -340,7 +340,7 @@ public class Vala.Method : Subroutine, Callable {
                }
 
                List<DataType> method_type_args = null;
-               if (this.get_type_parameters ().size > 0) {
+               if (this.has_type_parameters ()) {
                        method_type_args = new ArrayList<DataType> ();
                        foreach (TypeParameter type_parameter in this.get_type_parameters ()) {
                                var type_arg = new GenericType (type_parameter);
@@ -461,6 +461,10 @@ public class Vala.Method : Subroutine, Callable {
                return -1;
        }
 
+       public bool has_type_parameters () {
+               return (type_parameters != null && type_parameters.size > 0);
+       }
+
        /**
         * Adds a precondition to this method.
         *
index 7fca36e39b613f9afb135ff7716b58e35a37a3b6..3b5917668b9a100bd9bf89d7449fb8795f7435bc 100644 (file)
@@ -535,7 +535,7 @@ public class Vala.MethodCall : Expression {
                                dynamic_sig.handler.target_type = new DelegateType (dynamic_sig.get_delegate (new ObjectType ((ObjectTypeSymbol) dynamic_sig.parent_symbol), this));
                        }
 
-                       if (m != null && m.get_type_parameters ().size > 0) {
+                       if (m != null && m.has_type_parameters ()) {
                                var ma = (MemberAccess) call;
                                if (ma.get_type_arguments ().size == 0) {
                                        // infer type arguments
index eab81c425f6e0b211b6c5275fe61dbfee9817106..66e7f955f33f6847781d494d9d1a09aa373ae765 100644 (file)
@@ -254,6 +254,10 @@ public abstract class Vala.ObjectTypeSymbol : TypeSymbol {
                return type_parameters;
        }
 
+       public bool has_type_parameters () {
+               return (type_parameters != null && type_parameters.size > 0);
+       }
+
        public override int get_type_parameter_index (string name) {
                int i = 0;
                foreach (TypeParameter parameter in type_parameters) {
index 4a36816f0896748c8ae8b098df9ce770a5bf366d..f9a67e90c92aa597ec6b27781cd52556539b2eed 100644 (file)
@@ -66,7 +66,7 @@ public class Vala.SignalType : CallableType {
                var result = new DelegateType (signal_symbol.get_delegate (sender_type, this));
                result.value_owned = true;
 
-               if (result.delegate_symbol.get_type_parameters ().size > 0) {
+               if (result.delegate_symbol.has_type_parameters ()) {
                        foreach (var type_param in type_sym.get_type_parameters ()) {
                                var type_arg = new GenericType (type_param);
                                type_arg.value_owned = true;