2024-05-01 10:39:18 +02:00
|
|
|
#include "elna/source/types.hpp"
|
|
|
|
#include "elna/source/symbol_table.hpp"
|
|
|
|
|
|
|
|
namespace elna::source
|
|
|
|
{
|
|
|
|
symbol_table::symbol_table(std::shared_ptr<symbol_table> scope)
|
|
|
|
: outer_scope(scope)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<info> symbol_table::lookup(const std::string& name)
|
|
|
|
{
|
|
|
|
auto entry = entries.find(name);
|
|
|
|
|
|
|
|
if (entry != entries.cend())
|
|
|
|
{
|
|
|
|
return entry->second;
|
|
|
|
}
|
|
|
|
if (this->outer_scope != nullptr)
|
|
|
|
{
|
|
|
|
return this->outer_scope->lookup(name);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void symbol_table::enter(const std::string& name, std::shared_ptr<info> entry)
|
|
|
|
{
|
|
|
|
entries.insert_or_assign(name, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<symbol_table> symbol_table::scope()
|
|
|
|
{
|
|
|
|
return this->outer_scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
info::~info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
info::info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
type_info::type_info(const class type& type)
|
|
|
|
: info(), m_type(std::make_shared<class type>(type))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
type_info::~type_info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<const class type> type_info::type() const noexcept
|
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:53:04 +02:00
|
|
|
typed_info::typed_info(std::shared_ptr<const class type> type)
|
|
|
|
: m_type(type)
|
2024-05-01 10:39:18 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:53:04 +02:00
|
|
|
typed_info::~typed_info()
|
2024-05-01 10:39:18 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:53:04 +02:00
|
|
|
std::shared_ptr<const class type> typed_info::type() const noexcept
|
2024-05-19 00:43:59 +02:00
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:53:04 +02:00
|
|
|
constant_info::constant_info(const std::shared_ptr<const class type> type, const std::int32_t value)
|
|
|
|
: typed_info(type), m_value(value)
|
2024-05-01 10:39:18 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:53:04 +02:00
|
|
|
std::int32_t constant_info::value() const noexcept
|
2024-05-01 10:39:18 +02:00
|
|
|
{
|
2024-06-05 19:53:04 +02:00
|
|
|
return m_value;
|
2024-05-01 10:39:18 +02:00
|
|
|
}
|
|
|
|
|
2024-06-05 19:53:04 +02:00
|
|
|
variable_info::variable_info(std::shared_ptr<const class type> type)
|
|
|
|
: typed_info(type)
|
2024-05-01 10:39:18 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
parameter_info::parameter_info(std::shared_ptr<const class type> type)
|
2024-06-05 19:53:04 +02:00
|
|
|
: typed_info(type)
|
2024-05-01 10:39:18 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-05-19 00:43:59 +02:00
|
|
|
intrinsic_info::intrinsic_info(const class procedure_type& type)
|
|
|
|
: m_type(std::make_shared<procedure_type>(type))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-05-01 10:39:18 +02:00
|
|
|
intrinsic_info::~intrinsic_info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-05-19 00:43:59 +02:00
|
|
|
std::shared_ptr<const class procedure_type> intrinsic_info::type() const noexcept
|
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
2024-05-01 10:39:18 +02:00
|
|
|
std::size_t intrinsic_info::parameter_stack_size() const noexcept
|
|
|
|
{
|
2024-05-19 00:43:59 +02:00
|
|
|
return type()->arguments.size() * sizeof(std::int32_t);
|
2024-05-01 10:39:18 +02:00
|
|
|
}
|
|
|
|
|
2024-05-19 00:43:59 +02:00
|
|
|
procedure_info::procedure_info(const class procedure_type& type, std::shared_ptr<symbol_table> outer_scope)
|
|
|
|
: intrinsic_info(type), local_table(std::make_shared<symbol_table>(outer_scope))
|
2024-05-01 10:39:18 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
procedure_info::~procedure_info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<symbol_table> procedure_info::scope()
|
|
|
|
{
|
|
|
|
return local_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t procedure_info::stack_size() const noexcept
|
|
|
|
{
|
|
|
|
return local_stack_size + argument_stack_size;
|
|
|
|
}
|
|
|
|
}
|