Insert "%s" argument in printf calls with non-literal format string
[vala-lang.git] / vala / valacatchclause.vala
blob4ce8ce1fe1e60b1060f3d703d2221fab4f833efb
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using Gee;
25 /**
26 * Represents a catch clause in a try statement in the source code.
28 public class Vala.CatchClause : CodeNode {
29 /**
30 * Specifies the error type.
32 public DataType? error_type {
33 get { return _data_type; }
34 set {
35 _data_type = value;
36 if (_data_type != null) {
37 _data_type.parent_node = this;
42 /**
43 * Specifies the error variable name.
45 public string? variable_name { get; set; }
47 /**
48 * Specifies the error handler body.
50 public Block body {
51 get { return _body; }
52 set {
53 _body = value;
54 _body.parent_node = this;
58 /**
59 * Specifies the declarator for the generated error variable.
61 public LocalVariable error_variable {
62 get { return _error_variable; }
63 set {
64 _error_variable = value;
65 _error_variable.parent_node = this;
69 /**
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;
76 private Block _body;
77 private LocalVariable _error_variable;
79 /**
80 * Creates a new catch
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;
91 this.body = body;
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) {
114 if (checked) {
115 return !error;
118 checked = true;
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;
127 } else {
128 error_type = new ErrorType (null, null, source_reference);
131 error_type.check (analyzer);
133 body.check (analyzer);
135 return !error;
138 public override void get_defined_variables (Collection<LocalVariable> collection) {
139 if (error_variable != null) {
140 collection.add (error_variable);