Improve string tests
[vala-lang.git] / vala / valadeclarationstatement.vala
blob3f6c90e2725d806ec891408f983d8053ab906915
1 /* valadeclarationstatement.vala
3 * Copyright (C) 2006-2008 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 local variable or constant declaration statement in the source code.
28 public class Vala.DeclarationStatement : CodeNode, Statement {
29 /**
30 * The local variable or constant declaration.
32 public Symbol declaration {
33 get {
34 return _declaration;
36 set {
37 _declaration = value;
38 if (_declaration != null) {
39 _declaration.parent_node = this;
44 Symbol _declaration;
46 /**
47 * Creates a new declaration statement.
49 * @param decl local variable declaration
50 * @param source reference to source code
51 * @return newly created declaration statement
53 public DeclarationStatement (Symbol declaration, SourceReference? source_reference) {
54 this.declaration = declaration;
55 this.source_reference = source_reference;
58 public override void accept (CodeVisitor visitor) {
59 visitor.visit_declaration_statement (this);
62 public override void accept_children (CodeVisitor visitor) {
63 declaration.accept (visitor);
66 public override bool check (SemanticAnalyzer analyzer) {
67 if (checked) {
68 return !error;
71 checked = true;
73 declaration.check (analyzer);
75 var local = declaration as LocalVariable;
76 if (local != null && local.initializer != null) {
77 foreach (DataType error_type in local.initializer.get_error_types ()) {
78 // ensure we can trace back which expression may throw errors of this type
79 var initializer_error_type = error_type.copy ();
80 initializer_error_type.source_reference = local.initializer.source_reference;
82 add_error_type (initializer_error_type);
86 return !error;
89 public override void get_defined_variables (Collection<LocalVariable> collection) {
90 var local = declaration as LocalVariable;
91 if (local != null && local.initializer != null) {
92 local.initializer.get_defined_variables (collection);
93 collection.add (local);
97 public override void get_used_variables (Collection<LocalVariable> collection) {
98 var local = declaration as LocalVariable;
99 if (local != null && local.initializer != null) {
100 local.initializer.get_used_variables (collection);