IdentifierTable.h 789 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DeprecatedFlyString.h>
  8. #include <AK/DistinctNumeric.h>
  9. #include <AK/Vector.h>
  10. namespace JS::Bytecode {
  11. struct IdentifierTableIndex {
  12. bool is_valid() const { return value != NumericLimits<u32>::max(); }
  13. u32 value { 0 };
  14. };
  15. class IdentifierTable {
  16. AK_MAKE_NONMOVABLE(IdentifierTable);
  17. AK_MAKE_NONCOPYABLE(IdentifierTable);
  18. public:
  19. IdentifierTable() = default;
  20. IdentifierTableIndex insert(DeprecatedFlyString);
  21. DeprecatedFlyString const& get(IdentifierTableIndex) const;
  22. void dump() const;
  23. bool is_empty() const { return m_identifiers.is_empty(); }
  24. private:
  25. Vector<DeprecatedFlyString> m_identifiers;
  26. };
  27. }