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
20 * Jürg Billeter <j@bitron.ch>
25 * Represents a throw statement in the source code.
27 public class Vala
.ThrowStatement
: CodeNode
, Statement
{
29 * The error expression to throw.
31 public Expression error_expression
{
33 return _error_expression
;
36 _error_expression
= value
;
37 if (_error_expression
!= null) {
38 _error_expression
.parent_node
= this
;
43 private Expression _error_expression
;
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
) {
82 if (context
.profile
== Profile
.GOBJECT
) {
83 error_expression
.target_type
= new
ErrorType (null, null, source_reference
);
85 error_expression
.target_type
= context
.analyzer
.error_type
.copy ();
87 error_expression
.target_type
.value_owned
= true;
89 if (error_expression
!= null) {
90 if (!error_expression
.check (context
)) {
95 if (error_expression
.value_type
== null) {
96 Report
.error (error_expression
.source_reference
, "invalid error expression");
101 if (context
.profile
== Profile
.GOBJECT
&& !(error_expression
.value_type is ErrorType
)) {
102 Report
.error (error_expression
.source_reference
, "`%s' is not an error type".printf (error_expression
.value_type
.to_string ()));
108 var error_type
= error_expression
.value_type
.copy ();
109 error_type
.source_reference
= source_reference
;
111 add_error_type (error_type
);
116 public override void emit (CodeGenerator codegen
) {
117 if (error_expression
!= null) {
118 error_expression
.emit (codegen
);
120 codegen
.visit_end_full_expression (error_expression
);
123 codegen
.visit_throw_statement (this
);
126 public override void get_defined_variables (Collection
<LocalVariable
> collection
) {
127 error_expression
.get_defined_variables (collection
);
130 public override void get_used_variables (Collection
<LocalVariable
> collection
) {
131 error_expression
.get_used_variables (collection
);