1 /* valadostatement.vala
3 * Copyright (C) 2006-2008 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 do iteration statement in the source code.
28 public class Vala
.DoStatement
: CodeNode
, Statement
{
30 * Specifies the loop body.
38 _body
.parent_node
= this
;
43 * Specifies the loop condition.
45 public Expression condition
{
51 _condition
.parent_node
= this
;
55 private Expression _condition
;
59 * Creates a new do statement.
61 * @param cond loop condition
62 * @param body loop body
63 * @param source reference to source code
64 * @return newly created do statement
66 public DoStatement (Block body
, Expression condition
, SourceReference? source_reference
= null) {
67 this
.condition
= condition
;
68 this
.source_reference
= source_reference
;
72 public override void accept (CodeVisitor visitor
) {
73 visitor
.visit_do_statement (this
);
76 public override void accept_children (CodeVisitor visitor
) {
77 body
.accept (visitor
);
79 condition
.accept (visitor
);
81 visitor
.visit_end_full_expression (condition
);
84 public override void replace_expression (Expression old_node
, Expression new_node
) {
85 if (condition
== old_node
) {
90 public override bool check (SemanticAnalyzer analyzer
) {
97 body
.check (analyzer
);
99 if (!condition
.check (analyzer
)) {
100 /* if there was an error in the condition, skip this check */
105 if (!condition
.value_type
.compatible (analyzer
.bool_type
)) {
107 Report
.error (condition
.source_reference
, "Condition must be boolean");
111 add_error_types (condition
.get_error_types ());
112 add_error_types (body
.get_error_types ());