vala r1645 - in trunk: . gobject vala



Author: juergbi
Date: Wed Jun 25 14:26:21 2008
New Revision: 1645
URL: http://svn.gnome.org/viewvc/vala?rev=1645&view=rev

Log:
2008-06-25  JÃrg Billeter  <j bitron ch>

	* vala/valasemanticanalyzer.vala:
	* gobject/valaccodegenerator.vala:

	Support `in' operator for Gee.Collection and Gee.Map,
	patch by Jamie McCracken


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodegenerator.vala
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Wed Jun 25 14:26:21 2008
@@ -3402,6 +3402,28 @@
 		} else if (expr.operator == BinaryOperator.OR) {
 			op = CCodeBinaryOperator.OR;
 		} else if (expr.operator == BinaryOperator.IN) {
+			var container_type = expr.right.value_type.data_type;
+			if (container_type != null && collection_type != null && map_type != null &&
+		           (container_type.is_subtype_of (collection_type) || container_type.is_subtype_of (map_type))) {
+				Method contains_method;
+				if (container_type.is_subtype_of (collection_type)) {
+					contains_method = (Method) collection_type.scope.lookup ("contains");
+					assert (contains_method != null);
+					var contains_ccall = new CCodeFunctionCall (new CCodeIdentifier (contains_method.get_cname ()));
+					contains_ccall.add_argument (new InstanceCast (cright, collection_type));
+					contains_ccall.add_argument (cleft);
+					expr.ccodenode = contains_ccall;
+				} else {
+					contains_method = (Method) map_type.scope.lookup ("contains");
+					assert (contains_method != null);
+					var contains_ccall = new CCodeFunctionCall (new CCodeIdentifier (contains_method.get_cname ()));
+					contains_ccall.add_argument (new InstanceCast (cright, map_type));
+					contains_ccall.add_argument (cleft);
+					expr.ccodenode = contains_ccall;
+				}
+				return;
+			}
+		
 			expr.ccodenode = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.BITWISE_AND, new CCodeParenthesizedExpression (cright), new CCodeParenthesizedExpression (cleft))), new CCodeParenthesizedExpression (cleft));
 			return;
 		}

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Wed Jun 25 14:26:21 2008
@@ -62,6 +62,7 @@
 	DataType iterable_type;
 	Interface iterator_type;
 	Interface list_type;
+	Interface collection_type;
 	Interface map_type;
 
 	private int next_lambda_id = 0;
@@ -118,6 +119,7 @@
 			iterable_type = new ObjectType ((Interface) gee_ns.scope.lookup ("Iterable"));
 			iterator_type = (Interface) gee_ns.scope.lookup ("Iterator");
 			list_type = (Interface) gee_ns.scope.lookup ("List");
+			collection_type = (Interface) gee_ns.scope.lookup ("Collection");
 			map_type = (Interface) gee_ns.scope.lookup ("Map");
 		}
 
@@ -3225,9 +3227,31 @@
 
 			expr.value_type = bool_type;
 		} else if (expr.operator == BinaryOperator.IN) {
-			// integer type or flags type
+			// integer type or flags type or collection/map
+
+			/* handle collections and maps */
+			var container_type = expr.right.value_type.data_type;
+			
+			if ((collection_type != null && container_type.is_subtype_of (collection_type))
+			    || (map_type != null && container_type.is_subtype_of (map_type))) {
+				Symbol contains_sym = null;
+				if (container_type.is_subtype_of (collection_type)) {
+					contains_sym = collection_type.scope.lookup ("contains");
+				} else if (container_type.is_subtype_of (map_type)) {
+					contains_sym = map_type.scope.lookup ("contains");
+				}
+				var contains_method = (Method) contains_sym;
+				Gee.List<FormalParameter> contains_params = contains_method.get_parameters ();
+				Iterator<FormalParameter> contains_params_it = contains_params.iterator ();
+				contains_params_it.next ();
+				var contains_param = contains_params_it.get ();
 
+				var key_type = get_actual_type (expr.right.value_type, contains_method, contains_param.parameter_type, expr);
+				expr.left.target_type = key_type;
+			}
+			
 			expr.value_type = bool_type;
+			
 		} else {
 			assert_not_reached ();
 		}



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