Commit 07c6c965 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

add support for `in' operator for enums, fixes bug 473820

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
parent 700beda2
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
......
......@@ -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 &&
......
......@@ -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
......
/* 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
}
......@@ -2361,6 +2361,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
Report.error (expr.source_reference, "Operands must be boolean");
}
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 ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment