linux: Add psiginfo(3)
[vala-gnome.git] / vala / valaaddressofexpression.vala
blobb5371745d2f100f7c8cb8e7ed3ea60c7e1b2e8e7
1 /* valaaddressofexpression.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>
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 visitor.visit_addressof_expression (this);
58 visitor.visit_expression (this);
61 public override void accept_children (CodeVisitor visitor) {
62 inner.accept (visitor);
65 public override void replace_expression (Expression old_node, Expression new_node) {
66 if (inner == old_node) {
67 inner = new_node;
71 public override bool is_pure () {
72 return inner.is_pure ();
75 public override bool is_accessible (Symbol sym) {
76 return inner.is_accessible (sym);
79 public override bool check (CodeContext context) {
80 if (checked) {
81 return !error;
84 checked = true;
86 inner.lvalue = true;
88 if (!inner.check (context)) {
89 error = true;
90 return false;
92 var ea = inner as ElementAccess;
93 if (inner is MemberAccess && inner.symbol_reference is Variable) {
94 // address of variable is always possible
95 } else if (ea != null &&
96 (ea.container.value_type is ArrayType || ea.container.value_type is PointerType)) {
97 // address of element of regular array or pointer is always possible
98 } else {
99 error = true;
100 Report.error (source_reference, "Address-of operator not supported for this expression");
101 return false;
104 if (inner.value_type.is_reference_type_or_type_parameter ()) {
105 value_type = new PointerType (new PointerType (inner.value_type));
106 } else {
107 value_type = new PointerType (inner.value_type);
110 return !error;
113 public override void emit (CodeGenerator codegen) {
114 inner.emit (codegen);
116 codegen.visit_addressof_expression (this);
118 codegen.visit_expression (this);