gstreamer-pbutils-0.10: Ownership transfer fixes
[vala-lang.git] / vala / valathrowstatement.vala
blob4ff77241b86286544646df267a4823a55e2ff1f2
1 /* valathrowstatement.vala
3 * Copyright (C) 2007-2009 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 Gee;
25 /**
26 * Represents a throw statement in the source code.
28 public class Vala.ThrowStatement : CodeNode, Statement {
29 /**
30 * The error expression to throw.
32 public Expression error_expression {
33 get {
34 return _error_expression;
36 set {
37 _error_expression = value;
38 if (_error_expression != null) {
39 _error_expression.parent_node = this;
44 private Expression _error_expression;
46 /**
47 * Creates a new throw statement.
49 * @param error_expression the error expression
50 * @param source_reference reference to source code
51 * @return newly created throw statement
53 public ThrowStatement (Expression error_expression, SourceReference? source_reference = null) {
54 this.source_reference = source_reference;
55 this.error_expression = error_expression;
58 public override void accept (CodeVisitor visitor) {
59 visitor.visit_throw_statement (this);
62 public override void accept_children (CodeVisitor visitor) {
63 if (error_expression != null) {
64 error_expression.accept (visitor);
66 visitor.visit_end_full_expression (error_expression);
70 public override void replace_expression (Expression old_node, Expression new_node) {
71 if (error_expression == old_node) {
72 error_expression = new_node;
76 public override bool check (SemanticAnalyzer analyzer) {
77 if (checked) {
78 return !error;
81 checked = true;
83 error_expression.target_type = new ErrorType (null, null, source_reference);
84 error_expression.target_type.value_owned = true;
86 if (error_expression != null) {
87 if (!error_expression.check (analyzer)) {
88 error = true;
89 return false;
92 if (error_expression.value_type == null) {
93 Report.error (error_expression.source_reference, "invalid error expression");
94 error = true;
95 return false;
98 if (!(error_expression.value_type is ErrorType)) {
99 Report.error (error_expression.source_reference, "`%s' is not an error type".printf (error_expression.value_type.to_string ()));
100 error = true;
101 return false;
105 var error_type = error_expression.value_type.copy ();
106 error_type.source_reference = source_reference;
108 add_error_type (error_type);
110 return !error;
113 public override void get_defined_variables (Collection<LocalVariable> collection) {
114 error_expression.get_defined_variables (collection);
117 public override void get_used_variables (Collection<LocalVariable> collection) {
118 error_expression.get_used_variables (collection);