glib-2.0: Add float.parse/try_parse()
[vala-gnome.git] / vala / valapointerindirection.vala
blob97f6473a80e42456c32c8e186000650742d9a613
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 is_accessible (Symbol sym) {
73 return inner.is_accessible (sym);
76 public override bool check (CodeContext context) {
77 if (checked) {
78 return !error;
81 checked = true;
83 if (!inner.check (context)) {
84 return false;
86 if (inner.value_type == null) {
87 error = true;
88 Report.error (source_reference, "internal error: unknown type of inner expression");
89 return false;
91 if (inner.value_type is PointerType) {
92 var pointer_type = (PointerType) inner.value_type;
93 if (pointer_type.base_type is ReferenceType || pointer_type.base_type is VoidType) {
94 error = true;
95 Report.error (source_reference, "Pointer indirection not supported for this expression");
96 return false;
98 value_type = pointer_type.base_type;
99 } else {
100 error = true;
101 Report.error (source_reference, "Pointer indirection not supported for this expression");
102 return false;
105 return !error;
108 public override void emit (CodeGenerator codegen) {
109 inner.emit (codegen);
111 codegen.visit_pointer_indirection (this);
113 codegen.visit_expression (this);
116 public override void get_defined_variables (Collection<Variable> collection) {
117 inner.get_defined_variables (collection);
120 public override void get_used_variables (Collection<Variable> collection) {
121 inner.get_used_variables (collection);