D-Bus: Remove extra semicolon to avoid C warning
[vala-lang.git] / vala / valadeclarationstatement.vala
blob9eb8fffd6630e0ccb0b60f19b6bef7077ce9428c
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
24 /**
25 * Represents a local variable or constant declaration statement in the source code.
27 public class Vala.DeclarationStatement : CodeNode, Statement {
28 /**
29 * The local variable or constant declaration.
31 public Symbol declaration {
32 get {
33 return _declaration;
35 set {
36 _declaration = value;
37 if (_declaration != null) {
38 _declaration.parent_node = this;
43 Symbol _declaration;
45 /**
46 * Creates a new declaration statement.
48 * @param decl local variable declaration
49 * @param source 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) {
66 if (checked) {
67 return !error;
70 checked = true;
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);
85 return !error;
88 public override void emit (CodeGenerator codegen) {
89 codegen.visit_declaration_statement (this);
92 public override void get_defined_variables (Collection<LocalVariable> collection) {
93 var local = declaration as LocalVariable;
94 if (local != null) {
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<LocalVariable> collection) {
106 var local = declaration as LocalVariable;
107 if (local != null && local.initializer != null) {
108 local.initializer.get_used_variables (collection);