1 /* 2 * Copyright 2020 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_STRUCTDEFINITION 9 #define SKSL_STRUCTDEFINITION 10 11 #include "include/private/base/SkTArray.h" 12 #include "src/sksl/SkSLPosition.h" 13 #include "src/sksl/ir/SkSLIRNode.h" 14 #include "src/sksl/ir/SkSLProgramElement.h" 15 #include "src/sksl/ir/SkSLType.h" // IWYU pragma: keep 16 17 #include <memory> 18 #include <string> 19 #include <string_view> 20 21 namespace SkSL { 22 23 class Context; 24 25 /** 26 * A struct at global scope, as in: 27 * 28 * struct RenderData { 29 * float3 color; 30 * bool highQuality; 31 * }; 32 */ 33 class StructDefinition final : public ProgramElement { 34 public: 35 inline static constexpr Kind kIRNodeKind = Kind::kStructDefinition; 36 StructDefinition(Position pos,const Type & type)37 StructDefinition(Position pos, const Type& type) 38 : INHERITED(pos, kIRNodeKind) 39 , fType(&type) {} 40 41 static std::unique_ptr<StructDefinition> Convert(const Context& context, 42 Position pos, 43 std::string_view name, 44 skia_private::TArray<Field> fields); 45 46 static std::unique_ptr<StructDefinition> Make(Position pos, const Type& type); 47 type()48 const Type& type() const { 49 return *fType; 50 } 51 52 std::string description() const override; 53 54 private: 55 const Type* fType = nullptr; 56 57 using INHERITED = ProgramElement; 58 }; 59 60 } // namespace SkSL 61 62 #endif 63