diff options
Diffstat (limited to 'boot/type_check.cc')
| -rw-r--r-- | boot/type_check.cc | 45 |
1 files changed, 13 insertions, 32 deletions
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<type_requirement_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); } } |
