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 "SkSLContext.h"
12 #include "SkSLExpression.h"
13 
14 namespace SkSL {
15 
16 /**
17  * A literal floating point number.
18  */
19 struct FloatLiteral : public Expression {
FloatLiteralFloatLiteral20     FloatLiteral(const Context& context, int offset, double value)
21     : INHERITED(offset, kFloatLiteral_Kind, *context.fFloat_Type)
22     , fValue(value) {}
23 
FloatLiteralFloatLiteral24     FloatLiteral(int offset, double value, const Type* type)
25     : INHERITED(offset, kFloatLiteral_Kind, *type)
26     , fValue(value) {}
27 
descriptionFloatLiteral28     String description() const override {
29         return to_string(fValue);
30     }
31 
hasSideEffectsFloatLiteral32     bool hasSideEffects() const override {
33         return false;
34     }
35 
isConstantFloatLiteral36     bool isConstant() const override {
37         return true;
38     }
39 
compareConstantFloatLiteral40     bool compareConstant(const Context& context, const Expression& other) const override {
41         FloatLiteral& f = (FloatLiteral&) other;
42         return fValue == f.fValue;
43     }
44 
getConstantFloatFloatLiteral45     double getConstantFloat() const override {
46         return fValue;
47     }
48 
cloneFloatLiteral49     std::unique_ptr<Expression> clone() const override {
50         return std::unique_ptr<Expression>(new FloatLiteral(fOffset, fValue, &fType));
51     }
52 
53     const double fValue;
54 
55     typedef Expression INHERITED;
56 };
57 
58 } // namespace
59 
60 #endif
61