SkSLForStatement.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_FORSTATEMENT
  8. #define SKSL_FORSTATEMENT
  9. #include "src/sksl/ir/SkSLExpression.h"
  10. #include "src/sksl/ir/SkSLStatement.h"
  11. #include "src/sksl/ir/SkSLSymbolTable.h"
  12. namespace SkSL {
  13. /**
  14. * A 'for' statement.
  15. */
  16. struct ForStatement : public Statement {
  17. ForStatement(int offset, std::unique_ptr<Statement> initializer,
  18. std::unique_ptr<Expression> test, std::unique_ptr<Expression> next,
  19. std::unique_ptr<Statement> statement, std::shared_ptr<SymbolTable> symbols)
  20. : INHERITED(offset, kFor_Kind)
  21. , fSymbols(symbols)
  22. , fInitializer(std::move(initializer))
  23. , fTest(std::move(test))
  24. , fNext(std::move(next))
  25. , fStatement(std::move(statement)) {}
  26. std::unique_ptr<Statement> clone() const override {
  27. return std::unique_ptr<Statement>(new ForStatement(fOffset, fInitializer->clone(),
  28. fTest->clone(), fNext->clone(),
  29. fStatement->clone(), fSymbols));
  30. }
  31. String description() const override {
  32. String result("for (");
  33. if (fInitializer) {
  34. result += fInitializer->description();
  35. }
  36. result += " ";
  37. if (fTest) {
  38. result += fTest->description();
  39. }
  40. result += "; ";
  41. if (fNext) {
  42. result += fNext->description();
  43. }
  44. result += ") " + fStatement->description();
  45. return result;
  46. }
  47. // it's important to keep fSymbols defined first (and thus destroyed last) because destroying
  48. // the other fields can update symbol reference counts
  49. const std::shared_ptr<SymbolTable> fSymbols;
  50. std::unique_ptr<Statement> fInitializer;
  51. std::unique_ptr<Expression> fTest;
  52. std::unique_ptr<Expression> fNext;
  53. std::unique_ptr<Statement> fStatement;
  54. typedef Statement INHERITED;
  55. };
  56. } // namespace
  57. #endif