Support constructor chain up to GObject using Object (...)
[vala-lang.git] / vala / valaaddressofexpression.vala
blob2859a2c3941bdf0005e8f43f65bfeb174b7c48ad
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents an address-of expression in the source code, e.g. `&foo'.
28 public class Vala.AddressofExpression : Expression {
29 /**
30 * The variable whose address is to be computed.
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 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;
52 this.inner = inner;
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) {
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 error = true;
82 return false;
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)) {
88 error = true;
89 Report.error (source_reference, "Address-of operator not supported for this expression");
90 return false;
93 if (inner.value_type.is_reference_type_or_type_parameter ()) {
94 value_type = new PointerType (new PointerType (inner.value_type));
95 } else {
96 value_type = new PointerType (inner.value_type);
99 return !error;