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, Position position, double value, 21 const Type* type = nullptr) 22 : INHERITED(position, 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 42 const double fValue; 43 44 typedef Expression INHERITED; 45 }; 46 47 } // namespace 48 49 #endif 50