+2008-03-05 Jürg Billeter <j@bitron.ch>
+
+ * vala/valaclasstype.vala, vala/valadatatype.vala,
+ vala/valainterfacetype.vala, vala/valainvalidtype.vala,
+ vala/valatypeparametertype.vala, vala/valavaluetype.vala,
+ vala/valavoidtype.vala, gobject/valaccodegenerator.vala,
+ gobject/valaccodegeneratorinvocationexpression.vala,
+ gobject/valaccodegeneratormemberaccess.vala,
+ gobject/valadbusbindingprovider.vala:
+
+ Mark DataType as abstract base class
+
2008-03-04 Jürg Billeter <j@bitron.ch>
* vala/Makefile.am, vala/valasemanticanalyzer.vala,
if (field.instance) {
var length_cname = get_array_length_cname (field.name, dim);
- var instance_expression_type = new DataType ();
- instance_expression_type.data_type = base_type;
- var instance_target_type = new DataType ();
- instance_target_type.data_type = (Typesymbol) field.parent_symbol;
+ var instance_expression_type = get_data_type_for_symbol (base_type);
+ var instance_target_type = get_data_type_for_symbol ((Typesymbol) field.parent_symbol);
CCodeExpression typed_inst = get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
CCodeExpression inst;
}
if (field.instance) {
- var instance_expression_type = new DataType ();
- instance_expression_type.data_type = base_type;
- var instance_target_type = new DataType ();
- instance_target_type.data_type = (Typesymbol) field.parent_symbol;
+ var instance_expression_type = get_data_type_for_symbol (base_type);
+ var instance_target_type = get_data_type_for_symbol ((Typesymbol) field.parent_symbol);
CCodeExpression typed_inst = get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
CCodeExpression inst;
foreach (MemberInitializer init in expr.get_object_initializer ()) {
if (init.symbol_reference is Field) {
var f = (Field) init.symbol_reference;
- var instance_target_type = new DataType ();
- instance_target_type.data_type = (Typesymbol) f.parent_symbol;
+ var instance_target_type = get_data_type_for_symbol ((Typesymbol) f.parent_symbol);
var typed_inst = get_implicit_cast_expression (instance, expr.type_reference, instance_target_type);
CCodeExpression lhs;
if (expr.type_reference.data_type is Struct) {
DataType instance_expression_type;
if (ma.inner == null) {
instance = new CCodeIdentifier ("self");
- instance_expression_type = new DataType ();
- instance_expression_type.data_type = current_type_symbol;
+ instance_expression_type = get_data_type_for_symbol (current_type_symbol);
} else {
instance = (CCodeExpression) ma.inner.ccodenode;
instance_expression_type = ma.inner.static_type;
}
- var instance_target_type = new DataType ();
- instance_target_type.data_type = (Typesymbol) base_property.parent_symbol;
+ var instance_target_type = get_data_type_for_symbol ((Typesymbol) base_property.parent_symbol);
instance = get_implicit_cast_expression (instance, instance_expression_type, instance_target_type);
ccall.add_argument (instance);
return wrappers.add (wrapper_name);
}
+ public static DataType get_data_type_for_symbol (Typesymbol sym) {
+ DataType type = null;
+
+ if (sym is Class) {
+ type = new ClassType ((Class) sym);
+ } else if (sym is Interface) {
+ type = new InterfaceType ((Interface) sym);
+ } else if (sym is Struct) {
+ type = new ValueType ((Struct) sym);
+ } else if (sym is Enum) {
+ type = new ValueType ((Enum) sym);
+ } else {
+ Report.error (null, "internal error: `%s' is not a supported type".printf (sym.get_full_name ()));
+ return new InvalidType ();
+ }
+
+ return type;
+ }
+
public override CodeBinding create_namespace_binding (Namespace! node) {
return null;
}
DataType instance_expression_type;
if (ma.inner == null) {
instance = new CCodeIdentifier ("self");
- instance_expression_type = new DataType ();
- instance_expression_type.data_type = current_type_symbol;
+ instance_expression_type = get_data_type_for_symbol (current_type_symbol);
} else {
instance = (CCodeExpression) ma.inner.ccodenode;
instance_expression_type = ma.inner.static_type;
// parent_symbol may be null for late bound methods
if (base_method.parent_symbol != null) {
- var instance_target_type = new DataType ();
+ var instance_target_type = ma.static_type.copy ();
instance_target_type.data_type = (Typesymbol) base_method.parent_symbol;
instance = get_implicit_cast_expression (instance, instance_expression_type, instance_target_type);
}
ccall.add_argument (get_dbus_array_type (array_type));
- var garray_type_reference = new DataType ();
- garray_type_reference.data_type = garray_type;
+ var garray_type_reference = get_data_type_for_symbol (garray_type);
var temp_decl = get_temp_variable_declarator (garray_type_reference);
temp_vars.insert (0, temp_decl);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_decl.name)));
var f = (Field) expr.symbol_reference;
if (f.instance) {
var instance_expression_type = base_type;
- var instance_target_type = new DataType ();
- instance_target_type.data_type = (Typesymbol) f.parent_symbol;
+ var instance_target_type = get_data_type_for_symbol ((Typesymbol) f.parent_symbol);
CCodeExpression typed_inst = get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
bool is_gtypeinstance = (instance_target_type.data_type.is_subtype_of (gtypeinstance_type));
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_get_%s".printf (base_property_type.get_lower_case_cname (null), base_property.name)));
var instance_expression_type = base_type;
- var instance_target_type = new DataType ();
- instance_target_type.data_type = base_property_type;
+ var instance_target_type = get_data_type_for_symbol (base_property_type);
CCodeExpression typed_pub_inst = get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
ccall.add_argument (typed_pub_inst);
if (sig.has_emitter) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_%s".printf (cl.get_lower_case_cname (null), sig.name)));
var instance_expression_type = base_type;
- var instance_target_type = new DataType ();
- instance_target_type.data_type = cl;
+ var instance_target_type = get_data_type_for_symbol (cl);
CCodeExpression typed_pub_inst = get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
ccall.add_argument (typed_pub_inst);
/* valadbusbindingprovider.vala
*
- * Copyright (C) 2007 Jürg Billeter
+ * Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
} else if (ma.inner != null && ma.inner.static_type != null && is_dbus_interface (ma.inner.static_type)) {
if (ma.parent_node is InvocationExpression) {
var expr = (InvocationExpression) ma.parent_node;
- var ret_type = new DataType ();
+ DataType ret_type;
if (expr.expected_type != null) {
- ret_type.data_type = expr.expected_type.data_type;
+ ret_type = CCodeGenerator.get_data_type_for_symbol (expr.expected_type.data_type);
ret_type.transfers_ownership = ret_type.data_type.is_reference_type ();
+ } else {
+ ret_type = new VoidType ();
}
var m = new DBusMethod (ma.member_name, ret_type, ma.source_reference);
if (expr.expected_type != null) {
- var error_type = new DataType ();
- error_type.data_type = dbus_error_type;
+ var error_type = CCodeGenerator.get_data_type_for_symbol (dbus_error_type);
m.add_error_domain (error_type);
}
m.access = SymbolAccessibility.PUBLIC;
/* valaclasstype.vala
*
- * Copyright (C) 2007 Jürg Billeter
+ * Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
public ClassType (construct Class! class_symbol) {
data_type = class_symbol;
}
+
+ public override DataType copy () {
+ var result = new ClassType (class_symbol);
+ result.source_reference = source_reference;
+ result.transfers_ownership = transfers_ownership;
+ result.takes_ownership = takes_ownership;
+ result.is_out = is_out;
+ result.nullable = nullable;
+ result.requires_null_check = requires_null_check;
+ result.floating_reference = floating_reference;
+ result.is_ref = is_ref;
+
+ foreach (DataType arg in get_type_arguments ()) {
+ result.add_type_argument (arg.copy ());
+ }
+
+ return result;
+ }
}
* A reference to a data type. This is used to specify static types of
* expressions.
*/
-public class Vala.DataType : CodeNode {
+public abstract class Vala.DataType : CodeNode {
/**
* Specifies that the expression transfers ownership of its value.
*/
public bool is_ref { get; set; }
private Gee.List<DataType> type_argument_list = new ArrayList<DataType> ();
-
- public DataType () {
- }
/**
* Appends the specified type as generic type argument.
*
* @return copy of this type reference
*/
- public virtual DataType! copy () {
- var result = new DataType ();
- result.source_reference = source_reference;
- result.transfers_ownership = transfers_ownership;
- result.takes_ownership = takes_ownership;
- result.is_out = is_out;
- result.nullable = nullable;
- result.requires_null_check = requires_null_check;
- result.data_type = data_type;
- result.type_parameter = type_parameter;
- result.floating_reference = floating_reference;
- result.is_ref = is_ref;
-
- foreach (DataType arg in type_argument_list) {
- result.type_argument_list.add (arg.copy ());
- }
-
- return result;
- }
-
+ public abstract DataType copy ();
+
/**
* Checks two type references for equality. May only be used with
* resolved type references.
/* valainterfacetype.vala
*
- * Copyright (C) 2007 Jürg Billeter
+ * Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
public InterfaceType (construct Interface! interface_symbol) {
data_type = interface_symbol;
}
+
+ public override DataType copy () {
+ var result = new InterfaceType (interface_symbol);
+ result.source_reference = source_reference;
+ result.transfers_ownership = transfers_ownership;
+ result.takes_ownership = takes_ownership;
+ result.is_out = is_out;
+ result.nullable = nullable;
+ result.requires_null_check = requires_null_check;
+ result.floating_reference = floating_reference;
+ result.is_ref = is_ref;
+
+ foreach (DataType arg in get_type_arguments ()) {
+ result.add_type_argument (arg.copy ());
+ }
+
+ return result;
+ }
}
/* valainvalidtype.vala
*
- * Copyright (C) 2007 Jürg Billeter
+ * Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
public InvalidType () {
error = true;
}
+
+ public override DataType copy () {
+ return new InvalidType ();
+ }
}
public TypeParameterType (TypeParameter type_parameter) {
this.type_parameter = type_parameter;
}
+
+ public override DataType copy () {
+ var result = new TypeParameterType (type_parameter);
+ result.source_reference = source_reference;
+ result.transfers_ownership = transfers_ownership;
+ result.takes_ownership = takes_ownership;
+ result.is_out = is_out;
+ result.nullable = nullable;
+ result.requires_null_check = requires_null_check;
+ result.floating_reference = floating_reference;
+ result.is_ref = is_ref;
+
+ return result;
+ }
}
/* valavaluetype.vala
*
- * Copyright (C) 2007 Jürg Billeter
+ * Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
public ValueType (construct Typesymbol! type_symbol) {
data_type = type_symbol;
}
+
+ public override DataType copy () {
+ var result = new ValueType (type_symbol);
+ result.source_reference = source_reference;
+ result.transfers_ownership = transfers_ownership;
+ result.takes_ownership = takes_ownership;
+ result.is_out = is_out;
+ result.nullable = nullable;
+ result.requires_null_check = requires_null_check;
+ result.floating_reference = floating_reference;
+ result.is_ref = is_ref;
+
+ foreach (DataType arg in get_type_arguments ()) {
+ result.add_type_argument (arg.copy ());
+ }
+
+ return result;
+ }
}
public override string get_cname (bool var_type = false, bool const_type = false) {
return "void";
}
+
+ public override DataType copy () {
+ return new VoidType ();
+ }
}