gtk+-3.0: Drop sealed fields
[vala-lang.git] / ccode / valaccodeunaryexpression.vala
blob7f2b89b232316ad4eec66f6018ec0ca2f7724731
1 /* valaccodeunaryexpression.vala
3 * Copyright (C) 2006-2009 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 one operand in the C code.
28 public class Vala.CCodeUnaryExpression : CCodeExpression {
29 /**
30 * The unary operator.
32 public CCodeUnaryOperator operator { get; set; }
34 /**
35 * The operand.
37 public CCodeExpression inner { get; set; }
39 public CCodeUnaryExpression (CCodeUnaryOperator op, CCodeExpression expr) {
40 operator = op;
41 inner = expr;
44 public override void write (CCodeWriter writer) {
45 if (operator == CCodeUnaryOperator.PLUS) {
46 writer.write_string ("+");
47 } else if (operator == CCodeUnaryOperator.MINUS) {
48 writer.write_string ("-");
49 } else if (operator == CCodeUnaryOperator.LOGICAL_NEGATION) {
50 writer.write_string ("!");
51 } else if (operator == CCodeUnaryOperator.BITWISE_COMPLEMENT) {
52 writer.write_string ("~");
53 } else if (operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
54 var inner_unary = inner as CCodeUnaryExpression;
55 if (inner_unary != null && inner_unary.operator == CCodeUnaryOperator.ADDRESS_OF) {
56 // simplify expression
57 inner_unary.inner.write (writer);
58 return;
60 writer.write_string ("*");
61 } else if (operator == CCodeUnaryOperator.ADDRESS_OF) {
62 var inner_unary = inner as CCodeUnaryExpression;
63 if (inner_unary != null && inner_unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
64 // simplify expression
65 inner_unary.inner.write (writer);
66 return;
68 writer.write_string ("&");
69 } else if (operator == CCodeUnaryOperator.PREFIX_INCREMENT) {
70 writer.write_string ("++");
71 } else if (operator == CCodeUnaryOperator.PREFIX_DECREMENT) {
72 writer.write_string ("--");
75 inner.write_inner (writer);
77 if (operator == CCodeUnaryOperator.POSTFIX_INCREMENT) {
78 writer.write_string ("++");
79 } else if (operator == CCodeUnaryOperator.POSTFIX_DECREMENT) {
80 writer.write_string ("--");
84 public override void write_inner (CCodeWriter writer) {
85 writer.write_string ("(");
86 this.write (writer);
87 writer.write_string (")");
91 public enum Vala.CCodeUnaryOperator {
92 PLUS,
93 MINUS,
94 LOGICAL_NEGATION,
95 BITWISE_COMPLEMENT,
96 POINTER_INDIRECTION,
97 ADDRESS_OF,
98 PREFIX_INCREMENT,
99 PREFIX_DECREMENT,
100 POSTFIX_INCREMENT,
101 POSTFIX_DECREMENT