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. 18 */ 19 struct FloatLiteral : public Expression { FloatLiteralFloatLiteral20 FloatLiteral(const Context& context, int offset, double value) 21 : INHERITED(offset, kFloatLiteral_Kind, *context.fFloatLiteral_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 coercionCostFloatLiteral40 int coercionCost(const Type& target) const override { 41 if (target.isFloat()) { 42 return 0; 43 } 44 return INHERITED::coercionCost(target); 45 } 46 compareConstantFloatLiteral47 bool compareConstant(const Context& context, const Expression& other) const override { 48 FloatLiteral& f = (FloatLiteral&) other; 49 return fValue == f.fValue; 50 } 51 getConstantFloatFloatLiteral52 double getConstantFloat() const override { 53 return fValue; 54 } 55 cloneFloatLiteral56 std::unique_ptr<Expression> clone() const override { 57 return std::unique_ptr<Expression>(new FloatLiteral(fOffset, fValue, &fType)); 58 } 59 60 const double fValue; 61 62 typedef Expression INHERITED; 63 }; 64 65 } // namespace 66 67 #endif 68