SkSLAppendStage.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2018 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_APPENDSTAGE
  8. #define SKSL_APPENDSTAGE
  9. #ifndef SKSL_STANDALONE
  10. #include "src/core/SkRasterPipeline.h"
  11. #include "src/sksl/SkSLContext.h"
  12. #include "src/sksl/ir/SkSLExpression.h"
  13. namespace SkSL {
  14. struct AppendStage : public Expression {
  15. AppendStage(const Context& context, int offset, SkRasterPipeline::StockStage stage,
  16. std::vector<std::unique_ptr<Expression>> arguments)
  17. : INHERITED(offset, kAppendStage_Kind, *context.fVoid_Type)
  18. , fStage(stage)
  19. , fArguments(std::move(arguments)) {}
  20. std::unique_ptr<Expression> clone() const override {
  21. std::vector<std::unique_ptr<Expression>> cloned;
  22. for (const auto& arg : fArguments) {
  23. cloned.push_back(arg->clone());
  24. }
  25. return std::unique_ptr<Expression>(new AppendStage(fOffset, fStage, std::move(cloned),
  26. &fType));
  27. }
  28. String description() const override {
  29. String result = "append(";
  30. const char* separator = "";
  31. for (const auto& a : fArguments) {
  32. result += separator;
  33. result += a->description();
  34. separator = ", ";
  35. }
  36. result += ")";
  37. return result;
  38. }
  39. bool hasSideEffects() const override {
  40. return true;
  41. }
  42. SkRasterPipeline::StockStage fStage;
  43. std::vector<std::unique_ptr<Expression>> fArguments;
  44. typedef Expression INHERITED;
  45. private:
  46. AppendStage(int offset, SkRasterPipeline::StockStage stage,
  47. std::vector<std::unique_ptr<Expression>> arguments, const Type* type)
  48. : INHERITED(offset, kAppendStage_Kind, *type)
  49. , fStage(stage)
  50. , fArguments(std::move(arguments)) {}
  51. };
  52. } // namespace
  53. #endif // SKSL_STANDALONE
  54. #endif // SKSL_APPENDSTAGE