// Copyright 2023 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.

#ifndef SRC_TINT_LANG_SPIRV_READER_AST_PARSER_ATTRIBUTES_H_
#define SRC_TINT_LANG_SPIRV_READER_AST_PARSER_ATTRIBUTES_H_

#include "src/tint/lang/core/builtin_value.h"
#include "src/tint/lang/wgsl/ast/attribute.h"
#include "src/tint/lang/wgsl/program/program_builder.h"
#include "src/tint/utils/containers/enum_set.h"
#include "src/tint/utils/containers/vector.h"

namespace tint::spirv::reader::ast_parser {

/// Attributes holds a vector of ast::Attribute pointers, and a enum-set of flags used to hold
/// additional metadata.
struct Attributes {
    /// Flags used by #flags.
    enum class Flags {
        kHasBuiltinSampleMask,
    };

    /// Adds the attributes and flags of @p other to this.
    /// @param other the other Attributes to combine into this
    void Add(const Attributes& other) {
        for (auto* attr : other.list) {
            list.Push(attr);
        }
        for (auto flag : other.flags) {
            flags.Add(flag);
        }
    }

    /// Adds the attribute @p attr to the list of attributes
    /// @param attr the attribute to add to this
    void Add(const ast::Attribute* attr) { list.Push(attr); }

    /// Adds the builtin to the attribute list, also marking any necessary flags
    /// @param builder the program builder
    /// @param source the source of the builtin attribute
    /// @param builtin the builtin attribute to add
    void Add(ProgramBuilder& builder, const Source& source, core::BuiltinValue builtin) {
        Add(builder.Builtin(source, builtin));
        if (builtin == core::BuiltinValue::kSampleMask) {
            flags.Add(Flags::kHasBuiltinSampleMask);
        }
    }

    /// @returns true if the attribute list contains an attribute with the type `T`.
    template <typename T>
    bool Has() const {
        return ast::HasAttribute<T>(list);
    }

    /// @returns the attribute with type `T` in the list, or nullptr if no attribute of the given
    /// type exists in list.
    template <typename T>
    const T* Get() const {
        return ast::GetAttribute<T>(list);
    }

    /// The attributes
    tint::Vector<const ast::Attribute*, 8> list;
    /// The additional metadata flags
    tint::EnumSet<Flags> flags;
};

}  // namespace tint::spirv::reader::ast_parser

#endif  // SRC_TINT_LANG_SPIRV_READER_AST_PARSER_ATTRIBUTES_H_
