fakir/src/SymTable.hpp

40 lines
812 B
C++
Raw Normal View History

2023-09-20 15:17:13 +00:00
#ifndef fk_SYMTABLE_HPP
#define fk_SYMTABLE_HPP
#include "commons.hpp"
#include "SymEntry.hpp"
namespace fk
{
FK_ERROR(symbol_error);
class SymTable
{
public:
explicit SymTable();
virtual ~SymTable();
SymEntry& declare_local(std::string const& name,
addr_t addr,
Loc const& loc);
2023-09-20 15:17:13 +00:00
SymEntry& declare_global(std::string const& name,
addr_t addr,
Loc const& loc);
2023-09-20 15:17:13 +00:00
std::optional<SymEntry> find(std::string const& name);
std::string string() const;
void enter_scope(std::shared_ptr<Node> parent=nullptr);
2023-09-21 13:59:46 +00:00
void leave_scope();
2023-09-20 15:17:13 +00:00
private:
std::vector<SymEntry> m_entries;
2023-09-21 13:59:46 +00:00
int m_scope;
std::vector<std::shared_ptr<Node>> m_parents;
2023-09-20 15:17:13 +00:00
};
}
#endif