• 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_ARRAY_CAST
9 #define SKSL_CONSTRUCTOR_ARRAY_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 typecasting of an array. Arrays cannot be directly casted in SkSL (or GLSL), but
21  * type narrowing can cause an array to be implicitly casted. For instance, the expression
22  * `myHalf2Array == float[2](a, b)` should be allowed when narrowing conversions are enabled; this
23  * constructor allows the necessary array-type conversion to be represented in IR.
24  *
25  * These always contain exactly 1 array of matching size, and are never constant.
26  */
27 class ConstructorArrayCast final : public SingleArgumentConstructor {
28 public:
29     inline static constexpr Kind kExpressionKind = Kind::kConstructorArrayCast;
30 
ConstructorArrayCast(int line,const Type & type,std::unique_ptr<Expression> arg)31     ConstructorArrayCast(int line, const Type& type, std::unique_ptr<Expression> arg)
32         : INHERITED(line, kExpressionKind, &type, std::move(arg)) {}
33 
34     static std::unique_ptr<Expression> Make(const Context& context,
35                                             int line,
36                                             const Type& type,
37                                             std::unique_ptr<Expression> arg);
38 
isCompileTimeConstant()39     bool isCompileTimeConstant() const override {
40         // If this were a compile-time constant, we would have made a ConstructorArray instead.
41         return false;
42     }
43 
clone()44     std::unique_ptr<Expression> clone() const override {
45         return std::make_unique<ConstructorArrayCast>(fLine, this->type(), argument()->clone());
46     }
47 
48 private:
49     using INHERITED = SingleArgumentConstructor;
50 };
51 
52 }  // namespace SkSL
53 
54 #endif
55