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 <memory> 12 13 #include "include/private/SkSLProgramElement.h" 14 #include "src/sksl/ir/SkSLSymbolTable.h" 15 #include "src/sksl/ir/SkSLType.h" 16 17 namespace SkSL { 18 19 /** 20 * A struct at global scope, as in: 21 * 22 * struct RenderData { 23 * float3 color; 24 * bool highQuality; 25 * }; 26 */ 27 class StructDefinition final : public ProgramElement { 28 public: 29 inline static constexpr Kind kProgramElementKind = Kind::kStructDefinition; 30 StructDefinition(int line,const Type & type)31 StructDefinition(int line, const Type& type) 32 : INHERITED(line, kProgramElementKind) 33 , fType(&type) {} 34 type()35 const Type& type() const { 36 return *fType; 37 } 38 clone()39 std::unique_ptr<ProgramElement> clone() const override { 40 return std::make_unique<StructDefinition>(fLine, this->type()); 41 } 42 description()43 String description() const override { 44 String s = "struct "; 45 s += this->type().name(); 46 s += " { "; 47 for (const auto& f : this->type().fields()) { 48 s += f.fModifiers.description(); 49 s += f.fType->description(); 50 s += " "; 51 s += f.fName; 52 s += "; "; 53 } 54 s += "};"; 55 return s; 56 } 57 58 private: 59 const Type* fType = nullptr; 60 61 using INHERITED = ProgramElement; 62 }; 63 64 } // namespace SkSL 65 66 #endif 67