update for 0.4.0 release
[vala-lang.git] / ccode / valaccodebinaryexpression.vala
blobaaeefb3f77f9e0fe59464cc29e308c0b2c97e4b0
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents an expression with two operands in C code.
28 public class Vala.CCodeBinaryExpression : CCodeExpression {
29 /**
30 * The binary operator.
32 public CCodeBinaryOperator operator { get; set; }
34 /**
35 * The left operand.
37 public CCodeExpression left { get; set; }
39 /**
40 * The right operand.
42 public CCodeExpression right { get; set; }
44 public CCodeBinaryExpression (CCodeBinaryOperator op, CCodeExpression l, CCodeExpression r) {
45 operator = op;
46 left = l;
47 right = r;
50 public override void write (CCodeWriter writer) {
51 left.write (writer);
53 writer.write_string (" ");
54 if (operator == CCodeBinaryOperator.PLUS) {
55 writer.write_string ("+");
56 } else if (operator == CCodeBinaryOperator.MINUS) {
57 writer.write_string ("-");
58 } else if (operator == CCodeBinaryOperator.MUL) {
59 writer.write_string ("*");
60 } else if (operator == CCodeBinaryOperator.DIV) {
61 writer.write_string ("/");
62 } else if (operator == CCodeBinaryOperator.MOD) {
63 writer.write_string ("%");
64 } else if (operator == CCodeBinaryOperator.SHIFT_LEFT) {
65 writer.write_string ("<<");
66 } else if (operator == CCodeBinaryOperator.SHIFT_RIGHT) {
67 writer.write_string (">>");
68 } else if (operator == CCodeBinaryOperator.LESS_THAN) {
69 writer.write_string ("<");
70 } else if (operator == CCodeBinaryOperator.GREATER_THAN) {
71 writer.write_string (">");
72 } else if (operator == CCodeBinaryOperator.LESS_THAN_OR_EQUAL) {
73 writer.write_string ("<=");
74 } else if (operator == CCodeBinaryOperator.GREATER_THAN_OR_EQUAL) {
75 writer.write_string (">=");
76 } else if (operator == CCodeBinaryOperator.EQUALITY) {
77 writer.write_string ("==");
78 } else if (operator == CCodeBinaryOperator.INEQUALITY) {
79 writer.write_string ("!=");
80 } else if (operator == CCodeBinaryOperator.BITWISE_AND) {
81 writer.write_string ("&");
82 } else if (operator == CCodeBinaryOperator.BITWISE_OR) {
83 writer.write_string ("|");
84 } else if (operator == CCodeBinaryOperator.BITWISE_XOR) {
85 writer.write_string ("^");
86 } else if (operator == CCodeBinaryOperator.AND) {
87 writer.write_string ("&&");
88 } else if (operator == CCodeBinaryOperator.OR) {
89 writer.write_string ("||");
92 writer.write_string (" ");
94 right.write (writer);
98 public enum Vala.CCodeBinaryOperator {
99 PLUS,
100 MINUS,
101 MUL,
102 DIV,
103 MOD,
104 SHIFT_LEFT,
105 SHIFT_RIGHT,
106 LESS_THAN,
107 GREATER_THAN,
108 LESS_THAN_OR_EQUAL,
109 GREATER_THAN_OR_EQUAL,
110 EQUALITY,
111 INEQUALITY,
112 BITWISE_AND,
113 BITWISE_OR,
114 BITWISE_XOR,
115 AND,