70 lines
1.3 KiB
C++
70 lines
1.3 KiB
C++
#include "SymTable.hpp"
|
|
|
|
namespace roza
|
|
{
|
|
/*static*/ int SymTable::addr = 0;
|
|
|
|
/*explicit*/ SymTable::SymTable()
|
|
{
|
|
}
|
|
|
|
/*explicit*/ SymTable::SymTable(SymTable const& sym_table)
|
|
{
|
|
m_scope = sym_table.m_scope;
|
|
|
|
for (auto const& entry: sym_table.m_entries)
|
|
{
|
|
m_entries[entry.first] = entry.second;
|
|
}
|
|
}
|
|
|
|
/*virtual*/ SymTable::~SymTable()
|
|
{
|
|
}
|
|
|
|
int SymTable::declare(std::string const& name, std::shared_ptr<Node> node)
|
|
{
|
|
assert(!exists(name));
|
|
|
|
m_entries.insert({name, SymEntry {
|
|
SymTable::addr++,
|
|
m_scope,
|
|
node,
|
|
false
|
|
}});
|
|
|
|
return SymTable::addr - 1;
|
|
}
|
|
|
|
int SymTable::declare_mut(std::string const& name, std::shared_ptr<Node> node)
|
|
{
|
|
assert(!exists(name));
|
|
|
|
m_entries.insert({name, SymEntry {
|
|
SymTable::addr++,
|
|
m_scope,
|
|
node,
|
|
true
|
|
}});
|
|
|
|
return SymTable::addr - 1;
|
|
}
|
|
|
|
SymEntry& SymTable::find(std::string const& name)
|
|
{
|
|
assert(exists(name));
|
|
return m_entries[name];
|
|
}
|
|
|
|
SymEntry const& SymTable::find(std::string const& name) const
|
|
{
|
|
assert(exists(name));
|
|
return m_entries.at(name);
|
|
}
|
|
|
|
bool SymTable::exists(std::string const& name) const
|
|
{
|
|
return m_entries.find(name) != std::end(m_entries);
|
|
}
|
|
}
|