Debian Codegraph @

src/sksl/ir/SkSLFunctionCall.h

raw
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/SkSLDefines.h"
12 #include "src/sksl/SkSLPosition.h"
13 #include "src/sksl/ir/SkSLExpression.h"
14 #include "src/sksl/ir/SkSLIRNode.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
35 FunctionCall(Position pos,
36 const Type* type,
37 const FunctionDeclaration* function,
38 ExpressionArray arguments,
39 const FunctionCall* stablePointer)
40 : INHERITED(pos, kIRNodeKind, type)
41 , fFunction(*function)
42 , fArguments(std::move(arguments))
43 , fStablePointer(stablePointer ? stablePointer : this) {}
44
45 // Resolves generic types, performs type conversion on arguments, determines return type, and
46 // chooses a unique stable ID. Reports errors via the ErrorReporter.
47 static std::unique_ptr<Expression> Convert(const Context& context,
48 Position pos,
49 const FunctionDeclaration& function,
50 ExpressionArray arguments);
51
52 static std::unique_ptr<Expression> Convert(const Context& context,
53 Position pos,
54 std::unique_ptr<Expression> functionValue,
55 ExpressionArray arguments);
56
57 // Creates a function call with a given stable ID; reports errors via ASSERT.
58 static std::unique_ptr<Expression> Make(const Context& context,
59 Position pos,
60 const Type* returnType,
61 const FunctionDeclaration& function,
62 ExpressionArray arguments);
63
64 static const FunctionDeclaration* FindBestFunctionForCall(const Context& context,
65 const FunctionDeclaration* overloads,
66 const ExpressionArray& arguments);
67
68 const FunctionDeclaration& function() const {
69 return fFunction;
70 }
71
72 ExpressionArray& arguments() {
73 return fArguments;
74 }
75
76 const ExpressionArray& arguments() const {
77 return fArguments;
78 }
79
80 const FunctionCall* stablePointer() const {
81 return fStablePointer;
82 }
83
84 std::unique_ptr<Expression> clone(Position pos) const override;
85
86 std::string description(OperatorPrecedence) const override;
87
88 private:
89 const FunctionDeclaration& fFunction;
90 ExpressionArray fArguments;
91
92 // The stable pointer uniquely identifies this FunctionCall across an entire SkSL program.
93 // This allows us to clone() a FunctionCall but still find that call in a hash-map.
94 const FunctionCall* fStablePointer = nullptr;
95
96 using INHERITED = Expression;
97 };
98
99 } // namespace SkSL
100
101 #endif