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