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 { 20 FloatLiteral(const Context& context, int offset, double value, 21 const Type* type = nullptr) 22 : INHERITED(offset, kFloatLiteral_Kind, type ? *type : *context.fFloat_Type) 23 , fValue(value) {} 24 descriptionFloatLiteral25 String description() const override { 26 return to_string(fValue); 27 } 28 hasSideEffectsFloatLiteral29 bool hasSideEffects() const override { 30 return false; 31 } 32 isConstantFloatLiteral33 bool isConstant() const override { 34 return true; 35 } 36 compareConstantFloatLiteral37 bool compareConstant(const Context& context, const Expression& other) const override { 38 FloatLiteral& f = (FloatLiteral&) other; 39 return fValue == f.fValue; 40 } 41 getConstantFloatFloatLiteral42 double getConstantFloat() const override { 43 return fValue; 44 } 45 46 const double fValue; 47 48 typedef Expression INHERITED; 49 }; 50 51 } // namespace 52 53 #endif 54