From ff5a94fe1912b84c905dfda9b85fc9c7813c3334 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Wed, 6 Dec 2017 20:54:54 +0100 Subject: [PATCH] Move type_parameter property to GenericType --- codegen/valaccodearraymodule.vala | 2 +- codegen/valaccodebasemodule.vala | 50 ++++++++++++++++++---------------- codegen/valaccodemethodcallmodule.vala | 5 ++-- vala/valadatatype.vala | 5 ---- vala/valagenerictype.vala | 5 ++++ 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala index ea0a85ded..6cab68a42 100644 --- a/codegen/valaccodearraymodule.vala +++ b/codegen/valaccodearraymodule.vala @@ -480,7 +480,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { function.add_parameter (new CCodeParameter ("length", "int")); if (array_type.element_type is GenericType) { // dup function array elements - string func_name = "%s_dup_func".printf (array_type.element_type.type_parameter.name.down ()); + string func_name = "%s_dup_func".printf (((GenericType) array_type.element_type).type_parameter.name.down ()); function.add_parameter (new CCodeParameter (func_name, "GBoxedCopyFunc")); } diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index f35645ab4..059399e16 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -2591,7 +2591,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return local; } - bool is_in_generic_type (DataType type) { + bool is_in_generic_type (GenericType type) { if (current_symbol != null && type.type_parameter.parent_symbol is TypeSymbol && (current_method == null || current_method.binding == MemberBinding.INSTANCE)) { return true; @@ -2610,13 +2610,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { public CCodeExpression get_type_id_expression (DataType type, bool is_chainup = false) { if (type is GenericType) { - string var_name = "%s_type".printf (type.type_parameter.name.down ()); + var type_parameter = ((GenericType) type).type_parameter; + string var_name = "%s_type".printf (type_parameter.name.down ()); - if (type.type_parameter.parent_symbol is Interface) { - var iface = (Interface) type.type_parameter.parent_symbol; + if (type_parameter.parent_symbol is Interface) { + var iface = (Interface) type_parameter.parent_symbol; require_generic_accessors (iface); - string method_name = "get_%s_type".printf (type.type_parameter.name.down ()); + string method_name = "get_%s_type".printf (type_parameter.name.down ()); var cast_self = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface)))); cast_self.add_argument (new CCodeIdentifier ("self")); var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name)); @@ -2624,7 +2625,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return function_call; } - if (is_in_generic_type (type) && !is_chainup && !in_creation_method) { + if (is_in_generic_type ((GenericType) type) && !is_chainup && !in_creation_method) { return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), var_name); } else { return get_variable_cexpression (var_name); @@ -2679,13 +2680,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return new CCodeIdentifier (dup_function); } else if (type is GenericType) { - string func_name = "%s_dup_func".printf (type.type_parameter.name.down ()); + var type_parameter = ((GenericType) type).type_parameter; + string func_name = "%s_dup_func".printf (type_parameter.name.down ()); - if (type.type_parameter.parent_symbol is Interface) { - var iface = (Interface) type.type_parameter.parent_symbol; + if (type_parameter.parent_symbol is Interface) { + var iface = (Interface) type_parameter.parent_symbol; require_generic_accessors (iface); - string method_name = "get_%s_dup_func".printf (type.type_parameter.name.down ()); + string method_name = "get_%s_dup_func".printf (type_parameter.name.down ()); var cast_self = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface)))); cast_self.add_argument (new CCodeIdentifier ("self")); var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name)); @@ -2693,7 +2695,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return function_call; } - if (is_in_generic_type (type) && !is_chainup && !in_creation_method) { + if (is_in_generic_type ((GenericType) type) && !is_chainup && !in_creation_method) { return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), func_name); } else { return get_variable_cexpression (func_name); @@ -3177,13 +3179,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } return new CCodeIdentifier (unref_function); } else if (type is GenericType) { - string func_name = "%s_destroy_func".printf (type.type_parameter.name.down ()); + var type_parameter = ((GenericType) type).type_parameter; + string func_name = "%s_destroy_func".printf (type_parameter.name.down ()); - if (type.type_parameter.parent_symbol is Interface) { - var iface = (Interface) type.type_parameter.parent_symbol; + if (type_parameter.parent_symbol is Interface) { + var iface = (Interface) type_parameter.parent_symbol; require_generic_accessors (iface); - string method_name = "get_%s_destroy_func".printf (type.type_parameter.name.down ()); + string method_name = "get_%s_destroy_func".printf (type_parameter.name.down ()); var cast_self = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface)))); cast_self.add_argument (new CCodeIdentifier ("self")); var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name)); @@ -3191,7 +3194,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return function_call; } - if (is_in_generic_type (type) && !is_chainup && !in_creation_method) { + if (is_in_generic_type ((GenericType) type) && !is_chainup && !in_creation_method) { return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), func_name); } else { return get_variable_cexpression (func_name); @@ -3383,7 +3386,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cvar, new CCodeConstant ("NULL")); if (type is GenericType) { - var parent = type.type_parameter.parent_symbol; + var parent = ((GenericType) type).type_parameter.parent_symbol; var cl = parent as Class; if ((!(parent is Method) && !(parent is ObjectTypeSymbol)) || (cl != null && cl.is_compact)) { return new CCodeConstant ("NULL"); @@ -3848,8 +3851,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { public override void visit_expression (Expression expr) { if (get_cvalue (expr) != null && !expr.lvalue) { if (expr.formal_value_type is GenericType && !(expr.value_type is GenericType)) { - var st = expr.formal_value_type.type_parameter.parent_symbol.parent_symbol as Struct; - if (expr.formal_value_type.type_parameter.parent_symbol != garray_type && + var type_parameter = ((GenericType) expr.formal_value_type).type_parameter; + var st = type_parameter.parent_symbol.parent_symbol as Struct; + if (type_parameter.parent_symbol != garray_type && (st == null || get_ccode_name (st) != "va_list")) { // GArray and va_list don't use pointer-based generics set_cvalue (expr, convert_from_generic_pointer (get_cvalue (expr), expr.value_type)); @@ -3869,7 +3873,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } if (expr.formal_target_type is GenericType && !(expr.target_type is GenericType)) { - if (expr.formal_target_type.type_parameter.parent_symbol != garray_type) { + if (((GenericType) expr.formal_target_type).type_parameter.parent_symbol != garray_type) { // GArray doesn't use pointer-based generics set_cvalue (expr, convert_to_generic_pointer (get_cvalue (expr), expr.target_type)); ((GLibValue) expr.target_value).lvalue = false; @@ -4095,7 +4099,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return null; } - bool is_limited_generic_type (DataType type) { + bool is_limited_generic_type (GenericType type) { var cl = type.type_parameter.parent_symbol as Class; var st = type.type_parameter.parent_symbol as Struct; if ((cl != null && cl.is_compact) || st != null) { @@ -4119,7 +4123,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } if (type is GenericType) { - if (is_limited_generic_type (type)) { + if (is_limited_generic_type ((GenericType) type)) { return false; } } @@ -4145,7 +4149,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } if (type is GenericType) { - if (is_limited_generic_type (type)) { + if (is_limited_generic_type ((GenericType) type)) { return false; } } diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index 82a0574c6..acca4eddf 100644 --- a/codegen/valaccodemethodcallmodule.vala +++ b/codegen/valaccodemethodcallmodule.vala @@ -791,8 +791,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { var result_type = itype.get_return_type (); if (expr.formal_value_type is GenericType && !(expr.value_type is GenericType)) { - var st = expr.formal_value_type.type_parameter.parent_symbol.parent_symbol as Struct; - if (expr.formal_value_type.type_parameter.parent_symbol == garray_type || + var type_parameter = ((GenericType) expr.formal_value_type).type_parameter; + var st = type_parameter.parent_symbol.parent_symbol as Struct; + if (type_parameter.parent_symbol == garray_type || (st != null && get_ccode_name (st) == "va_list")) { // GArray and va_list don't use pointer-based generics // above logic copied from visit_expression () diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index 2655e437a..67f4185e8 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -45,11 +45,6 @@ public abstract class Vala.DataType : CodeNode { public weak TypeSymbol data_type { get; set; } /** - * The referred generic type parameter. - */ - public TypeParameter type_parameter { get; set; } - - /** * Specifies that the expression transfers a floating reference. */ public bool floating_reference { get; set; } diff --git a/vala/valagenerictype.vala b/vala/valagenerictype.vala index 66415e6f9..ca8aa657e 100644 --- a/vala/valagenerictype.vala +++ b/vala/valagenerictype.vala @@ -26,6 +26,11 @@ using GLib; * The type of a generic type parameter. */ public class Vala.GenericType : DataType { + /** + * The referred generic type parameter. + */ + public TypeParameter type_parameter { get; set; } + public GenericType (TypeParameter type_parameter) { this.type_parameter = type_parameter; // type parameters are always considered nullable -- 2.11.4.GIT