codegen: Limit scope of locals freed on errors thrown from catch clauses
[vala-lang.git] / vala / valaaddressofexpression.vala
blob7786cfd2ee4b48f0d53e22485b586b17e6ff3abe
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 check (CodeContext context) {
76 if (checked) {
77 return !error;
80 checked = true;
82 if (!inner.check (context)) {
83 error = true;
84 return false;
86 var ea = inner as ElementAccess;
87 if (inner is MemberAccess && inner.symbol_reference is Variable) {
88 // address of variable is always possible
89 } else if (ea != null &&
90 (ea.container.value_type is ArrayType || ea.container.value_type is PointerType)) {
91 // address of element of regular array or pointer is always possible
92 } else {
93 error = true;
94 Report.error (source_reference, "Address-of operator not supported for this expression");
95 return false;
98 if (inner.value_type.is_reference_type_or_type_parameter ()) {
99 value_type = new PointerType (new PointerType (inner.value_type));
100 } else {
101 value_type = new PointerType (inner.value_type);
104 return !error;
107 public override void emit (CodeGenerator codegen) {
108 inner.emit (codegen);
110 codegen.visit_addressof_expression (this);
112 codegen.visit_expression (this);