2 * Copyright 2021 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "src/sksl/SkSLContext.h"
9 #include "src/sksl/ir/SkSLChildCall.h"
13 bool ChildCall::hasProperty(Property property) const {
14 for (const auto& arg : this->arguments()) {
15 if (arg->hasProperty(property)) {
22 std::unique_ptr<Expression> ChildCall::clone(Position pos) const {
23 return std::make_unique<ChildCall>(pos, &this->type(), &this->child(),
24 this->arguments().clone());
27 std::string ChildCall::description() const {
28 std::string result = std::string(this->child().name()) + ".eval(";
29 std::string separator;
30 for (const std::unique_ptr<Expression>& arg : this->arguments()) {
32 result += arg->description();
39 [[maybe_unused]] static bool call_signature_is_valid(const Context& context,
40 const Variable& child,
41 const ExpressionArray& arguments) {
42 const Type* half4 = context.fTypes.fHalf4.get();
43 const Type* float2 = context.fTypes.fFloat2.get();
45 auto params = [&]() -> SkSTArray<2, const Type*> {
46 switch (child.type().typeKind()) {
47 case Type::TypeKind::kBlender: return { half4, half4 };
48 case Type::TypeKind::kColorFilter: return { half4 };
49 case Type::TypeKind::kShader: return { float2 };
55 if (params.size() != arguments.size()) {
58 for (size_t i = 0; i < arguments.size(); i++) {
59 if (!arguments[i]->type().matches(*params[i])) {
66 std::unique_ptr<Expression> ChildCall::Make(const Context& context,
68 const Type* returnType,
69 const Variable& child,
70 ExpressionArray arguments) {
71 SkASSERT(call_signature_is_valid(context, child, arguments));
72 return std::make_unique<ChildCall>(pos, returnType, &child, std::move(arguments));