SkSLBoolLiteral.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef SKSL_BOOLLITERAL
  8. #define SKSL_BOOLLITERAL
  9. #include "src/sksl/SkSLContext.h"
  10. #include "src/sksl/ir/SkSLExpression.h"
  11. namespace SkSL {
  12. /**
  13. * Represents 'true' or 'false'.
  14. */
  15. struct BoolLiteral : public Expression {
  16. BoolLiteral(const Context& context, int offset, bool value)
  17. : INHERITED(offset, kBoolLiteral_Kind, *context.fBool_Type)
  18. , fValue(value) {}
  19. String description() const override {
  20. return String(fValue ? "true" : "false");
  21. }
  22. bool hasSideEffects() const override {
  23. return false;
  24. }
  25. bool isConstant() const override {
  26. return true;
  27. }
  28. bool compareConstant(const Context& context, const Expression& other) const override {
  29. BoolLiteral& b = (BoolLiteral&) other;
  30. return fValue == b.fValue;
  31. }
  32. std::unique_ptr<Expression> clone() const override {
  33. return std::unique_ptr<Expression>(new BoolLiteral(fOffset, fValue, &fType));
  34. }
  35. const bool fValue;
  36. typedef Expression INHERITED;
  37. private:
  38. BoolLiteral(int offset, bool value, const Type* type)
  39. : INHERITED(offset, kBoolLiteral_Kind, *type)
  40. , fValue(value) {}
  41. };
  42. } // namespace
  43. #endif