vala r2366 - in trunk: . gobject vala



Author: juergbi
Date: Fri Jan 16 21:49:06 2009
New Revision: 2366
URL: http://svn.gnome.org/viewvc/vala?rev=2366&view=rev

Log:
2009-01-16  JÃrg Billeter  <j bitron ch>

	* vala/valaassignment.vala:
	* vala/valaelementaccess.vala:
	* vala/valasemanticanalyzer.vala:
	* gobject/valaccodearraymodule.vala:
	* gobject/valaccodeassignmentmodule.vala:
	* gobject/valaccodebasemodule.vala:

	Do not require libgee to support element access in custom types


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodearraymodule.vala
   trunk/gobject/valaccodeassignmentmodule.vala
   trunk/gobject/valaccodebasemodule.vala
   trunk/vala/valaassignment.vala
   trunk/vala/valaelementaccess.vala
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/gobject/valaccodearraymodule.vala
==============================================================================
--- trunk/gobject/valaccodearraymodule.vala	(original)
+++ trunk/gobject/valaccodearraymodule.vala	Fri Jan 16 21:49:06 2009
@@ -338,32 +338,6 @@
 			ccall.add_argument (coffsetcall);
 
 			expr.ccodenode = ccall;
-		} else if (container_type != null && list_type != null && map_type != null &&
-		           (container_type.is_subtype_of (list_type) || container_type.is_subtype_of (map_type))) {
-			// should be moved to a different module
-
-			TypeSymbol collection_iface = null;
-			if (container_type.is_subtype_of (list_type)) {
-				collection_iface = list_type;
-			} else if (container_type.is_subtype_of (map_type)) {
-				collection_iface = map_type;
-			}
-			var get_method = (Method) collection_iface.scope.lookup ("get");
-			Gee.List<FormalParameter> get_params = get_method.get_parameters ();
-			Iterator<FormalParameter> get_params_it = get_params.iterator ();
-			get_params_it.next ();
-			var get_param = get_params_it.get ();
-
-			if (get_param.parameter_type is GenericType) {
-				var index_type = SemanticAnalyzer.get_actual_type (expr.container.value_type, (GenericType) get_param.parameter_type, expr);
-				cindex = convert_to_generic_pointer (cindex, index_type);
-			}
-
-			var get_ccall = new CCodeFunctionCall (new CCodeIdentifier (get_method.get_cname ()));
-			get_ccall.add_argument (new CCodeCastExpression (ccontainer, collection_iface.get_cname () + "*"));
-			get_ccall.add_argument (cindex);
-
-			expr.ccodenode = convert_from_generic_pointer (get_ccall, expr.value_type);
 		} else {
 			// access to element in an array
 			for (int i = 1; i < rank; i++) {

Modified: trunk/gobject/valaccodeassignmentmodule.vala
==============================================================================
--- trunk/gobject/valaccodeassignmentmodule.vala	(original)
+++ trunk/gobject/valaccodeassignmentmodule.vala	Fri Jan 16 21:49:06 2009
@@ -92,52 +92,6 @@
 		}
 	}
 
-	private CCodeExpression? emit_non_array_element_access (Assignment assignment) {
-		// custom element access
-		CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
-
-		var expr = (ElementAccess) assignment.left;
-		var container_type = expr.container.value_type.data_type;
-		Gee.List<Expression> indices = expr.get_indices ();
-		Iterator<Expression> indices_it = indices.iterator ();
-		indices_it.next ();
-
-		var ccontainer = (CCodeExpression) get_ccodenode (expr.container);
-		var cindex = (CCodeExpression) get_ccodenode (indices_it.get ());
-
-		if (container_type != null && list_type != null && map_type != null &&
-		    (container_type.is_subtype_of (list_type) || container_type.is_subtype_of (map_type))) {
-			// lookup symbol in interface instead of class as implemented interface methods are not in VAPI files
-			TypeSymbol collection_iface = null;
-			if (container_type.is_subtype_of (list_type)) {
-				collection_iface = list_type;
-			} else if (container_type.is_subtype_of (map_type)) {
-				collection_iface = map_type;
-			}
-			var set_method = (Method) collection_iface.scope.lookup ("set");
-			Gee.List<FormalParameter> set_params = set_method.get_parameters ();
-			Iterator<FormalParameter> set_params_it = set_params.iterator ();
-			set_params_it.next ();
-			var set_param = set_params_it.get ();
-
-			if (set_param.parameter_type is GenericType) {
-				var index_type = SemanticAnalyzer.get_actual_type (expr.container.value_type, (GenericType) set_param.parameter_type, assignment);
-				cindex = convert_to_generic_pointer (cindex, index_type);
-			}
-
-			var set_ccall = new CCodeFunctionCall (new CCodeIdentifier (set_method.get_cname ()));
-			set_ccall.add_argument (new CCodeCastExpression (ccontainer, collection_iface.get_cname () + "*"));
-			set_ccall.add_argument (cindex);
-			set_ccall.add_argument (convert_to_generic_pointer (rhs, expr.value_type));
-
-			return set_ccall;
-		} else {
-			Report.error (assignment.source_reference, "internal error: unsupported element access");
-			assignment.error = true;
-			return null;
-		}
-	}
-
 	CCodeExpression emit_simple_assignment (Assignment assignment) {
 		CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
 
@@ -246,10 +200,6 @@
 
 		if (assignment.left.symbol_reference is Property) {
 			assignment.ccodenode = emit_property_assignment (assignment);
-		} else if (assignment.left is ElementAccess
-		           && !(((ElementAccess) assignment.left).container.value_type is ArrayType)
-		           && !(((ElementAccess) assignment.left).container.value_type is PointerType)) {
-			assignment.ccodenode = emit_non_array_element_access (assignment);
 		} else {
 			assignment.ccodenode = emit_simple_assignment (assignment);
 		}

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Fri Jan 16 21:49:06 2009
@@ -127,8 +127,6 @@
 	public Struct gvalue_type;
 	public Struct mutex_type;
 	public TypeSymbol type_module_type;
-	public Interface list_type;
-	public Interface map_type;
 	public TypeSymbol dbus_object_type;
 
 	public bool in_plugin = false;
@@ -613,12 +611,6 @@
 			}
 		}
 
-		var gee_ns = root_symbol.scope.lookup ("Gee");
-		if (gee_ns != null) {
-			list_type = (Interface) gee_ns.scope.lookup ("List");
-			map_type = (Interface) gee_ns.scope.lookup ("Map");
-		}
-
 		var dbus_ns = root_symbol.scope.lookup ("DBus");
 		if (dbus_ns != null) {
 			dbus_object_type = (TypeSymbol) dbus_ns.scope.lookup ("Object");

Modified: trunk/vala/valaassignment.vala
==============================================================================
--- trunk/vala/valaassignment.vala	(original)
+++ trunk/vala/valaassignment.vala	Fri Jan 16 21:49:06 2009
@@ -1,6 +1,6 @@
 /* valaassignment.vala
  *
- * Copyright (C) 2006-2008  JÃrg Billeter
+ * Copyright (C) 2006-2009  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
@@ -148,6 +148,14 @@
 				var ma = (MemberAccess) ea.container;
 				var sig = (Signal) ea.container.symbol_reference;
 				right.target_type = new DelegateType (sig.get_delegate (ma.inner.value_type, this));
+			} else if (ea.container.value_type.get_member ("set") is Method) {
+				var set_call = new MethodCall (new MemberAccess (ea.container, "set"));
+				foreach (Expression e in ea.get_indices ()) {
+					set_call.add_argument (e);
+				}
+				set_call.add_argument (right);
+				parent_node.replace_expression (this, set_call);
+				return set_call.check (analyzer);
 			} else {
 				right.target_type = left.value_type;
 			}

Modified: trunk/vala/valaelementaccess.vala
==============================================================================
--- trunk/vala/valaelementaccess.vala	(original)
+++ trunk/vala/valaelementaccess.vala	Fri Jan 16 21:49:06 2009
@@ -1,6 +1,7 @@
 /* valaelementaccess.vala
  *
- * Copyright (C) 2006-2008  Raffaele Sandrini, JÃrg Billeter
+ * Copyright (C) 2006-2009  JÃrg Billeter
+ * Copyright (C) 2006-2008  Raffaele Sandrini
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -148,56 +149,33 @@
 			}
 
 			value_type = analyzer.unichar_type;
-		} else if (container_type != null && analyzer.list_type != null && analyzer.map_type != null &&
-		           (container_type.is_subtype_of (analyzer.list_type) || container_type.is_subtype_of (analyzer.map_type))) {
-			Gee.List<Expression> indices = get_indices ();
-			if (indices.size != 1) {
-				error = true;
-				Report.error (source_reference, "Element access with more than one dimension is not supported for the specified type");
-				return false;
-			}
-			Iterator<Expression> indices_it = indices.iterator ();
-			indices_it.next ();
-			var index = indices_it.get ();
-			index_int_type_check = false;
-
-			// lookup symbol in interface instead of class as implemented interface methods are not in VAPI files
-			Symbol get_sym = null;
-			if (container_type.is_subtype_of (analyzer.list_type)) {
-				get_sym = analyzer.list_type.scope.lookup ("get");
-			} else if (container_type.is_subtype_of (analyzer.map_type)) {
-				get_sym = analyzer.map_type.scope.lookup ("get");
-			}
-			var get_method = (Method) get_sym;
-			Gee.List<FormalParameter> get_params = get_method.get_parameters ();
-			Iterator<FormalParameter> get_params_it = get_params.iterator ();
-			get_params_it.next ();
-			var get_param = get_params_it.get ();
-
-			var index_type = get_param.parameter_type;
-			if (index_type is GenericType) {
-				index_type = analyzer.get_actual_type (container.value_type, (GenericType) index_type, this);
-			}
-
-			if (!index.value_type.compatible (index_type)) {
-				error = true;
-				Report.error (source_reference, "index expression: Cannot convert from `%s' to `%s'".printf (index.value_type.to_string (), index_type.to_string ()));
-				return false;
-			}
-
-			value_type = analyzer.get_actual_type (container.value_type, (GenericType) get_method.return_type, this).copy ();
-			if (lvalue) {
-				// get () returns owned value, set () accepts unowned value
-				value_type.value_owned = false;
-			}
 		} else if (container is MemberAccess && container.symbol_reference is Signal) {
 			index_int_type_check = false;
 
 			symbol_reference = container.symbol_reference;
 			value_type = container.value_type;
 		} else {
+			if (lvalue) {
+				var set_method = container.value_type.get_member ("set") as Method;
+				var assignment = parent_node as Assignment;
+				if (set_method != null && assignment != null) {
+					return !error;
+				}
+			} else {
+				var get_method = container.value_type.get_member ("get") as Method;
+				if (get_method != null) {
+					var get_call = new MethodCall (new MemberAccess (container, "get"));
+					foreach (Expression e in get_indices ()) {
+						get_call.add_argument (e);
+					}
+					get_call.target_type = this.target_type;
+					parent_node.replace_expression (this, get_call);
+					return get_call.check (analyzer);
+				}
+			}
+
 			error = true;
-			Report.error (source_reference, "The expression `%s' does not denote an Array".printf (container.value_type.to_string ()));
+			Report.error (source_reference, "The expression `%s' does not denote an array".printf (container.value_type.to_string ()));
 		}
 
 		if (index_int_type_check) {

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Fri Jan 16 21:49:06 2009
@@ -62,8 +62,6 @@
 	public DataType gslist_type;
 	public DataType garray_type;
 	public Class gerror_type;
-	public Interface list_type;
-	public Interface map_type;
 
 	public int next_lambda_id = 0;
 
@@ -116,12 +114,6 @@
 			gerror_type = (Class) glib_ns.scope.lookup ("Error");
 		}
 
-		var gee_ns = root_symbol.scope.lookup ("Gee");
-		if (gee_ns != null) {
-			list_type = (Interface) gee_ns.scope.lookup ("List");
-			map_type = (Interface) gee_ns.scope.lookup ("Map");
-		}
-
 		current_symbol = root_symbol;
 		context.root.check (this);
 		context.accept (this);



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