/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace JS::Bytecode { struct IdentifierTableIndex { static constexpr u32 invalid = 0xffffffffu; bool is_valid() const { return value != invalid; } u32 value { 0 }; }; class IdentifierTable { AK_MAKE_NONMOVABLE(IdentifierTable); AK_MAKE_NONCOPYABLE(IdentifierTable); public: IdentifierTable() = default; IdentifierTableIndex insert(Utf16FlyString); Utf16FlyString const& get(IdentifierTableIndex) const; void dump() const; bool is_empty() const { return m_identifiers.is_empty(); } ReadonlySpan identifiers() const { return m_identifiers; } private: Vector m_identifiers; }; } namespace AK { template<> struct SentinelOptionalTraits { static constexpr JS::Bytecode::IdentifierTableIndex sentinel_value() { return { JS::Bytecode::IdentifierTableIndex::invalid }; } static constexpr bool is_sentinel(JS::Bytecode::IdentifierTableIndex const& value) { return !value.is_valid(); } }; template<> class Optional : public SentinelOptional { public: using SentinelOptional::SentinelOptional; }; }