Line data Source code
1 : /* valaloopstatement.vala
2 : *
3 : * Copyright (C) 2009-2010 Jürg Billeter
4 : *
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.
9 :
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.
14 :
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
18 : *
19 : * Author:
20 : * Jürg Billeter <j@bitron.ch>
21 : */
22 :
23 : using GLib;
24 :
25 : /**
26 : * Represents an endless loop.
27 : */
28 2846 : public class Vala.LoopStatement : Loop, Statement {
29 : /**
30 : * Creates a new loop.
31 : *
32 : * @param body loop body
33 : * @param source_reference reference to source code
34 : * @return newly created while statement
35 : */
36 27146 : public LoopStatement (Block body, SourceReference? source_reference = null) {
37 13573 : base (new BooleanLiteral (true, source_reference), body, source_reference);
38 : }
39 :
40 9506 : public override void accept (CodeVisitor visitor) {
41 9506 : visitor.visit_loop_statement (this);
42 : }
43 :
44 1 : public override void accept_children (CodeVisitor visitor) {
45 1 : body.accept (visitor);
46 : }
47 :
48 13110 : public override void get_error_types (Collection<DataType> collection, SourceReference? source_reference = null) {
49 13110 : body.get_error_types (collection, source_reference);
50 : }
51 :
52 13573 : public override bool check (CodeContext context) {
53 13573 : if (checked) {
54 0 : return !error;
55 : }
56 :
57 13573 : checked = true;
58 :
59 13573 : condition.check (context);
60 13573 : body.check (context);
61 :
62 13573 : return !error;
63 : }
64 :
65 880 : public override void emit (CodeGenerator codegen) {
66 880 : codegen.visit_loop_statement (this);
67 : }
68 : }
69 :
|