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