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 "include/private/SkTArray.h" 12 #include "src/sksl/ir/SkSLExpression.h" 13 #include "src/sksl/ir/SkSLFunctionDeclaration.h" 14 15 namespace SkSL { 16 17 /** 18 * A function invocation. 19 */ 20 class FunctionCall final : public Expression { 21 public: 22 inline static constexpr Kind kExpressionKind = Kind::kFunctionCall; 23 FunctionCall(int line,const Type * type,const FunctionDeclaration * function,ExpressionArray arguments)24 FunctionCall(int line, const Type* type, const FunctionDeclaration* function, 25 ExpressionArray arguments) 26 : INHERITED(line, kExpressionKind, type) 27 , fFunction(*function) 28 , fArguments(std::move(arguments)) {} 29 30 // Resolves generic types, performs type conversion on arguments, determines return type, and 31 // reports errors via the ErrorReporter. 32 static std::unique_ptr<Expression> Convert(const Context& context, 33 int line, 34 const FunctionDeclaration& function, 35 ExpressionArray arguments); 36 37 static std::unique_ptr<Expression> Convert(const Context& context, 38 int line, 39 std::unique_ptr<Expression> functionValue, 40 ExpressionArray arguments); 41 42 // Creates the function call; reports errors via ASSERT. 43 static std::unique_ptr<Expression> Make(const Context& context, 44 int line, 45 const Type* returnType, 46 const FunctionDeclaration& function, 47 ExpressionArray arguments); 48 49 static const FunctionDeclaration* FindBestFunctionForCall( 50 const Context& context, 51 const std::vector<const FunctionDeclaration*>& functions, 52 const ExpressionArray& arguments); 53 function()54 const FunctionDeclaration& function() const { 55 return fFunction; 56 } 57 arguments()58 ExpressionArray& arguments() { 59 return fArguments; 60 } 61 arguments()62 const ExpressionArray& arguments() const { 63 return fArguments; 64 } 65 66 bool hasProperty(Property property) const override; 67 68 std::unique_ptr<Expression> clone() const override; 69 70 std::string description() const override; 71 72 private: 73 static CoercionCost CallCost(const Context& context, 74 const FunctionDeclaration& function, 75 const ExpressionArray& arguments); 76 77 const FunctionDeclaration& fFunction; 78 ExpressionArray fArguments; 79 80 using INHERITED = Expression; 81 }; 82 83 } // namespace SkSL 84 85 #endif 86