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
20 * Jürg Billeter <j@bitron.ch>
26 * Represents an expression with one operand in the C code.
28 public class Vala
.CCodeUnaryExpression
: CCodeExpression
{
32 public CCodeUnaryOperator operator
{ get; set; }
37 public CCodeExpression inner
{ get; set; }
39 public CCodeUnaryExpression (CCodeUnaryOperator op
, CCodeExpression 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
);
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
);
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 ("(");
87 writer
.write_string (")");
91 public enum Vala
.CCodeUnaryOperator
{