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