1 /* valaaddressofexpression.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
20 * Jürg Billeter <j@bitron.ch>
26 * Represents an address-of expression in the source code, e.g. `&foo`.
28 public class Vala
.AddressofExpression
: Expression
{
30 * The variable whose address is to be computed.
32 public Expression inner
{
38 _inner
.parent_node
= this
;
42 private Expression _inner
;
45 * Creates a new address-of expression.
47 * @param inner variable whose address is to be computed
48 * @return newly created address-of expression
50 public AddressofExpression (Expression inner
, SourceReference? source_reference
= null) {
51 this
.source_reference
= source_reference
;
55 public override void accept (CodeVisitor visitor
) {
56 inner
.accept (visitor
);
58 visitor
.visit_addressof_expression (this
);
60 visitor
.visit_expression (this
);
63 public override void replace_expression (Expression old_node
, Expression new_node
) {
64 if (inner
== old_node
) {
69 public override bool is_pure () {
70 return inner
.is_pure ();
73 public override bool check (SemanticAnalyzer analyzer
) {
80 if (!inner
.check (analyzer
)) {
84 if (!(inner
.value_type is ValueType
85 || inner
.value_type is ObjectType
86 || inner
.value_type is PointerType
87 || inner
.value_type is GenericType
)) {
89 Report
.error (source_reference
, "Address-of operator not supported for this expression");
93 if (inner
.value_type
.is_reference_type_or_type_parameter ()) {
94 value_type
= new
PointerType (new
PointerType (inner
.value_type
));
96 value_type
= new
PointerType (inner
.value_type
);