2021-10-24 15:34:30 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
2021-10-24 15:34:30 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/DistinctNumeric.h>
|
2025-08-02 19:27:29 -04:00
|
|
|
#include <AK/Utf16FlyString.h>
|
2021-10-24 15:34:30 +02:00
|
|
|
#include <AK/Vector.h>
|
|
|
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
|
2024-05-06 10:12:02 +02:00
|
|
|
struct IdentifierTableIndex {
|
2025-03-27 14:59:34 +00:00
|
|
|
static constexpr u32 invalid = 0xffffffffu;
|
|
|
|
|
bool is_valid() const { return value != invalid; }
|
2024-05-06 10:12:02 +02:00
|
|
|
u32 value { 0 };
|
|
|
|
|
};
|
2021-10-24 15:34:30 +02:00
|
|
|
|
2025-07-19 10:41:08 -07:00
|
|
|
class IdentifierTable {
|
2021-10-24 15:34:30 +02:00
|
|
|
AK_MAKE_NONMOVABLE(IdentifierTable);
|
|
|
|
|
AK_MAKE_NONCOPYABLE(IdentifierTable);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
IdentifierTable() = default;
|
|
|
|
|
|
2025-08-02 19:27:29 -04:00
|
|
|
IdentifierTableIndex insert(Utf16FlyString);
|
|
|
|
|
Utf16FlyString const& get(IdentifierTableIndex) const;
|
2021-10-24 15:34:30 +02:00
|
|
|
void dump() const;
|
|
|
|
|
bool is_empty() const { return m_identifiers.is_empty(); }
|
|
|
|
|
|
2025-10-07 16:47:41 +02:00
|
|
|
ReadonlySpan<Utf16FlyString const> identifiers() const { return m_identifiers; }
|
|
|
|
|
|
2021-10-24 15:34:30 +02:00
|
|
|
private:
|
2025-08-02 19:27:29 -04:00
|
|
|
Vector<Utf16FlyString> m_identifiers;
|
2021-10-24 15:34:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
2025-03-27 14:59:34 +00:00
|
|
|
|
|
|
|
|
namespace AK {
|
2025-05-13 07:06:33 -04:00
|
|
|
|
2025-03-27 14:59:34 +00:00
|
|
|
template<>
|
2026-03-18 20:43:56 +01:00
|
|
|
struct SentinelOptionalTraits<JS::Bytecode::IdentifierTableIndex> {
|
|
|
|
|
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(); }
|
|
|
|
|
};
|
2025-03-27 14:59:34 +00:00
|
|
|
|
2026-03-18 20:43:56 +01:00
|
|
|
template<>
|
|
|
|
|
class Optional<JS::Bytecode::IdentifierTableIndex> : public SentinelOptional<JS::Bytecode::IdentifierTableIndex> {
|
2025-03-27 14:59:34 +00:00
|
|
|
public:
|
2026-03-18 20:43:56 +01:00
|
|
|
using SentinelOptional::SentinelOptional;
|
2025-03-27 14:59:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|