xref: /aosp_15_r20/external/skia/src/sksl/ir/SkSLFunctionReference.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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_FUNCTIONREFERENCE
9 #define SKSL_FUNCTIONREFERENCE
10 
11 #include "src/sksl/SkSLBuiltinTypes.h"
12 #include "src/sksl/SkSLContext.h"
13 #include "src/sksl/ir/SkSLExpression.h"
14 #include "src/sksl/ir/SkSLFunctionDeclaration.h"
15 
16 namespace SkSL {
17 
18 /**
19  * An identifier referring to a function name. This is an intermediate value: FunctionReferences are
20  * always eventually replaced by FunctionCalls in valid programs.
21  */
22 class FunctionReference final : public Expression {
23 public:
24     inline static constexpr Kind kIRNodeKind = Kind::kFunctionReference;
25 
FunctionReference(const Context & context,Position pos,const FunctionDeclaration * overloadChain)26     FunctionReference(const Context& context, Position pos,
27                       const FunctionDeclaration* overloadChain)
28         : INHERITED(pos, kIRNodeKind, context.fTypes.fInvalid.get())
29         , fOverloadChain(overloadChain) {}
30 
overloadChain()31     const FunctionDeclaration* overloadChain() const {
32         return fOverloadChain;
33     }
34 
clone(Position pos)35     std::unique_ptr<Expression> clone(Position pos) const override {
36         return std::unique_ptr<Expression>(new FunctionReference(pos, this->overloadChain(),
37                                                                  &this->type()));
38     }
39 
description(OperatorPrecedence)40     std::string description(OperatorPrecedence) const override {
41         return "<function>";
42     }
43 
44 private:
FunctionReference(Position pos,const FunctionDeclaration * overloadChain,const Type * type)45     FunctionReference(Position pos, const FunctionDeclaration* overloadChain, const Type* type)
46             : INHERITED(pos, kIRNodeKind, type)
47             , fOverloadChain(overloadChain) {}
48 
49     const FunctionDeclaration* fOverloadChain;
50 
51     using INHERITED = Expression;
52 };
53 
54 }  // namespace SkSL
55 
56 #endif
57