Add string.replace method, patch by Ali Sabil
[vala-lang.git] / vala / valadostatement.vala
blob8700c883c09771909f9f412443e3b6b4f34d9625
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents a do iteration statement in the source code.
28 public class Vala.DoStatement : CodeNode, Statement {
29 /**
30 * Specifies the loop body.
32 public Block body {
33 get {
34 return _body;
36 set {
37 _body = value;
38 _body.parent_node = this;
42 /**
43 * Specifies the loop condition.
45 public Expression condition {
46 get {
47 return _condition;
49 set {
50 _condition = value;
51 _condition.parent_node = this;
55 private Expression _condition;
56 private Block _body;
58 /**
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;
69 this.body = body;
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) {
86 condition = new_node;
90 public override bool check (SemanticAnalyzer analyzer) {
91 if (checked) {
92 return !error;
95 checked = true;
97 body.check (analyzer);
99 if (!condition.check (analyzer)) {
100 /* if there was an error in the condition, skip this check */
101 error = true;
102 return false;
105 if (!condition.value_type.compatible (analyzer.bool_type)) {
106 error = true;
107 Report.error (condition.source_reference, "Condition must be boolean");
108 return false;
111 add_error_types (condition.get_error_types ());
112 add_error_types (body.get_error_types ());
114 return !error;