| 1 |
/* |
| 2 |
* Copyright 2021 Google LLC |
| 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_METHODREFERENCE |
| 9 |
#define SKSL_METHODREFERENCE |
| 10 |
|
| 11 |
#include "src/sksl/SkSLBuiltinTypes.h" |
| 12 |
#include "src/sksl/SkSLContext.h" |
| 13 |
#include "src/sksl/ir/SkSLExpression.h" |
| 14 |
|
| 15 |
namespace SkSL { |
| 16 |
|
| 17 |
class FunctionDeclaration; |
| 18 |
|
| 19 |
/** |
| 20 |
* An identifier referring to a method name, along with an instance for the call. |
| 21 |
* This is an intermediate value: MethodReferences are always eventually replaced by FunctionCalls |
| 22 |
* in valid programs. |
| 23 |
* |
| 24 |
* Method calls are only supported on effect-child types, and they all resolve to intrinsics |
| 25 |
* prefixed with '$', and taking the 'self' object as the last parameter. For example: |
| 26 |
* |
| 27 |
* uniform shader child; |
| 28 |
* ... |
| 29 |
* child.eval(xy) --> $eval(xy, child) |
| 30 |
*/ |
| 31 |
class MethodReference final : public Expression { |
| 32 |
public: |
| 33 |
inline static constexpr Kind kIRNodeKind = Kind::kMethodReference; |
| 34 |
|
| 35 |
MethodReference(const Context& context, |
| 36 |
Position pos, |
| 37 |
std::unique_ptr<Expression> self, |
| 38 |
const FunctionDeclaration* overloadChain) |
| 39 |
: INHERITED(pos, kIRNodeKind, context.fTypes.fInvalid.get()) |
| 40 |
, fSelf(std::move(self)) |
| 41 |
, fOverloadChain(overloadChain) {} |
| 42 |
|
| 43 |
std::unique_ptr<Expression>& self() { return fSelf; } |
| 44 |
const std::unique_ptr<Expression>& self() const { return fSelf; } |
| 45 |
|
| 46 |
const FunctionDeclaration* overloadChain() const { return fOverloadChain; } |
| 47 |
|
| 48 |
std::unique_ptr<Expression> clone(Position pos) const override { |
| 49 |
return std::unique_ptr<Expression>(new MethodReference( |
| 50 |
pos, this->self()->clone(), this->overloadChain(), &this->type())); |
| 51 |
} |
| 52 |
|
| 53 |
std::string description(OperatorPrecedence) const override { |
| 54 |
return "<method>"; |
| 55 |
} |
| 56 |
|
| 57 |
private: |
| 58 |
MethodReference(Position pos, |
| 59 |
std::unique_ptr<Expression> self, |
| 60 |
const FunctionDeclaration* overloadChain, |
| 61 |
const Type* type) |
| 62 |
: INHERITED(pos, kIRNodeKind, type) |
| 63 |
, fSelf(std::move(self)) |
| 64 |
, fOverloadChain(overloadChain) {} |
| 65 |
|
| 66 |
std::unique_ptr<Expression> fSelf; |
| 67 |
const FunctionDeclaration* fOverloadChain; |
| 68 |
|
| 69 |
using INHERITED = Expression; |
| 70 |
}; |
| 71 |
|
| 72 |
} // namespace SkSL |
| 73 |
|
| 74 |
#endif |