/src/skia/src/sksl/ir/SkSLFloatLiteral.h
Line | Count | Source (jump to first uncovered line) |
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_FLOATLITERAL |
9 | | #define SKSL_FLOATLITERAL |
10 | | |
11 | | #include "src/sksl/SkSLContext.h" |
12 | | #include "src/sksl/ir/SkSLExpression.h" |
13 | | |
14 | | namespace SkSL { |
15 | | |
16 | | /** |
17 | | * A literal floating point number. These are generally referred to as FloatLiteral, but |
18 | | * Literal<SKSL_FLOAT> is also available for use with template code. |
19 | | */ |
20 | | template <typename T> class Literal; |
21 | | using FloatLiteral = Literal<SKSL_FLOAT>; |
22 | | |
23 | | template <> |
24 | | class Literal<SKSL_FLOAT> final : public Expression { |
25 | | public: |
26 | | static constexpr Kind kExpressionKind = Kind::kFloatLiteral; |
27 | | |
28 | | Literal(int offset, float value, const Type* type) |
29 | | : INHERITED(offset, kExpressionKind, type) |
30 | 4.05M | , fValue(value) {} |
31 | | |
32 | | // Makes a literal of $floatLiteral type. |
33 | 49.3k | static std::unique_ptr<FloatLiteral> Make(const Context& context, int offset, float value) { |
34 | 49.3k | return std::make_unique<FloatLiteral>(offset, value, context.fTypes.fFloatLiteral.get()); |
35 | 49.3k | } |
36 | | |
37 | | // Makes a literal of the specified floating-point type. |
38 | 2.84M | static std::unique_ptr<FloatLiteral> Make(int offset, float value, const Type* type) { |
39 | 2.84M | SkASSERT(type->isFloat()); |
40 | 2.84M | return std::make_unique<FloatLiteral>(offset, value, type); |
41 | 2.84M | } SkSL::Literal<float>::Make(int, float, SkSL::Type const*) Line | Count | Source | 38 | 293 | static std::unique_ptr<FloatLiteral> Make(int offset, float value, const Type* type) { | 39 | 293 | SkASSERT(type->isFloat()); | 40 | 293 | return std::make_unique<FloatLiteral>(offset, value, type); | 41 | 293 | } |
SkSL::Literal<float>::Make(int, float, SkSL::Type const*) Line | Count | Source | 38 | 2.84M | static std::unique_ptr<FloatLiteral> Make(int offset, float value, const Type* type) { | 39 | 2.84M | SkASSERT(type->isFloat()); | 40 | 2.84M | return std::make_unique<FloatLiteral>(offset, value, type); | 41 | 2.84M | } |
|
42 | | |
43 | 5.74M | float value() const { |
44 | 5.74M | return fValue; |
45 | 5.74M | } |
46 | | |
47 | 6.84k | String description() const override { |
48 | 6.84k | return to_string(this->value()); |
49 | 6.84k | } |
50 | | |
51 | 394k | bool hasProperty(Property property) const override { |
52 | 394k | return false; |
53 | 394k | } |
54 | | |
55 | 2.40M | bool isCompileTimeConstant() const override { |
56 | 2.40M | return true; |
57 | 2.40M | } |
58 | | |
59 | 31.6k | CoercionCost coercionCost(const Type& target) const override { |
60 | 31.6k | if (target.isFloat()) { |
61 | 29.0k | return CoercionCost::Free(); |
62 | 29.0k | } |
63 | 2.59k | return INHERITED::coercionCost(target); |
64 | 2.59k | } |
65 | | |
66 | 4.84k | ComparisonResult compareConstant(const Expression& other) const override { |
67 | 4.84k | if (!other.is<FloatLiteral>()) { |
68 | 0 | return ComparisonResult::kUnknown; |
69 | 0 | } |
70 | 4.84k | return this->value() == other.as<FloatLiteral>().value() ? ComparisonResult::kEqual |
71 | 1.67k | : ComparisonResult::kNotEqual; |
72 | 4.84k | } |
73 | | |
74 | 1.12M | std::unique_ptr<Expression> clone() const override { |
75 | 1.12M | return std::make_unique<FloatLiteral>(fOffset, this->value(), &this->type()); |
76 | 1.12M | } |
77 | | |
78 | 3.03M | const Expression* getConstantSubexpression(int n) const override { |
79 | 3.03M | SkASSERT(n == 0); |
80 | 3.03M | return this; |
81 | 3.03M | } SkSL::Literal<float>::getConstantSubexpression(int) const Line | Count | Source | 78 | 190 | const Expression* getConstantSubexpression(int n) const override { | 79 | 190 | SkASSERT(n == 0); | 80 | 190 | return this; | 81 | 190 | } |
SkSL::Literal<float>::getConstantSubexpression(int) const Line | Count | Source | 78 | 3.03M | const Expression* getConstantSubexpression(int n) const override { | 79 | 3.03M | SkASSERT(n == 0); | 80 | 3.03M | return this; | 81 | 3.03M | } |
|
82 | | |
83 | | private: |
84 | | float fValue; |
85 | | |
86 | | using INHERITED = Expression; |
87 | | }; |
88 | | |
89 | | } // namespace SkSL |
90 | | |
91 | | #endif |