Support procedure calls without arguments
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
|
||||
namespace elna::source
|
||||
{
|
||||
name_analysis_visitor::name_analysis_visitor(std::shared_ptr<symbol_table> table)
|
||||
: table(table)
|
||||
{
|
||||
}
|
||||
|
||||
void name_analysis_visitor::visit(constant_definition *definition)
|
||||
{
|
||||
this->table->enter(definition->identifier(),
|
||||
@@ -15,12 +20,24 @@ namespace elna::source
|
||||
std::make_shared<variable_info>(variable_info()));
|
||||
}
|
||||
|
||||
void name_analysis_visitor::visit(block *block)
|
||||
void name_analysis_visitor::visit(program *program)
|
||||
{
|
||||
this->table->enter("main", std::make_shared<procedure_info>(this->table));
|
||||
empty_visitor::visit(program);
|
||||
}
|
||||
|
||||
void name_analysis_visitor::visit(procedure_definition *procedure)
|
||||
{
|
||||
auto info = std::make_shared<procedure_info>(this->table);
|
||||
this->table->enter(procedure->identifier(), info);
|
||||
this->table = info->scope();
|
||||
empty_visitor::visit(procedure);
|
||||
this->table = info->scope()->scope();
|
||||
}
|
||||
|
||||
allocator_visitor::allocator_visitor(std::shared_ptr<symbol_table> table)
|
||||
: table(table)
|
||||
{
|
||||
this->table = block->table();
|
||||
empty_visitor::visit(block);
|
||||
this->table->enter("main",
|
||||
std::make_shared<procedure_info>());
|
||||
}
|
||||
|
||||
void allocator_visitor::visit(declaration *declaration)
|
||||
@@ -28,11 +45,19 @@ namespace elna::source
|
||||
this->offset -= sizeof(std::int32_t);
|
||||
}
|
||||
|
||||
void allocator_visitor::visit(block *block)
|
||||
void allocator_visitor::visit(program *program)
|
||||
{
|
||||
this->offset = 0;
|
||||
empty_visitor::visit(block);
|
||||
std::dynamic_pointer_cast<procedure_info>(block->table()->lookup("main"))
|
||||
empty_visitor::visit(program);
|
||||
std::dynamic_pointer_cast<procedure_info>(table->lookup("main"))
|
||||
->stack_size(std::abs(this->offset));
|
||||
}
|
||||
|
||||
void allocator_visitor::visit(procedure_definition *procedure)
|
||||
{
|
||||
this->offset = 0;
|
||||
empty_visitor::visit(procedure);
|
||||
std::dynamic_pointer_cast<procedure_info>(table->lookup(procedure->identifier()))
|
||||
->stack_size(std::abs(this->offset));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user