From c57a24b9fe37e233e7ec0e2e65405738d9c09c6e Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 27 Sep 2026 11:23:17 +0200 Subject: Reuse container visiting logic --- boot/name_analysis.cc | 55 ++++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) (limited to 'boot/name_analysis.cc') diff --git a/boot/name_analysis.cc b/boot/name_analysis.cc index 2ee3da1..20f08ee 100644 --- a/boot/name_analysis.cc +++ b/boot/name_analysis.cc @@ -284,10 +284,7 @@ namespace elna::boot void forward_declaration_visitor::visit(unit *unit) { - for (auto *const unit_declaration: unit->declarations) - { - unit_declaration->accept(this); - } + visit_all(this, unit->declarations); } void forward_declaration_visitor::visit(type_declaration *declaration) @@ -733,22 +730,10 @@ namespace elna::boot statement->rvalue().accept(this); } - void resolving_visitor::traverse_block(block& body) - { - for (variable_declaration *const variable : body.variables) - { - variable->accept(this); - } - for (statement *const body_statement : body.statements) - { - body_statement->accept(this); - } - } - void resolving_visitor::visit_block(block& body) { body.symbols = this->bag.enter(); - traverse_block(body); + traverse_block(this, body); this->bag.leave(); } @@ -813,7 +798,7 @@ namespace elna::boot add_error(statement->name.position(), label_name, original_definition); } - traverse_block(statement->body); + traverse_block(this, statement->body); this->bag.leave(); } @@ -852,10 +837,7 @@ namespace elna::boot statement->condition().accept(this); for (switch_case& case_block : statement->cases) { - for (expression *case_label : case_block.labels) - { - case_label->accept(this); - } + visit_all(this, case_block.labels); visit_block(case_block.body); } if (statement->alternative != nullptr) @@ -871,10 +853,7 @@ namespace elna::boot { call->type_decoration = procedure->return_type.proper_type; } - for (expression *const argument : call->arguments) - { - argument->accept(this); - } + visit_all(this, call->arguments); this->current_type = type(); } @@ -918,11 +897,9 @@ namespace elna::boot void resolving_visitor::visit(array_constructor_expression *expression) { - for (auto *const element : expression->elements) - { - element->accept(this); - } + visit_all(this, expression->elements); const type element_type = expression->elements.front()->type_decoration; + expression->type_decoration = type(std::make_shared(element_type, expression->elements.size())); this->current_type = type(); @@ -1347,10 +1324,7 @@ namespace elna::boot void declaration_visitor::visit(unit *unit) { - for (declaration *const unit_declaration : unit->declarations) - { - unit_declaration->accept(this); - } + visit_all(this, unit->declarations); if (unit->entry_point.has_value()) { const type word8_primitive = lookup_primitive_type("Word8"); @@ -1540,10 +1514,7 @@ namespace elna::boot const std::shared_ptr info = this->bag.lookup("")->is_procedure(); this->bag.enter(info->scope); - for (statement *body_statement : unit->entry_point.value()) - { - body_statement->accept(this); - } + visit_all(this, unit->entry_point.value()); this->bag.leave(); } } @@ -1590,7 +1561,11 @@ namespace elna::boot declaration->body->symbols = info->scope; this->bag.enter(info->scope); - traverse_body(this, declaration->body.value()); + traverse_block(this, declaration->body.value()); + if (declaration->body.value().return_expression != nullptr) + { + declaration->body.value().return_expression->accept(this); + } this->bag.leave(); } } @@ -1612,7 +1587,7 @@ namespace elna::boot register_variable(statement->counter->name(), lookup_primitive_type("Word"), statement->counter->position()); } - traverse_block(statement->body); + traverse_block(this, statement->body); this->bag.leave(); } } -- cgit v1.2.3