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 8 #ifndef SKSL_FUNCTIONCALL 9 #define SKSL_FUNCTIONCALL 10 11 #include "src/sksl/ir/SkSLExpression.h" 12 #include "src/sksl/ir/SkSLFunctionDeclaration.h" 13 14 namespace SkSL { 15 16 /** 17 * A function invocation. 18 */ 19 struct FunctionCall : public Expression { FunctionCallFunctionCall20 FunctionCall(int offset, const Type& type, const FunctionDeclaration& function, 21 std::vector<std::unique_ptr<Expression>> arguments) 22 : INHERITED(offset, kFunctionCall_Kind, type) 23 , fFunction(std::move(function)) 24 , fArguments(std::move(arguments)) {} 25 hasPropertyFunctionCall26 bool hasProperty(Property property) const override { 27 if (property == Property::kSideEffects && (fFunction.fModifiers.fFlags & 28 Modifiers::kHasSideEffects_Flag)) { 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 cloneFunctionCall39 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 FunctionCall(fOffset, fType, fFunction, 45 std::move(cloned))); 46 } 47 48 #ifdef SK_DEBUG descriptionFunctionCall49 String description() const override { 50 String result = String(fFunction.fName) + "("; 51 String separator; 52 for (size_t i = 0; i < fArguments.size(); i++) { 53 result += separator; 54 result += fArguments[i]->description(); 55 separator = ", "; 56 } 57 result += ")"; 58 return result; 59 } 60 #endif 61 62 const FunctionDeclaration& fFunction; 63 std::vector<std::unique_ptr<Expression>> fArguments; 64 65 typedef Expression INHERITED; 66 }; 67 68 } // namespace 69 70 #endif 71