Insert "%s" argument in printf calls with non-literal format string
[vala-lang.git] / vala / valadeclarationstatement.vala
blob428d88ef69db0244e3e875cad5cad85410158260
1 /* valadeclarationstatement.vala
3 * Copyright (C) 2006-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 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) {
92 var array_type = local.variable_type as ArrayType;
93 if (local.initializer != null) {
94 local.initializer.get_defined_variables (collection);
95 collection.add (local);
96 } else if (array_type != null && array_type.fixed_length) {
97 collection.add (local);
102 public override void get_used_variables (Collection<LocalVariable> collection) {
103 var local = declaration as LocalVariable;
104 if (local != null && local.initializer != null) {
105 local.initializer.get_used_variables (collection);