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
20 * Jürg Billeter <j@bitron.ch>
25 * Represents a pointer indirection in the source code, e.g. `*pointer`.
27 public class Vala
.PointerIndirection
: Expression
{
29 * The pointer to dereference.
31 public Expression inner
{
37 _inner
.parent_node
= this
;
41 private Expression _inner
;
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
;
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
) {
68 public override bool is_pure () {
69 return inner
.is_pure ();
72 public override bool check (CodeContext context
) {
79 if (!inner
.check (context
)) {
82 if (inner
.value_type
== null) {
84 Report
.error (source_reference
, "internal error: unknown type of inner expression");
87 if (inner
.value_type is PointerType
) {
88 var pointer_type
= (PointerType
) inner
.value_type
;
89 if (pointer_type
.base_type is ReferenceType
) {
91 Report
.error (source_reference
, "Pointer indirection not supported for this expression");
94 value_type
= pointer_type
.base_type
;
97 Report
.error (source_reference
, "Pointer indirection not supported for this expression");
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
);