Commit ff5a94fe authored by Rico Tzschichholz's avatar Rico Tzschichholz

Move type_parameter property to GenericType

parent 55be33eb
...@@ -480,7 +480,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { ...@@ -480,7 +480,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
function.add_parameter (new CCodeParameter ("length", "int")); function.add_parameter (new CCodeParameter ("length", "int"));
if (array_type.element_type is GenericType) { if (array_type.element_type is GenericType) {
// dup function array elements // 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")); function.add_parameter (new CCodeParameter (func_name, "GBoxedCopyFunc"));
} }
......
...@@ -2591,7 +2591,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -2591,7 +2591,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return local; 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 if (current_symbol != null && type.type_parameter.parent_symbol is TypeSymbol
&& (current_method == null || current_method.binding == MemberBinding.INSTANCE)) { && (current_method == null || current_method.binding == MemberBinding.INSTANCE)) {
return true; return true;
...@@ -2610,13 +2610,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -2610,13 +2610,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public CCodeExpression get_type_id_expression (DataType type, bool is_chainup = false) { public CCodeExpression get_type_id_expression (DataType type, bool is_chainup = false) {
if (type is GenericType) { 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) { if (type_parameter.parent_symbol is Interface) {
var iface = (Interface) type.type_parameter.parent_symbol; var iface = (Interface) type_parameter.parent_symbol;
require_generic_accessors (iface); 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)))); var cast_self = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface))));
cast_self.add_argument (new CCodeIdentifier ("self")); cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name)); var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
...@@ -2624,7 +2625,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -2624,7 +2625,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return function_call; 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); return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), var_name);
} else { } else {
return get_variable_cexpression (var_name); return get_variable_cexpression (var_name);
...@@ -2679,13 +2680,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -2679,13 +2680,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return new CCodeIdentifier (dup_function); return new CCodeIdentifier (dup_function);
} else if (type is GenericType) { } 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) { if (type_parameter.parent_symbol is Interface) {
var iface = (Interface) type.type_parameter.parent_symbol; var iface = (Interface) type_parameter.parent_symbol;
require_generic_accessors (iface); 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)))); var cast_self = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface))));
cast_self.add_argument (new CCodeIdentifier ("self")); cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name)); var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
...@@ -2693,7 +2695,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -2693,7 +2695,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return function_call; 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); return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), func_name);
} else { } else {
return get_variable_cexpression (func_name); return get_variable_cexpression (func_name);
...@@ -3177,13 +3179,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -3177,13 +3179,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
} }
return new CCodeIdentifier (unref_function); return new CCodeIdentifier (unref_function);
} else if (type is GenericType) { } 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) { if (type_parameter.parent_symbol is Interface) {
var iface = (Interface) type.type_parameter.parent_symbol; var iface = (Interface) type_parameter.parent_symbol;
require_generic_accessors (iface); 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)))); var cast_self = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface))));
cast_self.add_argument (new CCodeIdentifier ("self")); cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name)); var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
...@@ -3191,7 +3194,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -3191,7 +3194,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return function_call; 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); return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), func_name);
} else { } else {
return get_variable_cexpression (func_name); return get_variable_cexpression (func_name);
...@@ -3383,7 +3386,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -3383,7 +3386,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cvar, new CCodeConstant ("NULL")); var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cvar, new CCodeConstant ("NULL"));
if (type is GenericType) { if (type is GenericType) {
var parent = type.type_parameter.parent_symbol; var parent = ((GenericType) type).type_parameter.parent_symbol;
var cl = parent as Class; var cl = parent as Class;
if ((!(parent is Method) && !(parent is ObjectTypeSymbol)) || (cl != null && cl.is_compact)) { if ((!(parent is Method) && !(parent is ObjectTypeSymbol)) || (cl != null && cl.is_compact)) {
return new CCodeConstant ("NULL"); return new CCodeConstant ("NULL");
...@@ -3848,8 +3851,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -3848,8 +3851,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public override void visit_expression (Expression expr) { public override void visit_expression (Expression expr) {
if (get_cvalue (expr) != null && !expr.lvalue) { if (get_cvalue (expr) != null && !expr.lvalue) {
if (expr.formal_value_type is GenericType && !(expr.value_type is GenericType)) { 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; var type_parameter = ((GenericType) expr.formal_value_type).type_parameter;
if (expr.formal_value_type.type_parameter.parent_symbol != garray_type && 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")) { (st == null || get_ccode_name (st) != "va_list")) {
// GArray and va_list don't use pointer-based generics // GArray and va_list don't use pointer-based generics
set_cvalue (expr, convert_from_generic_pointer (get_cvalue (expr), expr.value_type)); set_cvalue (expr, convert_from_generic_pointer (get_cvalue (expr), expr.value_type));
...@@ -3869,7 +3873,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -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 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 // GArray doesn't use pointer-based generics
set_cvalue (expr, convert_to_generic_pointer (get_cvalue (expr), expr.target_type)); set_cvalue (expr, convert_to_generic_pointer (get_cvalue (expr), expr.target_type));
((GLibValue) expr.target_value).lvalue = false; ((GLibValue) expr.target_value).lvalue = false;
...@@ -4095,7 +4099,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -4095,7 +4099,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return null; 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 cl = type.type_parameter.parent_symbol as Class;
var st = type.type_parameter.parent_symbol as Struct; var st = type.type_parameter.parent_symbol as Struct;
if ((cl != null && cl.is_compact) || st != null) { if ((cl != null && cl.is_compact) || st != null) {
...@@ -4119,7 +4123,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -4119,7 +4123,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
} }
if (type is GenericType) { if (type is GenericType) {
if (is_limited_generic_type (type)) { if (is_limited_generic_type ((GenericType) type)) {
return false; return false;
} }
} }
...@@ -4145,7 +4149,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ...@@ -4145,7 +4149,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
} }
if (type is GenericType) { if (type is GenericType) {
if (is_limited_generic_type (type)) { if (is_limited_generic_type ((GenericType) type)) {
return false; return false;
} }
} }
......
...@@ -791,8 +791,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { ...@@ -791,8 +791,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
var result_type = itype.get_return_type (); var result_type = itype.get_return_type ();
if (expr.formal_value_type is GenericType && !(expr.value_type is GenericType)) { 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; var type_parameter = ((GenericType) expr.formal_value_type).type_parameter;
if (expr.formal_value_type.type_parameter.parent_symbol == garray_type || 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")) { (st != null && get_ccode_name (st) == "va_list")) {
// GArray and va_list don't use pointer-based generics // GArray and va_list don't use pointer-based generics
// above logic copied from visit_expression () // above logic copied from visit_expression ()
......
...@@ -44,11 +44,6 @@ public abstract class Vala.DataType : CodeNode { ...@@ -44,11 +44,6 @@ public abstract class Vala.DataType : CodeNode {
*/ */
public weak TypeSymbol data_type { get; set; } 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. * Specifies that the expression transfers a floating reference.
*/ */
......
...@@ -26,6 +26,11 @@ using GLib; ...@@ -26,6 +26,11 @@ using GLib;
* The type of a generic type parameter. * The type of a generic type parameter.
*/ */
public class Vala.GenericType : DataType { public class Vala.GenericType : DataType {
/**
* The referred generic type parameter.
*/
public TypeParameter type_parameter { get; set; }
public GenericType (TypeParameter type_parameter) { public GenericType (TypeParameter type_parameter) {
this.type_parameter = type_parameter; this.type_parameter = type_parameter;
// type parameters are always considered nullable // type parameters are always considered nullable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment