vala r1104 - in trunk: . gobject vala



Author: juergbi
Date: Tue Mar  4 23:23:30 2008
New Revision: 1104
URL: http://svn.gnome.org/viewvc/vala?rev=1104&view=rev

Log:
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


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodegenerator.vala
   trunk/gobject/valaccodegeneratorinvocationexpression.vala
   trunk/gobject/valaccodegeneratormemberaccess.vala
   trunk/gobject/valadbusbindingprovider.vala
   trunk/vala/valaclasstype.vala
   trunk/vala/valadatatype.vala
   trunk/vala/valainterfacetype.vala
   trunk/vala/valainvalidtype.vala
   trunk/vala/valatypeparametertype.vala
   trunk/vala/valavaluetype.vala
   trunk/vala/valavoidtype.vala

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Tue Mar  4 23:23:30 2008
@@ -2336,10 +2336,8 @@
 
 					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 @@
 				}
 
 				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 @@
 			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 @@
 		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 @@
 		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;
 	}

Modified: trunk/gobject/valaccodegeneratorinvocationexpression.vala
==============================================================================
--- trunk/gobject/valaccodegeneratorinvocationexpression.vala	(original)
+++ trunk/gobject/valaccodegeneratorinvocationexpression.vala	Tue Mar  4 23:23:30 2008
@@ -75,8 +75,7 @@
 			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 @@
 
 			// 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 @@
 
 				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)));

Modified: trunk/gobject/valaccodegeneratormemberaccess.vala
==============================================================================
--- trunk/gobject/valaccodegeneratormemberaccess.vala	(original)
+++ trunk/gobject/valaccodegeneratormemberaccess.vala	Tue Mar  4 23:23:30 2008
@@ -76,8 +76,7 @@
 			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 @@
 				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 @@
 			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);

Modified: trunk/gobject/valadbusbindingprovider.vala
==============================================================================
--- trunk/gobject/valadbusbindingprovider.vala	(original)
+++ trunk/gobject/valadbusbindingprovider.vala	Tue Mar  4 23:23:30 2008
@@ -1,6 +1,6 @@
 /* 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 @@
 		} 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;

Modified: trunk/vala/valaclasstype.vala
==============================================================================
--- trunk/vala/valaclasstype.vala	(original)
+++ trunk/vala/valaclasstype.vala	Tue Mar  4 23:23:30 2008
@@ -1,6 +1,6 @@
 /* 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 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;
+	}
 }

Modified: trunk/vala/valadatatype.vala
==============================================================================
--- trunk/vala/valadatatype.vala	(original)
+++ trunk/vala/valadatatype.vala	Tue Mar  4 23:23:30 2008
@@ -28,7 +28,7 @@
  * 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 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 @@
 	 *
 	 * @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.

Modified: trunk/vala/valainterfacetype.vala
==============================================================================
--- trunk/vala/valainterfacetype.vala	(original)
+++ trunk/vala/valainterfacetype.vala	Tue Mar  4 23:23:30 2008
@@ -1,6 +1,6 @@
 /* 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 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;
+	}
 }

Modified: trunk/vala/valainvalidtype.vala
==============================================================================
--- trunk/vala/valainvalidtype.vala	(original)
+++ trunk/vala/valainvalidtype.vala	Tue Mar  4 23:23:30 2008
@@ -1,6 +1,6 @@
 /* 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 InvalidType () {
 		error = true;
 	}
+
+	public override DataType copy () {
+		return new InvalidType ();
+	}
 }

Modified: trunk/vala/valatypeparametertype.vala
==============================================================================
--- trunk/vala/valatypeparametertype.vala	(original)
+++ trunk/vala/valatypeparametertype.vala	Tue Mar  4 23:23:30 2008
@@ -29,4 +29,18 @@
 	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;
+	}
 }

Modified: trunk/vala/valavaluetype.vala
==============================================================================
--- trunk/vala/valavaluetype.vala	(original)
+++ trunk/vala/valavaluetype.vala	Tue Mar  4 23:23:30 2008
@@ -1,6 +1,6 @@
 /* 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 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;
+	}
 }

Modified: trunk/vala/valavoidtype.vala
==============================================================================
--- trunk/vala/valavoidtype.vala	(original)
+++ trunk/vala/valavoidtype.vala	Tue Mar  4 23:23:30 2008
@@ -40,4 +40,8 @@
 	public override string get_cname (bool var_type = false, bool const_type = false) {
 		return "void";
 	}
+
+	public override DataType copy () {
+		return new VoidType ();
+	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]