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 "src/sksl/SkSLExternalValue.h" 12 #include "src/sksl/ir/SkSLExpression.h" 13 #include "src/sksl/ir/SkSLFunctionDeclaration.h" 14 15 namespace SkSL { 16 17 /** 18 * An external function invocation. 19 */ 20 struct ExternalFunctionCall : public Expression { ExternalFunctionCallExternalFunctionCall21 ExternalFunctionCall(int offset, const Type& type, ExternalValue* function, 22 std::vector<std::unique_ptr<Expression>> arguments) 23 : INHERITED(offset, kExternalFunctionCall_Kind, type) 24 , fFunction(function) 25 , fArguments(std::move(arguments)) {} 26 hasPropertyExternalFunctionCall27 bool hasProperty(Property property) const override { 28 if (property == Property::kSideEffects) { 29 return true; 30 } 31 for (const auto& arg : fArguments) { 32 if (arg->hasProperty(property)) { 33 return true; 34 } 35 } 36 return false; 37 } 38 cloneExternalFunctionCall39 std::unique_ptr<Expression> clone() const override { 40 std::vector<std::unique_ptr<Expression>> cloned; 41 for (const auto& arg : fArguments) { 42 cloned.push_back(arg->clone()); 43 } 44 return std::unique_ptr<Expression>(new ExternalFunctionCall(fOffset, 45 fType, 46 fFunction, 47 std::move(cloned))); 48 } 49 50 #ifdef SK_DEBUG descriptionExternalFunctionCall51 String description() const override { 52 String result = String(fFunction->fName) + "("; 53 String separator; 54 for (size_t i = 0; i < fArguments.size(); i++) { 55 result += separator; 56 result += fArguments[i]->description(); 57 separator = ", "; 58 } 59 result += ")"; 60 return result; 61 } 62 #endif 63 64 ExternalValue* fFunction; 65 std::vector<std::unique_ptr<Expression>> fArguments; 66 67 typedef Expression INHERITED; 68 }; 69 70 } // namespace 71 72 #endif 73