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
20 * Jürg Billeter <j@bitron.ch>
27 * Represents a source code block.
29 public class Vala
.Block
: Symbol
, Statement
{
31 * Specifies whether this block contains a jump statement. This
32 * information can be used to remove unreachable block cleanup code.
34 public bool contains_jump_statement
{ get; set; }
36 private Gee
.List
<Statement
> statement_list
= new ArrayList
<Statement
> ();
37 private Gee
.List
<LocalVariable
> local_variables
= new ArrayList
<LocalVariable
> ();
40 * Creates a new block.
42 * @param source reference to source code
44 public Block (SourceReference source_reference
) {
45 base (null, source_reference
);
49 * Append a statement to this block.
51 * @param stmt a statement
53 public void add_statement (Statement stmt
) {
54 statement_list
.add (stmt
);
58 * Returns a copy of the list of statements.
60 * @return statement list
62 public Gee
.List
<Statement
> get_statements () {
63 return new ReadOnlyList
<Statement
> (statement_list
);
67 * Add a local variable to this block.
69 * @param decl a variable declarator
71 public void add_local_variable (LocalVariable local
) {
72 local_variables
.add (local
);
76 * Returns a copy of the list of local variables.
78 * @return variable declarator list
80 public Gee
.List
<LocalVariable
> get_local_variables () {
81 return new ReadOnlyList
<LocalVariable
> (local_variables
);
84 public override void accept (CodeVisitor visitor
) {
85 visitor
.visit_block (this
);
88 public override void accept_children (CodeVisitor visitor
) {
89 foreach (Statement stmt
in statement_list
) {
90 stmt
.accept (visitor
);
94 public override bool check (SemanticAnalyzer analyzer
) {
101 owner
= analyzer
.current_symbol
.scope
;
102 analyzer
.current_symbol
= this
;
104 foreach (Statement stmt
in statement_list
) {
105 stmt
.check (analyzer
);
108 foreach (LocalVariable local
in get_local_variables ()) {
109 local
.active
= false;
112 foreach (Statement stmt
in get_statements ()) {
113 add_error_types (stmt
.get_error_types ());
116 analyzer
.current_symbol
= analyzer
.current_symbol
.parent_symbol
;