gstreamer-pbutils-0.10: Ownership transfer fixes
[vala-lang.git] / vala / valaswitchstatement.vala
blob0fd5b838332a0f4cef92df92f8dd71158f121206
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.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;
24 using Gee;
26 /**
27 * Represents a switch selection statement in the source code.
29 public class Vala.SwitchStatement : CodeNode, Statement {
30 /**
31 * Specifies the switch expression.
33 public Expression expression {
34 get {
35 return _expression;
37 set {
38 _expression = value;
39 _expression.parent_node = this;
43 private Expression _expression;
44 private Gee.List<SwitchSection> sections = new ArrayList<SwitchSection> ();
46 /**
47 * Creates a new switch statement.
49 * @param expression switch expression
50 * @param source_reference reference to source code
51 * @return newly created switch statement
53 public SwitchStatement (Expression expression, SourceReference source_reference) {
54 this.source_reference = source_reference;
55 this.expression = expression;
58 /**
59 * Appends the specified section to the list of switch sections.
61 * @param section a switch section
63 public void add_section (SwitchSection section) {
64 section.parent_node = this;
65 sections.add (section);
68 /**
69 * Returns a copy of the list of switch sections.
71 * @return section list
73 public Gee.List<SwitchSection> get_sections () {
74 return new ReadOnlyList<SwitchSection> (sections);
77 public override void accept (CodeVisitor visitor) {
78 visitor.visit_switch_statement (this);
81 public override void accept_children (CodeVisitor visitor) {
82 expression.accept (visitor);
84 visitor.visit_end_full_expression (expression);
86 foreach (SwitchSection section in sections) {
87 section.accept (visitor);
91 public override void replace_expression (Expression old_node, Expression new_node) {
92 if (expression == old_node) {
93 expression = new_node;
97 public override bool check (SemanticAnalyzer analyzer) {
98 if (checked) {
99 return !error;
102 checked = true;
104 if (!expression.check (analyzer)) {
105 error = true;
106 return false;
109 if (!expression.value_type.compatible (analyzer.uint64_type)
110 && !expression.value_type.compatible (analyzer.string_type)) {
111 Report.error (expression.source_reference, "Integer or string expression expected");
112 error = true;
113 return false;
116 foreach (SwitchSection section in sections) {
117 section.check (analyzer);
120 return !error;