1 | /* |
2 | * Copyright 2016 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #ifndef SKSL_BOOLLITERAL |
9 | #define SKSL_BOOLLITERAL |
10 | |
11 | #include "src/sksl/SkSLContext.h" |
12 | #include "src/sksl/ir/SkSLExpression.h" |
13 | |
14 | namespace SkSL { |
15 | |
16 | /** |
17 | * Represents 'true' or 'false'. |
18 | */ |
19 | struct BoolLiteral : public Expression { |
20 | BoolLiteral(const Context& context, int offset, bool value) |
21 | : INHERITED(offset, kBoolLiteral_Kind, *context.fBool_Type) |
22 | , fValue(value) {} |
23 | |
24 | #ifdef SK_DEBUG |
25 | String description() const override { |
26 | return String(fValue ? "true" : "false" ); |
27 | } |
28 | #endif |
29 | |
30 | bool hasProperty(Property property) const override { |
31 | return false; |
32 | } |
33 | |
34 | bool isConstant() const override { |
35 | return true; |
36 | } |
37 | |
38 | bool compareConstant(const Context& context, const Expression& other) const override { |
39 | BoolLiteral& b = (BoolLiteral&) other; |
40 | return fValue == b.fValue; |
41 | } |
42 | |
43 | std::unique_ptr<Expression> clone() const override { |
44 | return std::unique_ptr<Expression>(new BoolLiteral(fOffset, fValue, &fType)); |
45 | } |
46 | |
47 | const bool fValue; |
48 | |
49 | typedef Expression INHERITED; |
50 | |
51 | private: |
52 | BoolLiteral(int offset, bool value, const Type* type) |
53 | : INHERITED(offset, kBoolLiteral_Kind, *type) |
54 | , fValue(value) {} |
55 | }; |
56 | |
57 | } // namespace |
58 | |
59 | #endif |
60 | |