2023-08-31 19:25:00 +00:00
|
|
|
#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;
|
2023-08-31 19:25:00 +00:00
|
|
|
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();
|
|
|
|
|
2023-08-31 19:25:00 +00:00
|
|
|
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-08-31 19:25:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static int addr;
|
2023-08-31 23:22:51 +00:00
|
|
|
std::vector<SymEntry> m_entries;
|
2023-08-31 19:25:00 +00:00
|
|
|
int m_scope = 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|