]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Don't require libgee for `in' operations
authorJürg Billeter <j@bitron.ch>
Fri, 28 Nov 2008 16:45:45 +0000 (16:45 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 28 Nov 2008 16:45:45 +0000 (16:45 +0000)
2008-11-28  Jürg Billeter  <j@bitron.ch>

* vala/valabinaryexpression.vala:
* gobject/valaccodebasemodule.vala:

Don't require libgee for `in' operations

svn path=/trunk/; revision=2072

ChangeLog
gobject/valaccodebasemodule.vala
vala/valabinaryexpression.vala

index 73af10016abf782d8b6c4388471a68680c2d0e3c..5a166099346cffbffe6cfb2a13fa45e3e38dc770 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-11-28  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valabinaryexpression.vala:
+       * gobject/valaccodebasemodule.vala:
+
+       Don't require libgee for `in' operations
+
 2008-11-28  Jürg Billeter  <j@bitron.ch>
 
        * vapi/glib-2.0.vapi:
index 3a26d3570c3ab0fc8e8a1263015074727658e9fc..0afac8282dc3a43fa92aee1a94c8a8449c010c01 100644 (file)
@@ -2737,28 +2737,6 @@ public class Vala.CCodeBaseModule : CCodeModule {
                } 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;
                } else {
index 1a10b74db56763ab6c97f7be490de30c98cefe0c..1ba915d54ff1a801efeb636f1b4b93242650a86b 100644 (file)
@@ -269,27 +269,32 @@ public class Vala.BinaryExpression : Expression {
 
                        value_type = analyzer.bool_type;
                } else if (operator == BinaryOperator.IN) {
-                       // integer type or flags type or collection/map
-
-                       /* handle collections and maps */
-                       var container_type = right.value_type.data_type;
-                       
-                       if ((analyzer.collection_type != null && container_type.is_subtype_of (analyzer.collection_type))
-                           || (analyzer.map_type != null && container_type.is_subtype_of (analyzer.map_type))) {
-                               Symbol contains_sym = null;
-                               if (container_type.is_subtype_of (analyzer.collection_type)) {
-                                       contains_sym = analyzer.collection_type.scope.lookup ("contains");
-                               } else if (container_type.is_subtype_of (analyzer.map_type)) {
-                                       contains_sym = analyzer.map_type.scope.lookup ("contains");
+                       if (left.value_type.compatible (analyzer.int_type)
+                           && right.value_type.compatible (analyzer.int_type)) {
+                               // integers or enums
+                       } else {
+                               // otherwise require a bool contains () method
+                               var contains_method = right.value_type.get_member ("contains") as Method;
+                               if (contains_method == null) {
+                                       Report.error (source_reference, "`%s' does not have a `contains' method".printf (right.value_type.to_string ()));
+                                       error = true;
+                                       return false;
+                               }
+                               if (contains_method.get_parameters ().size != 1) {
+                                       Report.error (source_reference, "`%s' must have one parameter".printf (contains_method.get_full_name ()));
+                                       error = true;
+                                       return false;
+                               }
+                               if (!contains_method.return_type.compatible (analyzer.bool_type)) {
+                                       Report.error (source_reference, "`%s' must return a boolean value".printf (contains_method.get_full_name ()));
+                                       error = true;
+                                       return false;
                                }
-                               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 = analyzer.get_actual_type (right.value_type, (GenericType) contains_param.parameter_type, this);
-                               left.target_type = key_type;
+
+                               var contains_call = new MethodCall (new MemberAccess (right, "contains"));
+                               contains_call.add_argument (left);
+                               parent_node.replace_expression (this, contains_call);
+                               return contains_call.check (analyzer);
                        }
                        
                        value_type = analyzer.bool_type;