blob: 7c7631981faabc42ea29f4b22ea3e690b9a81e06 [file] [log] [blame]
Ryan Harrisondbc13af2022-02-21 15:19:07 +00001// 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/tint/ast/block_statement.h"
16
17#include "src/tint/program_builder.h"
18
19TINT_INSTANTIATE_TYPEINFO(tint::ast::BlockStatement);
20
dan sinclair34323ac2022-04-07 18:39:35 +000021namespace tint::ast {
Ryan Harrisondbc13af2022-02-21 15:19:07 +000022
Ben Clayton4a92a3c2022-07-18 20:50:02 +000023BlockStatement::BlockStatement(ProgramID pid,
24 NodeID nid,
25 const Source& src,
James Priced9f65962023-02-01 23:14:10 +000026 utils::VectorRef<const Statement*> stmts,
27 utils::VectorRef<const Attribute*> attrs)
28 : Base(pid, nid, src), statements(std::move(stmts)), attributes(attrs) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000029 for (auto* stmt : statements) {
30 TINT_ASSERT(AST, stmt);
31 TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, stmt, program_id);
32 }
James Priced9f65962023-02-01 23:14:10 +000033 for (auto* attr : attributes) {
34 TINT_ASSERT(AST, attr);
35 TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, attr, program_id);
36 }
Ryan Harrisondbc13af2022-02-21 15:19:07 +000037}
38
Ryan Harrisondbc13af2022-02-21 15:19:07 +000039BlockStatement::~BlockStatement() = default;
40
41const BlockStatement* BlockStatement::Clone(CloneContext* ctx) const {
dan sinclair41e4d9a2022-05-01 14:40:55 +000042 // Clone arguments outside of create() call to have deterministic ordering
43 auto src = ctx->Clone(source);
44 auto stmts = ctx->Clone(statements);
James Priced9f65962023-02-01 23:14:10 +000045 auto attrs = ctx->Clone(attributes);
46 return ctx->dst->create<BlockStatement>(src, std::move(stmts), std::move(attrs));
Ryan Harrisondbc13af2022-02-21 15:19:07 +000047}
48
dan sinclair34323ac2022-04-07 18:39:35 +000049} // namespace tint::ast