From dc9d03915c4b169fec749081b45d56f722105813 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 18 Sep 2026 12:19:13 +0200 Subject: Allow block-local variables --- boot/type_check.cc | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) (limited to 'boot/type_check.cc') diff --git a/boot/type_check.cc b/boot/type_check.cc index 2b82bec..5d5bc59 100644 --- a/boot/type_check.cc +++ b/boot/type_check.cc @@ -876,66 +876,47 @@ namespace elna::boot add_error(statement->range().position(), statement->range().type_decoration, type_requirement_error::kind::for_range); } - this->bag.enter(statement->symbols); - for (auto *body_statement : statement->body) - { - body_statement->accept(this); - } + traverse_block(statement->body); + } + + void type_analysis_visitor::traverse_block(block& body) + { + this->bag.enter(body.symbols); + walking_visitor::traverse_block(body); this->bag.leave(); } void type_analysis_visitor::visit(repeat_statement *statement) { visit_and_validate_condition(statement->condition()); - - for (auto *body_statement : statement->body) - { - body_statement->accept(this); - } + traverse_block(statement->body); } void type_analysis_visitor::visit(while_statement *statement) { visit_and_validate_condition(statement->branch().prerequisite()); + traverse_block(statement->branch().body); - for (auto *branch_statement : statement->branch().statements) - { - branch_statement->accept(this); - } for (conditional_statements *branch : statement->branches) { visit_and_validate_condition(branch->prerequisite()); - - for (auto *branch_statement : branch->statements) - { - branch_statement->accept(this); - } + traverse_block(branch->body); } } void type_analysis_visitor::visit(if_statement *statement) { visit_and_validate_condition(statement->branch().prerequisite()); + traverse_block(statement->branch().body); - for (auto *branch_statement : statement->branch().statements) - { - branch_statement->accept(this); - } for (conditional_statements *branch : statement->branches) { visit_and_validate_condition(branch->prerequisite()); - - for (auto *branch_statement : branch->statements) - { - branch_statement->accept(this); - } + traverse_block(branch->body); } if (statement->alternative != nullptr) { - for (auto *branch_statement : *statement->alternative) - { - branch_statement->accept(this); - } + traverse_block(*statement->alternative); } } -- cgit v1.2.3