libgda-4.0, gedit-2.20: Fix gedit typo and GdaXaTransactionId.data
[vala-lang.git] / vala / valapointerindirection.vala
blob424958bd86141dbf32d68522c7619533cbb026f4
1 /* valapointerindirection.vala
3 * Copyright (C) 2007-2010 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>
24 /**
25 * Represents a pointer indirection in the source code, e.g. `*pointer`.
27 public class Vala.PointerIndirection : Expression {
28 /**
29 * The pointer to dereference.
31 public Expression inner {
32 get {
33 return _inner;
35 set {
36 _inner = value;
37 _inner.parent_node = this;
41 private Expression _inner;
43 /**
44 * Creates a new pointer indirection.
46 * @param inner pointer to be dereferenced
47 * @return newly created pointer indirection
49 public PointerIndirection (Expression inner, SourceReference? source_reference = null) {
50 this.source_reference = source_reference;
51 this.inner = inner;
54 public override void accept (CodeVisitor visitor) {
55 inner.accept (visitor);
57 visitor.visit_pointer_indirection (this);
59 visitor.visit_expression (this);
62 public override void replace_expression (Expression old_node, Expression new_node) {
63 if (inner == old_node) {
64 inner = new_node;
68 public override bool is_pure () {
69 return inner.is_pure ();
72 public override bool check (CodeContext context) {
73 if (checked) {
74 return !error;
77 checked = true;
79 if (!inner.check (context)) {
80 return false;
82 if (inner.value_type == null) {
83 error = true;
84 Report.error (source_reference, "internal error: unknown type of inner expression");
85 return false;
87 if (inner.value_type is PointerType) {
88 var pointer_type = (PointerType) inner.value_type;
89 if (pointer_type.base_type is ReferenceType) {
90 error = true;
91 Report.error (source_reference, "Pointer indirection not supported for this expression");
92 return false;
94 value_type = pointer_type.base_type;
95 } else {
96 error = true;
97 Report.error (source_reference, "Pointer indirection not supported for this expression");
98 return false;
101 return !error;
104 public override void emit (CodeGenerator codegen) {
105 inner.emit (codegen);
107 codegen.visit_pointer_indirection (this);
109 codegen.visit_expression (this);
112 public override void get_defined_variables (Collection<LocalVariable> collection) {
113 inner.get_defined_variables (collection);
116 public override void get_used_variables (Collection<LocalVariable> collection) {
117 inner.get_used_variables (collection);