Sync NEWS from 0.40
[vala-gnome.git] / vala / valathrowstatement.vala
blobd4cade7a24b6d7d3e22be498a5d9d78fa42f1297
1 /* valathrowstatement.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 throw statement in the source code.
27 public class Vala.ThrowStatement : CodeNode, Statement {
28 /**
29 * The error expression to throw.
31 public Expression error_expression {
32 get {
33 return _error_expression;
35 set {
36 _error_expression = value;
37 if (_error_expression != null) {
38 _error_expression.parent_node = this;
43 private Expression _error_expression;
45 /**
46 * Creates a new throw statement.
48 * @param error_expression the error expression
49 * @param source_reference reference to source code
50 * @return newly created throw statement
52 public ThrowStatement (Expression error_expression, SourceReference? source_reference = null) {
53 this.source_reference = source_reference;
54 this.error_expression = error_expression;
57 public override void accept (CodeVisitor visitor) {
58 visitor.visit_throw_statement (this);
61 public override void accept_children (CodeVisitor visitor) {
62 if (error_expression != null) {
63 error_expression.accept (visitor);
65 visitor.visit_end_full_expression (error_expression);
69 public override void replace_expression (Expression old_node, Expression new_node) {
70 if (error_expression == old_node) {
71 error_expression = new_node;
75 public override bool check (CodeContext context) {
76 if (checked) {
77 return !error;
80 checked = true;
82 if (context.profile == Profile.POSIX) {
83 Report.error (source_reference, "`throws' is not supported in POSIX profile");
84 error = true;
85 return false;
88 error_expression.target_type = new ErrorType (null, null, source_reference);
89 error_expression.target_type.value_owned = true;
91 if (error_expression != null) {
92 if (!error_expression.check (context)) {
93 error = true;
94 return false;
97 if (error_expression.value_type == null) {
98 Report.error (error_expression.source_reference, "invalid error expression");
99 error = true;
100 return false;
103 if (context.profile == Profile.GOBJECT && !(error_expression.value_type is ErrorType)) {
104 Report.error (error_expression.source_reference, "`%s' is not an error type".printf (error_expression.value_type.to_string ()));
105 error = true;
106 return false;
110 var error_type = error_expression.value_type.copy ();
111 error_type.source_reference = source_reference;
113 add_error_type (error_type);
115 return !error;
118 public override void emit (CodeGenerator codegen) {
119 if (error_expression != null) {
120 error_expression.emit (codegen);
122 codegen.visit_end_full_expression (error_expression);
125 codegen.visit_throw_statement (this);
128 public override void get_defined_variables (Collection<Variable> collection) {
129 error_expression.get_defined_variables (collection);
132 public override void get_used_variables (Collection<Variable> collection) {
133 error_expression.get_used_variables (collection);