1 /* valaccodebinaryexpression.vala
3 * Copyright (C) 2006-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
26 * Represents an expression with two operands in C code.
28 public class Vala
.CCodeBinaryExpression
: CCodeExpression
{
30 * The binary operator.
32 public CCodeBinaryOperator operator
{ get; set; }
37 public CCodeExpression left
{ get; set; }
42 public CCodeExpression right
{ get; set; }
44 public CCodeBinaryExpression (CCodeBinaryOperator op
, CCodeExpression l
, CCodeExpression r
) {
50 public override void write (CCodeWriter writer
) {
51 left
.write_inner (writer
);
54 case CCodeBinaryOperator
.PLUS
: writer
.write_string (" + "); break;
55 case CCodeBinaryOperator
.MINUS
: writer
.write_string (" - "); break;
56 case CCodeBinaryOperator
.MUL
: writer
.write_string (" * "); break;
57 case CCodeBinaryOperator
.DIV
: writer
.write_string (" / "); break;
58 case CCodeBinaryOperator
.MOD
: writer
.write_string (" % "); break;
59 case CCodeBinaryOperator
.SHIFT_LEFT
: writer
.write_string (" << "); break;
60 case CCodeBinaryOperator
.SHIFT_RIGHT
: writer
.write_string (" >> "); break;
61 case CCodeBinaryOperator
.LESS_THAN
: writer
.write_string (" < "); break;
62 case CCodeBinaryOperator
.GREATER_THAN
: writer
.write_string (" > "); break;
63 case CCodeBinaryOperator
.LESS_THAN_OR_EQUAL
: writer
.write_string (" <= "); break;
64 case CCodeBinaryOperator
.GREATER_THAN_OR_EQUAL
: writer
.write_string (" >= "); break;
65 case CCodeBinaryOperator
.EQUALITY
: writer
.write_string (" == "); break;
66 case CCodeBinaryOperator
.INEQUALITY
: writer
.write_string (" != "); break;
67 case CCodeBinaryOperator
.BITWISE_AND
: writer
.write_string (" & "); break;
68 case CCodeBinaryOperator
.BITWISE_OR
: writer
.write_string (" | "); break;
69 case CCodeBinaryOperator
.BITWISE_XOR
: writer
.write_string (" ^ "); break;
70 case CCodeBinaryOperator
.AND
: writer
.write_string (" && "); break;
71 case CCodeBinaryOperator
.OR
: writer
.write_string (" || "); break;
72 default: assert_not_reached ();
75 right
.write_inner (writer
);
78 public override void write_inner (CCodeWriter writer
) {
79 writer
.write_string ("(");
81 writer
.write_string (")");
85 public enum Vala
.CCodeBinaryOperator
{
96 GREATER_THAN_OR_EQUAL
,