| 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 |
|
| 26 |
FunctionReference(const Context& context, Position pos, |
| 27 |
const FunctionDeclaration* overloadChain) |
| 28 |
: INHERITED(pos, kIRNodeKind, context.fTypes.fInvalid.get()) |
| 29 |
, fOverloadChain(overloadChain) {} |
| 30 |
|
| 31 |
const FunctionDeclaration* overloadChain() const { |
| 32 |
return fOverloadChain; |
| 33 |
} |
| 34 |
|
| 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 |
|
| 40 |
std::string description(OperatorPrecedence) const override { |
| 41 |
return "<function>"; |
| 42 |
} |
| 43 |
|
| 44 |
private: |
| 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 |