gio-unix-2.0: Add DesktopAppInfo.launch_uris_as_manager_with_fds()
[vala-gnome.git] / vala / valareferencetransferexpression.vala
blob9362bbd1ccec051aecb35a37dc25314e57baafb3
1 /* valareferencetransferexpression.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>
24 /**
25 * Represents a reference transfer expression in the source code, e.g. `#foo`.
27 public class Vala.ReferenceTransferExpression : Expression {
28 /**
29 * The variable whose reference is to be transferred.
31 public Expression inner {
32 get {
33 return _inner;
35 set {
36 _inner = value;
37 _inner.parent_node = this;
41 private Expression _inner;
43 /**
44 * Creates a new reference transfer expression.
46 * @param inner variable whose reference is to be transferred
47 * @return newly created reference transfer expression
49 public ReferenceTransferExpression (Expression inner, SourceReference? source_reference = null) {
50 this.inner = inner;
51 this.source_reference = source_reference;
54 public override void accept (CodeVisitor visitor) {
55 visitor.visit_reference_transfer_expression (this);
57 visitor.visit_expression (this);
60 public override void accept_children (CodeVisitor visitor) {
61 inner.accept (visitor);
64 public override void replace_expression (Expression old_node, Expression new_node) {
65 if (inner == old_node) {
66 inner = new_node;
70 public override bool is_pure () {
71 return false;
74 public override bool is_accessible (Symbol sym) {
75 return inner.is_accessible (sym);
78 public override bool check (CodeContext context) {
79 if (checked) {
80 return !error;
83 checked = true;
85 inner.lvalue = true;
87 inner.check (context);
89 if (inner.error) {
90 /* if there was an error in the inner expression, skip type check */
91 error = true;
92 return false;
95 if (!(inner is MemberAccess || inner is ElementAccess)) {
96 error = true;
97 Report.error (source_reference, "Reference transfer not supported for this expression");
98 return false;
101 var is_owned_delegate = inner.value_type is DelegateType && inner.value_type.value_owned;
102 if (!inner.value_type.is_disposable ()
103 && !(inner.value_type is PointerType)
104 && !is_owned_delegate) {
105 error = true;
106 Report.error (source_reference, "No reference to be transferred");
107 return false;
110 value_type = inner.value_type.copy ();
111 value_type.value_owned = true;
113 return !error;
116 public override void emit (CodeGenerator codegen) {
117 inner.emit (codegen);
119 codegen.visit_reference_transfer_expression (this);
121 codegen.visit_expression (this);
124 public override void get_defined_variables (Collection<Variable> collection) {
125 inner.get_defined_variables (collection);
126 var local = inner.symbol_reference as LocalVariable;
127 var param = inner.symbol_reference as Parameter;
128 if (local != null) {
129 collection.add (local);
130 } else if (param != null && param.direction == ParameterDirection.OUT) {
131 collection.add (param);
135 public override void get_used_variables (Collection<Variable> collection) {
136 inner.get_used_variables (collection);
137 var local = inner.symbol_reference as LocalVariable;
138 var param = inner.symbol_reference as Parameter;
139 if (local != null) {
140 collection.add (local);
141 } else if (param != null && param.direction == ParameterDirection.OUT) {
142 collection.add (param);