aboutsummaryrefslogtreecommitdiff
path: root/boot/type_check.cc
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-09-18 12:19:13 +0200
committerEugen Wissner <belka@caraus.de>2026-09-18 12:19:13 +0200
commitdc9d03915c4b169fec749081b45d56f722105813 (patch)
tree0a0719bc95f942b675fb52865d9c5bac9e105767 /boot/type_check.cc
parentb575036fe804f14b78da74897a74b010cc94f730 (diff)
downloadelna-dc9d03915c4b169fec749081b45d56f722105813.tar.gz
Allow block-local variables
Diffstat (limited to 'boot/type_check.cc')
-rw-r--r--boot/type_check.cc45
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);
}
}