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_STRUCT
9 #define SKSL_CONSTRUCTOR_STRUCT
10 
11 #include "src/sksl/ir/SkSLConstructor.h"
12 
13 namespace SkSL {
14 
15 /**
16  * Represents the construction of an struct object, such as "Color(red, green, blue, 1)".
17  */
18 class ConstructorStruct final : public MultiArgumentConstructor {
19 public:
20     static constexpr Kind kExpressionKind = Kind::kConstructorStruct;
21 
ConstructorStruct(int offset,const Type & type,ExpressionArray arguments)22     ConstructorStruct(int offset, const Type& type, ExpressionArray arguments)
23         : INHERITED(offset, kExpressionKind, &type, std::move(arguments)) {}
24 
25     // ConstructorStruct::Convert will typecheck and create struct-constructor expressions.
26     // Reports errors via the ErrorReporter; returns null on error.
27     static std::unique_ptr<Expression> Convert(const Context& context,
28                                                int offset,
29                                                const Type& type,
30                                                ExpressionArray args);
31 
32     // ConstructorStruct::Make creates struct-constructor expressions; errors reported via SkASSERT.
33     static std::unique_ptr<Expression> Make(const Context& context,
34                                             int offset,
35                                             const Type& type,
36                                             ExpressionArray args);
37 
clone()38     std::unique_ptr<Expression> clone() const override {
39         return std::make_unique<ConstructorStruct>(fOffset, this->type(), this->cloneArguments());
40     }
41 
42 private:
43     using INHERITED = MultiArgumentConstructor;
44 };
45 
46 }  // namespace SkSL
47 
48 #endif
49