Line data Source code
1 : /* valayieldstatement.vala
2 : *
3 : * Copyright (C) 2008-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 : /**
24 : * Represents a yield statement in the source code.
25 : */
26 26 : public class Vala.YieldStatement : CodeNode, Statement {
27 : /**
28 : * Creates a new yield statement.
29 : *
30 : * @param source_reference reference to source code
31 : * @return newly created yield statement
32 : */
33 36 : public YieldStatement (SourceReference? source_reference = null) {
34 18 : this.source_reference = source_reference;
35 : }
36 :
37 36 : public override void accept (CodeVisitor visitor) {
38 36 : visitor.visit_yield_statement (this);
39 : }
40 :
41 18 : public override bool check (CodeContext context) {
42 18 : if (checked) {
43 0 : return !error;
44 : }
45 :
46 18 : checked = true;
47 :
48 18 : if (context.analyzer.current_method == null || !context.analyzer.current_method.coroutine) {
49 1 : error = true;
50 1 : Report.error (source_reference, "yield statement not available outside async method");
51 : }
52 :
53 18 : return !error;
54 : }
55 :
56 17 : public override void emit (CodeGenerator codegen) {
57 17 : codegen.visit_yield_statement (this);
58 : }
59 : }
60 :
|