Home | History | Annotate | Download | only in ir
      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_INTLITERAL
      9 #define SKSL_INTLITERAL
     10 
     11 #include "SkSLContext.h"
     12 #include "SkSLExpression.h"
     13 
     14 namespace SkSL {
     15 
     16 /**
     17  * A literal integer.
     18  */
     19 struct IntLiteral : public Expression {
     20     // FIXME: we will need to revisit this if/when we add full support for both signed and unsigned
     21     // 64-bit integers, but for right now an int64_t will hold every value we care about
     22     IntLiteral(const Context& context, Position position, int64_t value, const Type* type = nullptr)
     23     : INHERITED(position, kIntLiteral_Kind, type ? *type : *context.fInt_Type)
     24     , fValue(value) {}
     25 
     26     String description() const override {
     27         return to_string(fValue);
     28     }
     29 
     30     bool hasSideEffects() const override {
     31         return false;
     32     }
     33 
     34     bool isConstant() const override {
     35         return true;
     36     }
     37 
     38     bool compareConstant(const Context& context, const Expression& other) const override {
     39         IntLiteral& i = (IntLiteral&) other;
     40         return fValue == i.fValue;
     41     }
     42 
     43     const int64_t fValue;
     44 
     45     typedef Expression INHERITED;
     46 };
     47 
     48 } // namespace
     49 
     50 #endif
     51