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>
}
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;
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 &&
%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
}
;
-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
/* 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
BITWISE_OR,
BITWISE_XOR,
AND,
- OR
+ OR,
+ IN
}
}
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 ();
}