roza/lib/SymTable.hpp

47 lines
913 B
C++
Raw Normal View History

#ifndef roza_SYMTABLE_HPP
#define roza_SYMTABLE_HPP
#include "commons.hpp"
#include "Node.hpp"
namespace roza
{
struct SymEntry {
2023-08-31 23:22:51 +00:00
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();
2023-08-31 23:22:51 +00:00
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;
2023-08-31 23:22:51 +00:00
bool exists_in_scope(std::string const& name) const;
2023-09-01 20:38:12 +00:00
std::string string() const;
private:
2023-09-01 20:38:12 +00:00
int m_addr = 0;
2023-08-31 23:22:51 +00:00
std::vector<SymEntry> m_entries;
int m_scope = 0;
};
}
#endif