1 /* valaswitchsection.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
20 * Jürg Billeter <j@bitron.ch>
26 * Represents a switch section in the source code.
28 public class Vala
.SwitchSection
: Block
{
29 private List
<SwitchLabel
> labels
= new ArrayList
<SwitchLabel
> ();
32 * Creates a new switch section.
34 * @param source_reference reference to source code
35 * @return newly created switch section
37 public SwitchSection (SourceReference? source_reference
) {
38 base (source_reference
);
42 * Appends the specified label to the list of switch labels.
44 * @param label a switch label
46 public void add_label (SwitchLabel label
) {
52 * Returns a copy of the list of switch labels.
54 * @return switch label list
56 public List
<SwitchLabel
> get_labels () {
60 public bool has_default_label () {
61 foreach (SwitchLabel label
in labels
) {
62 if (label
.expression
== null) {
70 public override void accept (CodeVisitor visitor
) {
71 visitor
.visit_switch_section (this
);
74 public override void accept_children (CodeVisitor visitor
) {
75 foreach (SwitchLabel label
in labels
) {
76 label
.accept (visitor
);
79 foreach (Statement st
in get_statements ()) {
84 public override bool check (CodeContext context
) {
91 foreach (SwitchLabel label
in get_labels ()) {
92 label
.check (context
);
95 owner
= context
.analyzer
.current_symbol
.scope
;
97 var old_symbol
= context
.analyzer
.current_symbol
;
98 var old_insert_block
= context
.analyzer
.insert_block
;
99 context
.analyzer
.current_symbol
= this
;
100 context
.analyzer
.insert_block
= this
;
102 foreach (Statement st
in get_statements ()) {
106 foreach (LocalVariable local
in get_local_variables ()) {
107 local
.active
= false;
110 // use get_statements () instead of statement_list to not miss errors within StatementList objects
111 foreach (Statement stmt
in get_statements ()) {
112 add_error_types (stmt
.get_error_types ());
115 context
.analyzer
.current_symbol
= old_symbol
;
116 context
.analyzer
.insert_block
= old_insert_block
;
121 public override void emit (CodeGenerator codegen
) {
122 foreach (SwitchLabel label
in labels
) {
123 label
.emit (codegen
);