codegen: Fix array size variable on assignment
[vala-lang.git] / ccode / valaccodeassignment.vala
blob37b48f33c49858579cb08448fff903fbf5488453
1 /* valaccodeassignment.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 assignment expression in the C code.
28 public class Vala.CCodeAssignment : CCodeExpression {
29 /**
30 * Left hand side of the assignment.
32 public CCodeExpression left { get; set; }
34 /**
35 * Assignment operator.
37 public CCodeAssignmentOperator operator { get; set; }
39 /**
40 * Right hand side of the assignment.
42 public CCodeExpression right { get; set; }
44 public CCodeAssignment (CCodeExpression l, CCodeExpression r, CCodeAssignmentOperator op = CCodeAssignmentOperator.SIMPLE) {
45 left = l;
46 operator = op;
47 right = r;
50 public override void write (CCodeWriter writer) {
51 left.write (writer);
53 writer.write_string (" ");
55 if (operator == CCodeAssignmentOperator.BITWISE_OR) {
56 writer.write_string ("|");
57 } else if (operator == CCodeAssignmentOperator.BITWISE_AND) {
58 writer.write_string ("&");
59 } else if (operator == CCodeAssignmentOperator.BITWISE_XOR) {
60 writer.write_string ("^");
61 } else if (operator == CCodeAssignmentOperator.ADD) {
62 writer.write_string ("+");
63 } else if (operator == CCodeAssignmentOperator.SUB) {
64 writer.write_string ("-");
65 } else if (operator == CCodeAssignmentOperator.MUL) {
66 writer.write_string ("*");
67 } else if (operator == CCodeAssignmentOperator.DIV) {
68 writer.write_string ("/");
69 } else if (operator == CCodeAssignmentOperator.PERCENT) {
70 writer.write_string ("%");
71 } else if (operator == CCodeAssignmentOperator.SHIFT_LEFT) {
72 writer.write_string ("<<");
73 } else if (operator == CCodeAssignmentOperator.SHIFT_RIGHT) {
74 writer.write_string (">>");
77 writer.write_string ("= ");
79 right.write (writer);
82 public override void write_inner (CCodeWriter writer) {
83 writer.write_string ("(");
84 this.write (writer);
85 writer.write_string (")");
89 public enum Vala.CCodeAssignmentOperator {
90 SIMPLE,
91 BITWISE_OR,
92 BITWISE_AND,
93 BITWISE_XOR,
94 ADD,
95 SUB,
96 MUL,
97 DIV,
98 PERCENT,
99 SHIFT_LEFT,
100 SHIFT_RIGHT