This repository has been archived on 2023-09-10. You can view files and clone it, but cannot push or open issues/pull-requests.
2023-09-09 22:03:28 +00:00
|
|
|
#ifndef jk_SYMTABLE_HPP
|
|
|
|
#define jk_SYMTABLE_HPP
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
#include "Type.hpp"
|
|
|
|
#include "Logger.hpp"
|
|
|
|
|
|
|
|
namespace jk
|
|
|
|
{
|
|
|
|
struct Sym {
|
|
|
|
std::string name;
|
|
|
|
std::shared_ptr<Type> type;
|
|
|
|
Loc loc;
|
|
|
|
bool is_global = false;
|
|
|
|
size_t addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
JK_ERROR(symbolic_error);
|
|
|
|
|
|
|
|
class SymTable
|
|
|
|
{
|
|
|
|
public:
|
2023-09-10 07:59:51 +00:00
|
|
|
explicit SymTable(Logger& logger,
|
|
|
|
std::shared_ptr<SymTable> parent=nullptr);
|
|
|
|
|
2023-09-09 22:03:28 +00:00
|
|
|
virtual ~SymTable();
|
|
|
|
|
|
|
|
size_t declare(std::string const& name,
|
|
|
|
std::shared_ptr<Type> type,
|
|
|
|
Loc const& loc);
|
|
|
|
|
|
|
|
size_t declare_global(std::string const& name,
|
|
|
|
std::shared_ptr<Type> type,
|
|
|
|
Loc const& loc);
|
|
|
|
|
|
|
|
std::optional<Sym> find(std::string const& name) const;
|
2023-09-10 07:59:51 +00:00
|
|
|
std::optional<Sym> find_local(std::string const& name) const;
|
2023-09-09 22:03:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Logger& m_logger;
|
2023-09-10 07:59:51 +00:00
|
|
|
std::shared_ptr<SymTable> m_parent;
|
2023-09-09 22:03:28 +00:00
|
|
|
std::vector<Sym> m_syms;
|
|
|
|
size_t m_addr = 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|