Line data Source code
1 : /* valaccodeassignment.vala
2 : *
3 : * Copyright (C) 2006-2008 Jürg Billeter
4 : *
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.
9 :
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.
14 :
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
18 : *
19 : * Author:
20 : * Jürg Billeter <j@bitron.ch>
21 : */
22 :
23 : using GLib;
24 :
25 : /**
26 : * Represents an assignment expression in the C code.
27 : */
28 82886 : public class Vala.CCodeAssignment : CCodeExpression {
29 : /**
30 : * Left hand side of the assignment.
31 : */
32 246213 : public CCodeExpression left { get; set; }
33 :
34 : /**
35 : * Assignment operator.
36 : */
37 82071 : public CCodeAssignmentOperator operator { get; set; }
38 :
39 : /**
40 : * Right hand side of the assignment.
41 : */
42 246213 : public CCodeExpression right { get; set; }
43 :
44 246213 : public CCodeAssignment (CCodeExpression l, CCodeExpression r, CCodeAssignmentOperator op = CCodeAssignmentOperator.SIMPLE) {
45 82071 : left = l;
46 82071 : operator = op;
47 82071 : right = r;
48 : }
49 :
50 80837 : public override void write (CCodeWriter writer) {
51 80837 : left.write (writer);
52 :
53 80837 : switch (operator) {
54 80760 : case CCodeAssignmentOperator.SIMPLE: writer.write_string (" = "); break;
55 3 : case CCodeAssignmentOperator.BITWISE_OR: writer.write_string (" |= "); break;
56 3 : case CCodeAssignmentOperator.BITWISE_AND: writer.write_string (" &= "); break;
57 3 : case CCodeAssignmentOperator.BITWISE_XOR: writer.write_string (" ^= "); break;
58 40 : case CCodeAssignmentOperator.ADD: writer.write_string (" += "); break;
59 9 : case CCodeAssignmentOperator.SUB: writer.write_string (" -= "); break;
60 5 : case CCodeAssignmentOperator.MUL: writer.write_string (" *= "); break;
61 5 : case CCodeAssignmentOperator.DIV: writer.write_string (" /= "); break;
62 3 : case CCodeAssignmentOperator.PERCENT: writer.write_string (" %= "); break;
63 3 : case CCodeAssignmentOperator.SHIFT_LEFT: writer.write_string (" <<= "); break;
64 3 : case CCodeAssignmentOperator.SHIFT_RIGHT: writer.write_string (" >>= "); break;
65 0 : default: assert_not_reached ();
66 : }
67 :
68 80837 : right.write (writer);
69 : }
70 :
71 1609 : public override void write_inner (CCodeWriter writer) {
72 1609 : writer.write_string ("(");
73 1609 : this.write (writer);
74 1609 : writer.write_string (")");
75 : }
76 : }
77 :
78 : public enum Vala.CCodeAssignmentOperator {
79 : SIMPLE,
80 : BITWISE_OR,
81 : BITWISE_AND,
82 : BITWISE_XOR,
83 : ADD,
84 : SUB,
85 : MUL,
86 : DIV,
87 : PERCENT,
88 : SHIFT_LEFT,
89 : SHIFT_RIGHT
90 : }
|