3 * Copyright (C) 2006-2007 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 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>
26 * Represents a source code block.
28 public class Vala
.Block
: Statement
{
30 * Specifies whether this block contains a jump statement. This
31 * information can be used to remove unreachable block cleanup code.
33 public bool contains_jump_statement
{ get; set; }
35 private List
<Statement
> statement_list
;
36 private List
<VariableDeclarator
> local_variables
;
39 * Creates a new block.
41 * @param source reference to source code
43 public Block (SourceReference source
= null) {
44 source_reference
= source
;
48 * Append a statement to this block.
50 * @param stmt a statement
52 public void add_statement (Statement
! stmt
) {
53 statement_list
.append (stmt
);
57 * Returns a copy of the list of statements.
59 * @return statement list
61 public List
<weak Statement
> get_statements () {
62 return statement_list
.copy ();
66 * Add a local variable to this block.
68 * @param decl a variable declarator
70 public void add_local_variable (VariableDeclarator
! decl
) {
71 local_variables
.append (decl
);
75 * Returns a copy of the list of local variables.
77 * @return variable declarator list
79 public List
<weak VariableDeclarator
> get_local_variables () {
80 return local_variables
.copy ();
83 public override void accept (CodeVisitor
! visitor
) {
84 visitor
.visit_begin_block (this
);
86 foreach (Statement
! stmt
in statement_list
) {
87 stmt
.accept (visitor
);
90 visitor
.visit_end_block (this
);