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 8 #ifndef SKSL_EXTERNALFUNCTIONCALL 9 #define SKSL_EXTERNALFUNCTIONCALL 10 11 #include "include/private/SkTArray.h" 12 #include "src/sksl/ir/SkSLExpression.h" 13 #include "src/sksl/ir/SkSLExternalFunction.h" 14 #include "src/sksl/ir/SkSLFunctionDeclaration.h" 15 16 namespace SkSL { 17 18 /** 19 * An external function invocation. 20 */ 21 class ExternalFunctionCall final : public Expression { 22 public: 23 inline static constexpr Kind kExpressionKind = Kind::kExternalFunctionCall; 24 ExternalFunctionCall(int line,const ExternalFunction * function,ExpressionArray arguments)25 ExternalFunctionCall(int line, const ExternalFunction* function, ExpressionArray arguments) 26 : INHERITED(line, kExpressionKind, &function->type()) 27 , fFunction(*function) 28 , fArguments(std::move(arguments)) {} 29 arguments()30 ExpressionArray& arguments() { 31 return fArguments; 32 } 33 arguments()34 const ExpressionArray& arguments() const { 35 return fArguments; 36 } 37 function()38 const ExternalFunction& function() const { 39 return fFunction; 40 } 41 hasProperty(Property property)42 bool hasProperty(Property property) const override { 43 if (property == Property::kSideEffects) { 44 return true; 45 } 46 for (const auto& arg : this->arguments()) { 47 if (arg->hasProperty(property)) { 48 return true; 49 } 50 } 51 return false; 52 } 53 clone()54 std::unique_ptr<Expression> clone() const override { 55 ExpressionArray cloned; 56 cloned.reserve_back(this->arguments().size()); 57 for (const auto& arg : this->arguments()) { 58 cloned.push_back(arg->clone()); 59 } 60 return std::make_unique<ExternalFunctionCall>(fLine, &this->function(), 61 std::move(cloned)); 62 } 63 description()64 String description() const override { 65 String result = String(this->function().name()) + "("; 66 String separator; 67 for (const std::unique_ptr<Expression>& arg : this->arguments()) { 68 result += separator; 69 result += arg->description(); 70 separator = ", "; 71 } 72 result += ")"; 73 return result; 74 } 75 76 private: 77 const ExternalFunction& fFunction; 78 ExpressionArray fArguments; 79 80 using INHERITED = Expression; 81 }; 82 83 } // namespace SkSL 84 85 #endif 86