roza/lib/SymTable.hpp

47 lines
913 B
C++

#ifndef roza_SYMTABLE_HPP
#define roza_SYMTABLE_HPP
#include "commons.hpp"
#include "Node.hpp"
namespace roza
{
struct SymEntry {
std::string name;
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();
void enter_scope();
void leave_scope();
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;
bool exists_in_scope(std::string const& name) const;
std::string string() const;
private:
int m_addr = 0;
std::vector<SymEntry> m_entries;
int m_scope = 0;
};
}
#endif