SkSLExternalFunctionCall.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2019 Google LLC
  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_EXTERNALFUNCTIONCALL
  8. #define SKSL_EXTERNALFUNCTIONCALL
  9. #include "src/sksl/SkSLExternalValue.h"
  10. #include "src/sksl/ir/SkSLExpression.h"
  11. #include "src/sksl/ir/SkSLFunctionDeclaration.h"
  12. namespace SkSL {
  13. /**
  14. * An external function invocation.
  15. */
  16. struct ExternalFunctionCall : public Expression {
  17. ExternalFunctionCall(int offset, const Type& type, ExternalValue* function,
  18. std::vector<std::unique_ptr<Expression>> arguments)
  19. : INHERITED(offset, kExternalFunctionCall_Kind, type)
  20. , fFunction(function)
  21. , fArguments(std::move(arguments)) {}
  22. bool hasSideEffects() const override {
  23. return true;
  24. }
  25. std::unique_ptr<Expression> clone() const override {
  26. std::vector<std::unique_ptr<Expression>> cloned;
  27. for (const auto& arg : fArguments) {
  28. cloned.push_back(arg->clone());
  29. }
  30. return std::unique_ptr<Expression>(new ExternalFunctionCall(fOffset,
  31. fType,
  32. fFunction,
  33. std::move(cloned)));
  34. }
  35. String description() const override {
  36. String result = String(fFunction->fName) + "(";
  37. String separator;
  38. for (size_t i = 0; i < fArguments.size(); i++) {
  39. result += separator;
  40. result += fArguments[i]->description();
  41. separator = ", ";
  42. }
  43. result += ")";
  44. return result;
  45. }
  46. ExternalValue* fFunction;
  47. std::vector<std::unique_ptr<Expression>> fArguments;
  48. typedef Expression INHERITED;
  49. };
  50. } // namespace
  51. #endif