Line data Source code
1 : /* valabooleanliteral.vala
2 : *
3 : * Copyright (C) 2006-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 a literal boolean, i.e. true or false.
27 : */
28 121755 : public class Vala.BooleanLiteral : Literal {
29 : /**
30 : * The literal value.
31 : */
32 127221 : public bool value { get; private set; }
33 :
34 : /**
35 : * Creates a new boolean literal.
36 : *
37 : * @param b boolean value
38 : * @param source reference to source code
39 : * @return newly created boolean literal
40 : */
41 240436 : public BooleanLiteral (bool b, SourceReference? source = null) {
42 120218 : value = b;
43 120218 : source_reference = source;
44 : }
45 :
46 172046 : public override void accept (CodeVisitor visitor) {
47 172046 : visitor.visit_boolean_literal (this);
48 :
49 172046 : visitor.visit_expression (this);
50 : }
51 :
52 0 : public override string to_string () {
53 0 : if (value) {
54 0 : return "true";
55 : } else {
56 0 : return "false";
57 : }
58 : }
59 :
60 0 : public override bool is_pure () {
61 0 : return true;
62 : }
63 :
64 116745 : public override bool check (CodeContext context) {
65 116745 : if (checked) {
66 684 : return !error;
67 : }
68 :
69 116061 : checked = true;
70 :
71 116061 : value_type = context.analyzer.bool_type;
72 :
73 116061 : return !error;
74 : }
75 :
76 6851 : public override void emit (CodeGenerator codegen) {
77 6851 : codegen.visit_boolean_literal (this);
78 :
79 6851 : codegen.visit_expression (this);
80 : }
81 : }
|