1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2021 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef SKSL_METHODREFERENCE 9cb93a386Sopenharmony_ci#define SKSL_METHODREFERENCE 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "src/sksl/SkSLContext.h" 12cb93a386Sopenharmony_ci#include "src/sksl/ir/SkSLExpression.h" 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_cinamespace SkSL { 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ciclass FunctionDeclaration; 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_ci/** 19cb93a386Sopenharmony_ci * An identifier referring to a method name, along with an instance for the call. 20cb93a386Sopenharmony_ci * This is an intermediate value: MethodReferences are always eventually replaced by FunctionCalls 21cb93a386Sopenharmony_ci * in valid programs. 22cb93a386Sopenharmony_ci * 23cb93a386Sopenharmony_ci * Method calls are only supported on effect-child types, and they all resolve to intrinsics 24cb93a386Sopenharmony_ci * prefixed with '$', and taking the 'self' object as the last parameter. For example: 25cb93a386Sopenharmony_ci * 26cb93a386Sopenharmony_ci * uniform shader child; 27cb93a386Sopenharmony_ci * ... 28cb93a386Sopenharmony_ci * child.eval(xy) --> $eval(xy, child) 29cb93a386Sopenharmony_ci */ 30cb93a386Sopenharmony_ciclass MethodReference final : public Expression { 31cb93a386Sopenharmony_cipublic: 32cb93a386Sopenharmony_ci inline static constexpr Kind kExpressionKind = Kind::kMethodReference; 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ci MethodReference(const Context& context, 35cb93a386Sopenharmony_ci int line, 36cb93a386Sopenharmony_ci std::unique_ptr<Expression> self, 37cb93a386Sopenharmony_ci std::vector<const FunctionDeclaration*> functions) 38cb93a386Sopenharmony_ci : INHERITED(line, kExpressionKind, context.fTypes.fInvalid.get()) 39cb93a386Sopenharmony_ci , fSelf(std::move(self)) 40cb93a386Sopenharmony_ci , fFunctions(std::move(functions)) {} 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_ci std::unique_ptr<Expression>& self() { return fSelf; } 43cb93a386Sopenharmony_ci const std::unique_ptr<Expression>& self() const { return fSelf; } 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_ci const std::vector<const FunctionDeclaration*>& functions() const { return fFunctions; } 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ci bool hasProperty(Property property) const override { return false; } 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ci std::unique_ptr<Expression> clone() const override { 50cb93a386Sopenharmony_ci return std::unique_ptr<Expression>(new MethodReference( 51cb93a386Sopenharmony_ci fLine, this->self()->clone(), this->functions(), &this->type())); 52cb93a386Sopenharmony_ci } 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_ci String description() const override { 55cb93a386Sopenharmony_ci return String("<method>"); 56cb93a386Sopenharmony_ci } 57cb93a386Sopenharmony_ci 58cb93a386Sopenharmony_ciprivate: 59cb93a386Sopenharmony_ci MethodReference(int line, 60cb93a386Sopenharmony_ci std::unique_ptr<Expression> self, 61cb93a386Sopenharmony_ci std::vector<const FunctionDeclaration*> functions, 62cb93a386Sopenharmony_ci const Type* type) 63cb93a386Sopenharmony_ci : INHERITED(line, kExpressionKind, type) 64cb93a386Sopenharmony_ci , fSelf(std::move(self)) 65cb93a386Sopenharmony_ci , fFunctions(std::move(functions)) {} 66cb93a386Sopenharmony_ci 67cb93a386Sopenharmony_ci std::unique_ptr<Expression> fSelf; 68cb93a386Sopenharmony_ci std::vector<const FunctionDeclaration*> fFunctions; 69cb93a386Sopenharmony_ci 70cb93a386Sopenharmony_ci using INHERITED = Expression; 71cb93a386Sopenharmony_ci}; 72cb93a386Sopenharmony_ci 73cb93a386Sopenharmony_ci} // namespace SkSL 74cb93a386Sopenharmony_ci 75cb93a386Sopenharmony_ci#endif 76