add support for `in' operator for enums, fixes bug 473820
authorJuerg Billeter <j@bitron.ch>
Sun, 28 Oct 2007 20:49:32 +0000 (20:49 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 28 Oct 2007 20:49:32 +0000 (20:49 +0000)
2007-10-28  Juerg Billeter  <j@bitron.ch>

* vala/parser.y, vala/valabinaryexpression.vala,
  vala/valasemanticanalyzer.vala, gobject/valaccodegenerator.vala:
  add support for `in' operator for enums, fixes bug 473820

svn path=/trunk/; revision=672

ChangeLog
gobject/valaccodegenerator.vala
vala/parser.y
vala/valabinaryexpression.vala
vala/valasemanticanalyzer.vala

index 7c66943..e8752e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2007-10-28  Jürg Billeter  <j@bitron.ch>
 
+       * vala/parser.y, vala/valabinaryexpression.vala,
+         vala/valasemanticanalyzer.vala, gobject/valaccodegenerator.vala:
+         add support for `in' operator for enums, fixes bug 473820
+
+2007-10-28  Jürg Billeter  <j@bitron.ch>
+
        * vala/valaenum.vala: add get_values method
 
 2007-10-27  Jürg Billeter  <j@bitron.ch>
index 953c98d..147086b 100644 (file)
@@ -2579,6 +2579,9 @@ public class Vala.CCodeGenerator : CodeGenerator {
        }
 
        public override void visit_binary_expression (BinaryExpression! expr) {
+               var cleft = (CCodeExpression) expr.left.ccodenode;
+               var cright = (CCodeExpression) expr.right.ccodenode;
+               
                CCodeBinaryOperator op;
                if (expr.operator == BinaryOperator.PLUS) {
                        op = CCodeBinaryOperator.PLUS;
@@ -2616,11 +2619,13 @@ public class Vala.CCodeGenerator : CodeGenerator {
                        op = CCodeBinaryOperator.AND;
                } else if (expr.operator == BinaryOperator.OR) {
                        op = CCodeBinaryOperator.OR;
+               } else if (expr.operator == BinaryOperator.IN) {
+                       expr.ccodenode = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.BITWISE_AND, new CCodeParenthesizedExpression (cright), new CCodeParenthesizedExpression (cleft))), new CCodeParenthesizedExpression (cleft));
+
+                       visit_expression (expr);
+                       return;
                }
                
-               var cleft = (CCodeExpression) expr.left.ccodenode;
-               var cright = (CCodeExpression) expr.right.ccodenode;
-               
                if (expr.operator == BinaryOperator.EQUALITY ||
                    expr.operator == BinaryOperator.INEQUALITY) {
                        if (expr.left.static_type != null && expr.right.static_type != null &&
index 82e93de..6003b4f 100644 (file)
@@ -261,6 +261,7 @@ static gboolean check_is_struct (ValaSymbol *symbol, ValaSourceReference *src);
 %type <expression> and_expression
 %type <expression> exclusive_or_expression
 %type <expression> inclusive_or_expression
+%type <expression> in_expression
 %type <expression> conditional_and_expression
 %type <expression> conditional_or_expression
 %type <expression> conditional_expression
@@ -1387,9 +1388,27 @@ inclusive_or_expression
          }
        ;
 
-conditional_and_expression
+in_expression
        : inclusive_or_expression
-       | conditional_and_expression OP_AND inclusive_or_expression
+       | in_expression IN inclusive_or_expression
+         {
+               if ($1 == NULL || $3 == NULL) {
+                       // error in subexpression
+                       $$ = NULL;
+               } else {
+                       ValaSourceReference *src = src(@2);
+                       $$ = VALA_EXPRESSION (vala_code_context_create_binary_expression (context, VALA_BINARY_OPERATOR_IN, $1, $3, src));
+                       g_object_unref (src);
+                       g_object_unref ($1);
+                       g_object_unref ($3);
+               }
+         }
+       ;
+
+
+conditional_and_expression
+       : in_expression
+       | conditional_and_expression OP_AND in_expression
          {
                if ($1 == NULL || $3 == NULL) {
                        // error in subexpression
index 928c696..8351725 100644 (file)
@@ -1,6 +1,6 @@
 /* valabinaryexpression.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  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
@@ -113,5 +113,6 @@ public enum Vala.BinaryOperator {
        BITWISE_OR,
        BITWISE_XOR,
        AND,
-       OR
+       OR,
+       IN
 }
index 5fbf18c..bd32a90 100644 (file)
@@ -2362,6 +2362,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        }
 
                        expr.static_type = bool_type;
+               } else if (expr.operator == BinaryOperator.IN) {
+                       // integer type or flags type
+
+                       expr.static_type = bool_type;
                } else {
                        assert_not_reached ();
                }