D-Bus: Remove extra semicolon to avoid C warning
[vala-lang.git] / vala / valacatchclause.vala
blob72c9d84682025d2bf40160765687b6b6b65fad0a
1 /* valacatchclause.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 catch clause in a try statement in the source code.
27 public class Vala.CatchClause : CodeNode {
28 /**
29 * Specifies the error type.
31 public DataType? error_type {
32 get { return _data_type; }
33 set {
34 _data_type = value;
35 if (_data_type != null) {
36 _data_type.parent_node = this;
41 /**
42 * Specifies the error variable name.
44 public string? variable_name { get; set; }
46 /**
47 * Specifies the error handler body.
49 public Block body {
50 get { return _body; }
51 set {
52 _body = value;
53 _body.parent_node = this;
57 /**
58 * Specifies the declarator for the generated error variable.
60 public LocalVariable error_variable {
61 get { return _error_variable; }
62 set {
63 _error_variable = value;
64 _error_variable.parent_node = this;
68 /**
69 * Specifies the label used for this catch clause in the C code.
71 public string? clabel_name { get; set; }
73 private DataType _data_type;
75 private Block _body;
76 private LocalVariable _error_variable;
78 /**
79 * Creates a new catch
81 * @param type_reference error type
82 * @param variable_name error variable name
83 * @param body error handler body
84 * @param source_reference reference to source code
85 * @return newly created catch clause
87 public CatchClause (DataType? error_type, string? variable_name, Block body, SourceReference? source_reference = null) {
88 this.error_type = error_type;
89 this.variable_name = variable_name;
90 this.body = body;
91 this.source_reference = source_reference;
94 public override void accept (CodeVisitor visitor) {
95 visitor.visit_catch_clause (this);
98 public override void accept_children (CodeVisitor visitor) {
99 if (error_type != null) {
100 error_type.accept (visitor);
103 body.accept (visitor);
106 public override void replace_type (DataType old_type, DataType new_type) {
107 if (error_type == old_type) {
108 error_type = new_type;
112 public override bool check (CodeContext context) {
113 if (checked) {
114 return !error;
117 checked = true;
119 if (error_type != null) {
120 error_variable = new LocalVariable (error_type.copy (), variable_name);
122 body.scope.add (variable_name, error_variable);
123 body.add_local_variable (error_variable);
125 error_variable.checked = true;
126 } else {
127 // generic catch clause
128 if (context.profile == Profile.GOBJECT) {
129 error_type = new ErrorType (null, null, source_reference);
130 } else {
131 error_type = context.analyzer.error_type;
135 error_type.check (context);
137 body.check (context);
139 return !error;
142 public override void emit (CodeGenerator codegen) {
143 if (error_variable != null) {
144 error_variable.active = true;
147 codegen.visit_catch_clause (this);
150 public override void get_defined_variables (Collection<LocalVariable> collection) {
151 if (error_variable != null) {
152 collection.add (error_variable);