1 /*
2 * Copyright 2023 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 #include "src/sksl/ir/SkSLStructDefinition.h"
9
10 #include "include/private/base/SkSpan_impl.h"
11 #include "src/sksl/SkSLContext.h"
12 #include "src/sksl/ir/SkSLLayout.h"
13 #include "src/sksl/ir/SkSLModifierFlags.h"
14 #include "src/sksl/ir/SkSLSymbolTable.h"
15 #include "src/sksl/ir/SkSLType.h"
16
17 #include <utility>
18
19 using namespace skia_private;
20
21 namespace SkSL {
22
Convert(const Context & context,Position pos,std::string_view name,TArray<Field> fields)23 std::unique_ptr<StructDefinition> StructDefinition::Convert(const Context& context,
24 Position pos,
25 std::string_view name,
26 TArray<Field> fields) {
27 std::unique_ptr<Type> ownedType = Type::MakeStructType(context, pos, name,
28 std::move(fields),
29 /*interfaceBlock=*/false);
30 const SkSL::Type* type = context.fSymbolTable->add(context, std::move(ownedType));
31 return StructDefinition::Make(pos, *type);
32 }
33
Make(Position pos,const Type & type)34 std::unique_ptr<StructDefinition> StructDefinition::Make(Position pos, const Type& type) {
35 return std::make_unique<SkSL::StructDefinition>(pos, type);
36 }
37
description() const38 std::string StructDefinition::description() const {
39 std::string s = "struct ";
40 s += this->type().name();
41 s += " { ";
42 for (const auto& f : this->type().fields()) {
43 s += f.fLayout.description();
44 s += f.fModifierFlags.description();
45 s += ' ';
46 s += f.fType->description();
47 s += ' ';
48 s += f.fName;
49 s += "; ";
50 }
51 s += "};";
52 return s;
53 }
54
55 } // namespace SkSL
56