1 /* valadeclarationstatement.vala
3 * Copyright (C) 2006-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 local variable or constant declaration statement in the source code.
27 public class Vala
.DeclarationStatement
: CodeNode
, Statement
{
29 * The local variable or constant declaration.
31 public Symbol declaration
{
37 if (_declaration
!= null) {
38 _declaration
.parent_node
= this
;
46 * Creates a new declaration statement.
48 * @param declaration local variable declaration
49 * @param source_reference reference to source code
50 * @return newly created declaration statement
52 public DeclarationStatement (Symbol declaration
, SourceReference? source_reference
) {
53 this
.declaration
= declaration
;
54 this
.source_reference
= source_reference
;
57 public override void accept (CodeVisitor visitor
) {
58 visitor
.visit_declaration_statement (this
);
61 public override void accept_children (CodeVisitor visitor
) {
62 declaration
.accept (visitor
);
65 public override bool check (CodeContext context
) {
72 declaration
.check (context
);
74 var local
= declaration as LocalVariable
;
75 if (local
!= null && local
.initializer
!= null) {
76 foreach (DataType error_type
in local
.initializer
.get_error_types ()) {
77 // ensure we can trace back which expression may throw errors of this type
78 var initializer_error_type
= error_type
.copy ();
79 initializer_error_type
.source_reference
= local
.initializer
.source_reference
;
81 add_error_type (initializer_error_type
);
88 public override void emit (CodeGenerator codegen
) {
89 codegen
.visit_declaration_statement (this
);
92 public override void get_defined_variables (Collection
<Variable
> collection
) {
93 var local
= declaration as LocalVariable
;
95 var array_type
= local
.variable_type as ArrayType
;
96 if (local
.initializer
!= null) {
97 local
.initializer
.get_defined_variables (collection
);
98 collection
.add (local
);
99 } else if (array_type
!= null && array_type
.fixed_length
) {
100 collection
.add (local
);
105 public override void get_used_variables (Collection
<Variable
> collection
) {
106 var local
= declaration as LocalVariable
;
107 if (local
!= null && local
.initializer
!= null) {
108 local
.initializer
.get_used_variables (collection
);