40 lines
812 B
C++
40 lines
812 B
C++
#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);
|
|
|
|
SymEntry& declare_global(std::string const& name,
|
|
addr_t addr,
|
|
Loc const& loc);
|
|
|
|
std::optional<SymEntry> find(std::string const& name);
|
|
|
|
std::string string() const;
|
|
|
|
void enter_scope(std::shared_ptr<Node> parent=nullptr);
|
|
void leave_scope();
|
|
|
|
private:
|
|
std::vector<SymEntry> m_entries;
|
|
int m_scope;
|
|
std::vector<std::shared_ptr<Node>> m_parents;
|
|
};
|
|
}
|
|
|
|
#endif
|