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