Commit 16f46e8b authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Mark DataType as abstract base class

2008-03-05  Juerg 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

svn path=/trunk/; revision=1104
parent 755de6e5
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,
......
......@@ -2336,10 +2336,8 @@ public class Vala.CCodeGenerator : CodeGenerator {
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;
......@@ -2461,10 +2459,8 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
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;
......@@ -2838,8 +2834,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
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) {
......@@ -3324,15 +3319,13 @@ public class Vala.CCodeGenerator : CodeGenerator {
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);
......@@ -3396,6 +3389,25 @@ public class Vala.CCodeGenerator : CodeGenerator {
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;
}
......
......@@ -75,8 +75,7 @@ public class Vala.CCodeGenerator {
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;
......@@ -88,7 +87,7 @@ public class Vala.CCodeGenerator {
// 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);
}
......@@ -510,8 +509,7 @@ public class Vala.CCodeGenerator {
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)));
......
......@@ -76,8 +76,7 @@ public class Vala.CCodeGenerator {
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));
......@@ -117,8 +116,7 @@ public class Vala.CCodeGenerator {
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);
......@@ -197,8 +195,7 @@ public class Vala.CCodeGenerator {
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
......@@ -75,15 +75,16 @@ public class Vala.DBusBindingProvider : Object, BindingProvider {
} 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
......@@ -34,4 +34,22 @@ public class Vala.ClassType : ReferenceType {
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;
}
}
......@@ -28,7 +28,7 @@ using Gee;
* 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.
*/
......@@ -77,9 +77,6 @@ public class Vala.DataType : CodeNode {
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.
......@@ -234,26 +231,8 @@ public class Vala.DataType : CodeNode {
*
* @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
......@@ -34,4 +34,22 @@ public class Vala.InterfaceType : ReferenceType {
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
......@@ -29,4 +29,8 @@ public class Vala.InvalidType : DataType {
public InvalidType () {
error = true;
}
public override DataType copy () {
return new InvalidType ();
}
}
......@@ -29,4 +29,18 @@ public class Vala.TypeParameterType : DataType {
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
......@@ -34,4 +34,22 @@ public class Vala.ValueType : DataType {
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;
}
}
......@@ -40,4 +40,8 @@ public class Vala.VoidType : DataType {
public override string get_cname (bool var_type = false, bool const_type = false) {
return "void";
}
public override DataType copy () {
return new VoidType ();
}
}
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