// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "src/tint/lang/wgsl/ast/loop_statement.h"

#include <utility>

#include "src/tint/lang/wgsl/program/program_builder.h"

TINT_INSTANTIATE_TYPEINFO(tint::ast::LoopStatement);

namespace tint::ast {

LoopStatement::LoopStatement(GenerationID pid,
                             NodeID nid,
                             const Source& src,
                             const BlockStatement* b,
                             const BlockStatement* cont,
                             utils::VectorRef<const ast::Attribute*> attrs)
    : Base(pid, nid, src), body(b), continuing(cont), attributes(std::move(attrs)) {
    TINT_ASSERT(AST, body);
    TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(AST, body, generation_id);
    TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(AST, continuing, generation_id);
    for (auto* attr : attributes) {
        TINT_ASSERT(AST, attr);
        TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(AST, attr, generation_id);
    }
}

LoopStatement::~LoopStatement() = default;

const LoopStatement* LoopStatement::Clone(CloneContext* ctx) const {
    // Clone arguments outside of create() call to have deterministic ordering
    auto src = ctx->Clone(source);
    auto* b = ctx->Clone(body);
    auto* cont = ctx->Clone(continuing);
    auto attrs = ctx->Clone(attributes);
    return ctx->dst->create<LoopStatement>(src, b, cont, std::move(attrs));
}

}  // namespace tint::ast
