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 function()49 const FunctionDeclaration& function() const { 50 return fFunction; 51 } 52 arguments()53 ExpressionArray& arguments() { 54 return fArguments; 55 } 56 arguments()57 const ExpressionArray& arguments() const { 58 return fArguments; 59 } 60 61 bool hasProperty(Property property) const override; 62 63 std::unique_ptr<Expression> clone() const override; 64 65 String description() const override; 66 67 private: 68 static CoercionCost CallCost(const Context& context, 69 const FunctionDeclaration& function, 70 const ExpressionArray& arguments); 71 72 static const FunctionDeclaration* FindBestFunctionForCall( 73 const Context& context, 74 const std::vector<const FunctionDeclaration*>& functions, 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