1 /* valaccodeunaryexpression.vala
3 * Copyright (C) 2006 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 writer
.write_string ("*");
55 } else if (operator
== CCodeUnaryOperator
.ADDRESS_OF
) {
56 writer
.write_string ("&");
57 } else if (operator
== CCodeUnaryOperator
.PREFIX_INCREMENT
) {
58 writer
.write_string ("++");
59 } else if (operator
== CCodeUnaryOperator
.PREFIX_DECREMENT
) {
60 writer
.write_string ("--");
63 inner
.write_inner (writer
);
65 if (operator
== CCodeUnaryOperator
.POSTFIX_INCREMENT
) {
66 writer
.write_string ("++");
67 } else if (operator
== CCodeUnaryOperator
.POSTFIX_DECREMENT
) {
68 writer
.write_string ("--");
72 public override void write_inner (CCodeWriter writer
) {
73 writer
.write_string ("(");
75 writer
.write_string (")");
79 public enum Vala
.CCodeUnaryOperator
{