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_member.h"
16
17 #include "src/program_builder.h"
18
19 TINT_INSTANTIATE_TYPEINFO(tint::ast::StructMember);
20
21 namespace tint {
22 namespace ast {
23
StructMember(ProgramID pid,const Source & src,const Symbol & sym,const ast::Type * ty,DecorationList decos)24 StructMember::StructMember(ProgramID pid,
25 const Source& src,
26 const Symbol& sym,
27 const ast::Type* ty,
28 DecorationList decos)
29 : Base(pid, src), symbol(sym), type(ty), decorations(std::move(decos)) {
30 TINT_ASSERT(AST, type);
31 TINT_ASSERT(AST, symbol.IsValid());
32 TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id);
33 for (auto* deco : decorations) {
34 TINT_ASSERT(AST, deco);
35 TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, deco, program_id);
36 }
37 }
38
39 StructMember::StructMember(StructMember&&) = default;
40
41 StructMember::~StructMember() = default;
42
Clone(CloneContext * ctx) const43 const StructMember* StructMember::Clone(CloneContext* ctx) const {
44 // Clone arguments outside of create() call to have deterministic ordering
45 auto src = ctx->Clone(source);
46 auto sym = ctx->Clone(symbol);
47 auto* ty = ctx->Clone(type);
48 auto decos = ctx->Clone(decorations);
49 return ctx->dst->create<StructMember>(src, sym, ty, decos);
50 }
51
52 } // namespace ast
53 } // namespace tint
54