roza/lib/SymTable.hpp

40 lines
773 B
C++

#ifndef roza_SYMTABLE_HPP
#define roza_SYMTABLE_HPP
#include "commons.hpp"
#include "Node.hpp"
namespace roza
{
struct SymEntry {
int addr;
int scope;
std::shared_ptr<Node> node;
bool is_mut;
};
class SymTable
{
public:
explicit SymTable();
explicit SymTable(SymTable const& sym_table);
virtual ~SymTable();
int declare(std::string const& name, std::shared_ptr<Node> node);
int declare_mut(std::string const& name, std::shared_ptr<Node> node);
SymEntry& find(std::string const& name);
SymEntry const& find(std::string const& name) const;
bool exists(std::string const& name) const;
private:
static int addr;
std::unordered_map<std::string, SymEntry> m_entries;
int m_scope = 0;
};
}
#endif