#include "elna/source/semantic.hpp" #include namespace elna::source { name_analysis_visitor::name_analysis_visitor(std::shared_ptr table) : table(table) { } void name_analysis_visitor::visit(constant_definition *definition) { this->table->enter(definition->identifier(), std::make_shared(constant_info(definition->body().number()))); } void name_analysis_visitor::visit(declaration *declaration) { this->table->enter(declaration->identifier(), std::make_shared(variable_info())); } void name_analysis_visitor::visit(program *program) { this->table->enter("main", std::make_shared(this->table)); empty_visitor::visit(program); } void name_analysis_visitor::visit(procedure_definition *procedure) { auto info = std::make_shared(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 table) : table(table) { } void allocator_visitor::visit(declaration *declaration) { this->offset -= sizeof(std::int32_t); } void allocator_visitor::visit(program *program) { this->offset = 0; empty_visitor::visit(program); std::dynamic_pointer_cast(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(table->lookup(procedure->identifier())) ->stack_size(std::abs(this->offset)); } }