glib-2.0: Support owned delegates with Idle.add
[vala-lang.git] / ccode / valaccodebinaryexpression.vala
blob047b55c41d50308bfff6aff840e3edb0769cee88
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_inner (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_inner (writer);
97 public override void write_inner (CCodeWriter writer) {
98 writer.write_string ("(");
99 this.write (writer);
100 writer.write_string (")");
104 public enum Vala.CCodeBinaryOperator {
105 PLUS,
106 MINUS,
107 MUL,
108 DIV,
109 MOD,
110 SHIFT_LEFT,
111 SHIFT_RIGHT,
112 LESS_THAN,
113 GREATER_THAN,
114 LESS_THAN_OR_EQUAL,
115 GREATER_THAN_OR_EQUAL,
116 EQUALITY,
117 INEQUALITY,
118 BITWISE_AND,
119 BITWISE_OR,
120 BITWISE_XOR,
121 AND,