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