1 /* valacatchclause.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
20 * Jürg Billeter <j@bitron.ch>
26 * Represents a catch clause in a try statement in the source code.
28 public class Vala
.CatchClause
: CodeNode
{
30 * Specifies the error type.
32 public DataType? error_type
{
33 get { return _data_type
; }
36 if (_data_type
!= null) {
37 _data_type
.parent_node
= this
;
43 * Specifies the error variable name.
45 public string? variable_name
{ get; set; }
48 * Specifies the error handler body.
54 _body
.parent_node
= this
;
59 * Specifies the declarator for the generated error variable.
61 public LocalVariable error_variable
{
62 get { return _error_variable
; }
64 _error_variable
= value
;
65 _error_variable
.parent_node
= this
;
70 * Specifies the label used for this catch clause in the C code.
72 public string? clabel_name
{ get; set; }
74 private DataType _data_type
;
77 private LocalVariable _error_variable
;
82 * @param type_reference error type
83 * @param variable_name error variable name
84 * @param body error handler body
85 * @param source_reference reference to source code
86 * @return newly created catch clause
88 public CatchClause (DataType? error_type
, string? variable_name
, Block body
, SourceReference? source_reference
= null) {
89 this
.error_type
= error_type
;
90 this
.variable_name
= variable_name
;
92 this
.source_reference
= source_reference
;
95 public override void accept (CodeVisitor visitor
) {
96 visitor
.visit_catch_clause (this
);
99 public override void accept_children (CodeVisitor visitor
) {
100 if (error_type
!= null) {
101 error_type
.accept (visitor
);
104 body
.accept (visitor
);
107 public override void replace_type (DataType old_type
, DataType new_type
) {
108 if (error_type
== old_type
) {
109 error_type
= new_type
;
113 public override bool check (SemanticAnalyzer analyzer
) {
120 if (error_type
!= null) {
121 error_variable
= new
LocalVariable (error_type
.copy (), variable_name
);
123 body
.scope
.add (variable_name
, error_variable
);
124 body
.add_local_variable (error_variable
);
126 error_variable
.checked
= true;
128 error_type
= new
ErrorType (null, null, source_reference
);
131 error_type
.check (analyzer
);
133 body
.check (analyzer
);
138 public override void get_defined_variables (Collection
<LocalVariable
> collection
) {
139 if (error_variable
!= null) {
140 collection
.add (error_variable
);