• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/ast/struct.h"
16 
17 #include <string>
18 
19 #include "src/ast/struct_block_decoration.h"
20 #include "src/program_builder.h"
21 
22 TINT_INSTANTIATE_TYPEINFO(tint::ast::Struct);
23 
24 namespace tint {
25 namespace ast {
26 
Struct(ProgramID pid,const Source & src,Symbol n,StructMemberList m,DecorationList decos)27 Struct::Struct(ProgramID pid,
28                const Source& src,
29                Symbol n,
30                StructMemberList m,
31                DecorationList decos)
32     : Base(pid, src, n), members(std::move(m)), decorations(std::move(decos)) {
33   for (auto* mem : members) {
34     TINT_ASSERT(AST, mem);
35     TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, mem, program_id);
36   }
37   for (auto* deco : decorations) {
38     TINT_ASSERT(AST, deco);
39     TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id);
40   }
41 }
42 
43 Struct::Struct(Struct&&) = default;
44 
45 Struct::~Struct() = default;
46 
IsBlockDecorated() const47 bool Struct::IsBlockDecorated() const {
48   return HasDecoration<StructBlockDecoration>(decorations);
49 }
50 
Clone(CloneContext * ctx) const51 const Struct* Struct::Clone(CloneContext* ctx) const {
52   // Clone arguments outside of create() call to have deterministic ordering
53   auto src = ctx->Clone(source);
54   auto n = ctx->Clone(name);
55   auto mem = ctx->Clone(members);
56   auto decos = ctx->Clone(decorations);
57   return ctx->dst->create<Struct>(src, n, mem, decos);
58 }
59 
60 }  // namespace ast
61 }  // namespace tint
62