Fix array length handling for get_attributes method
[vala-lang.git] / vala / valapointerindirection.vala
blob84f1b6e6f81915fa0fc7b78022895684a0f8cab7
1 /* valapointerindirection.vala
3 * Copyright (C) 2007-2008 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 Gee;
25 /**
26 * Represents a pointer indirection in the source code, e.g. `*pointer'.
28 public class Vala.PointerIndirection : Expression {
29 /**
30 * The pointer to dereference.
32 public Expression inner {
33 get {
34 return _inner;
36 set {
37 _inner = value;
38 _inner.parent_node = this;
42 private Expression _inner;
44 /**
45 * Creates a new pointer indirection.
47 * @param inner pointer to be dereferenced
48 * @return newly created pointer indirection
50 public PointerIndirection (Expression inner, SourceReference? source_reference = null) {
51 this.source_reference = source_reference;
52 this.inner = inner;
55 public override void accept (CodeVisitor visitor) {
56 inner.accept (visitor);
58 visitor.visit_pointer_indirection (this);
60 visitor.visit_expression (this);
63 public override void replace_expression (Expression old_node, Expression new_node) {
64 if (inner == old_node) {
65 inner = new_node;
69 public override bool is_pure () {
70 return inner.is_pure ();
73 public override bool check (SemanticAnalyzer analyzer) {
74 if (checked) {
75 return !error;
78 checked = true;
80 if (!inner.check (analyzer)) {
81 return false;
83 if (inner.value_type == null) {
84 error = true;
85 Report.error (source_reference, "internal error: unknown type of inner expression");
86 return false;
88 if (inner.value_type is PointerType) {
89 var pointer_type = (PointerType) inner.value_type;
90 if (pointer_type.base_type is ReferenceType) {
91 error = true;
92 Report.error (source_reference, "Pointer indirection not supported for this expression");
93 return false;
95 value_type = pointer_type.base_type;
96 } else {
97 error = true;
98 Report.error (source_reference, "Pointer indirection not supported for this expression");
99 return false;
102 return !error;
105 public override void get_defined_variables (Collection<LocalVariable> collection) {
106 inner.get_defined_variables (collection);
109 public override void get_used_variables (Collection<LocalVariable> collection) {
110 inner.get_used_variables (collection);