1 /* valaswitchstatement.vala
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 switch selection statement in the source code.
28 public class Vala
.SwitchStatement
: Statement
{
30 * Specifies the switch expression.
32 public Expression
! expression
{
38 _expression
.parent_node
= this
;
42 private Expression
! _expression
;
43 private List
<SwitchSection
> sections
;
46 * Creates a new switch statement.
48 * @param expr switch expression
49 * @param source reference to source code
50 * @return newly created switch statement
52 public SwitchStatement (Expression
! expr
, SourceReference source
) {
54 source_reference
= source
;
58 * Appends the specified section to the list of switch sections.
60 * @param section a switch section
62 public void add_section (SwitchSection
! section
) {
63 sections
.append (section
);
67 * Returns a copy of the list of switch sections.
69 * @return section list
71 public List
<weak SwitchSection
> get_sections () {
72 return sections
.copy ();
75 public override void accept (CodeVisitor
! visitor
) {
76 expression
.accept (visitor
);
78 visitor
.visit_end_full_expression (expression
);
80 foreach (SwitchSection section
in sections
) {
81 section
.accept (visitor
);
84 visitor
.visit_switch_statement (this
);
87 public override void replace (CodeNode
! old_node
, CodeNode
! new_node
) {
88 if (expression
== old_node
) {
89 expression
= (Expression
) new_node
;