girparser: Provide default constructor for classes.
[vala-lang.git] / vala / valaswitchsection.vala
blobce8180507d887eeff61523249f8140f2603c5918
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents a switch section in the source code.
28 public class Vala.SwitchSection : Block {
29 private List<SwitchLabel> labels = new ArrayList<SwitchLabel> ();
31 /**
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);
41 /**
42 * Appends the specified label to the list of switch labels.
44 * @param label a switch label
46 public void add_label (SwitchLabel label) {
47 labels.add (label);
48 label.section = this;
51 /**
52 * Returns a copy of the list of switch labels.
54 * @return switch label list
56 public List<SwitchLabel> get_labels () {
57 return labels;
60 public bool has_default_label () {
61 foreach (SwitchLabel label in labels) {
62 if (label.expression == null) {
63 return true;
67 return false;
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 ()) {
80 st.accept (visitor);
84 public override bool check (CodeContext context) {
85 if (checked) {
86 return !error;
89 checked = true;
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 ()) {
103 st.check (context);
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;
118 return !error;
121 public override void emit (CodeGenerator codegen) {
122 foreach (SwitchLabel label in labels) {
123 label.emit (codegen);
126 base.emit (codegen);