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_CONSTRUCTOR_COMPOUND_CAST 9cb93a386Sopenharmony_ci#define SKSL_CONSTRUCTOR_COMPOUND_CAST 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "src/sksl/SkSLContext.h" 12cb93a386Sopenharmony_ci#include "src/sksl/ir/SkSLConstructor.h" 13cb93a386Sopenharmony_ci#include "src/sksl/ir/SkSLExpression.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ci#include <memory> 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_cinamespace SkSL { 18cb93a386Sopenharmony_ci 19cb93a386Sopenharmony_ci/** 20cb93a386Sopenharmony_ci * Represents the construction of a vector/matrix typecast, such as `half3(myInt3)` or 21cb93a386Sopenharmony_ci * `float4x4(myHalf4x4)`. Matrix resizes are done in ConstructorMatrixResize, not here. 22cb93a386Sopenharmony_ci * 23cb93a386Sopenharmony_ci * These always contain exactly 1 vector or matrix of matching size, and are never constant. 24cb93a386Sopenharmony_ci */ 25cb93a386Sopenharmony_ciclass ConstructorCompoundCast final : public SingleArgumentConstructor { 26cb93a386Sopenharmony_cipublic: 27cb93a386Sopenharmony_ci inline static constexpr Kind kExpressionKind = Kind::kConstructorCompoundCast; 28cb93a386Sopenharmony_ci 29cb93a386Sopenharmony_ci ConstructorCompoundCast(int line, const Type& type, std::unique_ptr<Expression> arg) 30cb93a386Sopenharmony_ci : INHERITED(line, kExpressionKind, &type, std::move(arg)) {} 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci static std::unique_ptr<Expression> Make(const Context& context, 33cb93a386Sopenharmony_ci int line, 34cb93a386Sopenharmony_ci const Type& type, 35cb93a386Sopenharmony_ci std::unique_ptr<Expression> arg); 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci bool isCompileTimeConstant() const override { 38cb93a386Sopenharmony_ci // If this were a compile-time constant, we would have made a ConstructorCompound instead. 39cb93a386Sopenharmony_ci return false; 40cb93a386Sopenharmony_ci } 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_ci std::unique_ptr<Expression> clone() const override { 43cb93a386Sopenharmony_ci return std::make_unique<ConstructorCompoundCast>(fLine, this->type(), argument()->clone()); 44cb93a386Sopenharmony_ci } 45cb93a386Sopenharmony_ci 46cb93a386Sopenharmony_ciprivate: 47cb93a386Sopenharmony_ci using INHERITED = SingleArgumentConstructor; 48cb93a386Sopenharmony_ci}; 49cb93a386Sopenharmony_ci 50cb93a386Sopenharmony_ci} // namespace SkSL 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_ci#endif 53