4#include <unordered_map>
18 friend class SymbolTable;
21 const std::string * s;
23 explicit SymbolStr(
const std::string & symbol): s(&symbol) {}
26 bool operator == (std::string_view s2)
const
31 operator const std::string & ()
const
36 operator const std::string_view ()
const
41 friend std::ostream & operator <<(std::ostream & os,
const SymbolStr & symbol);
51 friend class SymbolTable;
56 explicit Symbol(uint32_t
id): id(
id) {}
61 explicit operator bool()
const {
return id > 0; }
63 bool operator<(
const Symbol other)
const {
return id < other.id; }
64 bool operator==(
const Symbol other)
const {
return id == other.id; }
65 bool operator!=(
const Symbol other)
const {
return id != other.id; }
75 std::unordered_map<std::string_view, std::pair<const std::string *, uint32_t>> symbols;
90 auto it = symbols.find(s);
91 if (it != symbols.end())
return Symbol(it->second.second + 1);
93 const auto & [rawSym, idx] = store.add(std::string(s));
94 symbols.emplace(rawSym, std::make_pair(&rawSym, idx));
100 if (s.id == 0 || s.id > store.size())
110 size_t totalSize()
const;
113 void dump(T callback)
const
115 store.forEach(callback);
Definition chunked-vector.hh:21
Definition symbol-table.hh:17
Definition symbol-table.hh:73
Symbol create(std::string_view s)
Definition symbol-table.hh:83
Definition symbol-table.hh:50