39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
#include "elna/source/semantic.hpp"
|
|
#include <cstdlib>
|
|
|
|
namespace elna::source
|
|
{
|
|
void name_analysis_visitor::visit(constant_definition *definition)
|
|
{
|
|
this->table->enter(definition->identifier(),
|
|
std::make_shared<constant_info>(constant_info(definition->body().number())));
|
|
}
|
|
|
|
void name_analysis_visitor::visit(declaration *declaration)
|
|
{
|
|
this->table->enter(declaration->identifier(),
|
|
std::make_shared<variable_info>(variable_info()));
|
|
}
|
|
|
|
void name_analysis_visitor::visit(block *block)
|
|
{
|
|
this->table = block->table();
|
|
empty_visitor::visit(block);
|
|
this->table->enter("main",
|
|
std::make_shared<procedure_info>());
|
|
}
|
|
|
|
void allocator_visitor::visit(declaration *declaration)
|
|
{
|
|
this->offset -= sizeof(std::int32_t);
|
|
}
|
|
|
|
void allocator_visitor::visit(block *block)
|
|
{
|
|
this->offset = 0;
|
|
empty_visitor::visit(block);
|
|
std::dynamic_pointer_cast<procedure_info>(block->table()->lookup("main"))
|
|
->stack_size(std::abs(this->offset));
|
|
}
|
|
}
|