SkSLIfStatement.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_IFSTATEMENT
  8. #define SKSL_IFSTATEMENT
  9. #include "src/sksl/ir/SkSLExpression.h"
  10. #include "src/sksl/ir/SkSLStatement.h"
  11. namespace SkSL {
  12. /**
  13. * An 'if' statement.
  14. */
  15. struct IfStatement : public Statement {
  16. IfStatement(int offset, bool isStatic, std::unique_ptr<Expression> test,
  17. std::unique_ptr<Statement> ifTrue, std::unique_ptr<Statement> ifFalse)
  18. : INHERITED(offset, kIf_Kind)
  19. , fIsStatic(isStatic)
  20. , fTest(std::move(test))
  21. , fIfTrue(std::move(ifTrue))
  22. , fIfFalse(std::move(ifFalse)) {}
  23. std::unique_ptr<Statement> clone() const override {
  24. return std::unique_ptr<Statement>(new IfStatement(fOffset, fIsStatic, fTest->clone(),
  25. fIfTrue->clone(), fIfFalse ? fIfFalse->clone() : nullptr));
  26. }
  27. String description() const override {
  28. String result;
  29. if (fIsStatic) {
  30. result += "@";
  31. }
  32. result += "if (" + fTest->description() + ") " + fIfTrue->description();
  33. if (fIfFalse) {
  34. result += " else " + fIfFalse->description();
  35. }
  36. return result;
  37. }
  38. bool fIsStatic;
  39. std::unique_ptr<Expression> fTest;
  40. std::unique_ptr<Statement> fIfTrue;
  41. // may be null
  42. std::unique_ptr<Statement> fIfFalse;
  43. typedef Statement INHERITED;
  44. };
  45. } // namespace
  46. #endif