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