Assign variables
This commit is contained in:
38
source/semantic.cpp
Normal file
38
source/semantic.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "elna/source/semantic.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
namespace elna::source
|
||||
{
|
||||
void name_analysis_visitor::visit(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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user