From 308a2addf655fe45f2098f8542f0ff1290612cd9 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 14 Jul 2026 19:42:32 +0200 Subject: Replace procedure end with return --- boot/ast.cc | 11 +++-------- boot/parser.yy | 12 ++++++------ boot/semantic.cc | 22 ---------------------- 3 files changed, 9 insertions(+), 36 deletions(-) (limited to 'boot') diff --git a/boot/ast.cc b/boot/ast.cc index 14bad30..2a22d69 100644 --- a/boot/ast.cc +++ b/boot/ast.cc @@ -348,10 +348,6 @@ namespace elna::boot { entry_statement->accept(this); } - if (unit->return_expression != nullptr) - { - unit->return_expression->accept(this); - } } void walking_visitor::visit(type_declaration *declaration) @@ -879,10 +875,9 @@ namespace elna::boot std::vector&& types, std::vector&& variables, std::vector&& procedures, - std::vector&& entry_point, - expression *const return_expression) + std::vector&& entry_point) : node(position), - procedure_body(std::move(constants), std::move(variables), std::move(entry_point), return_expression), + procedure_body(std::move(constants), std::move(variables), std::move(entry_point)), imports(std::move(imports)), types(std::move(types)), procedures(std::move(procedures)) { } @@ -894,7 +889,7 @@ namespace elna::boot bool unit::has_body() const { - return !this->entry_point.empty() || this->return_expression != nullptr; + return !this->entry_point.empty(); } unit::~unit() diff --git a/boot/parser.yy b/boot/parser.yy index ef887ab..9f610ee 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -136,7 +136,7 @@ along with GCC; see the file COPYING3. If not see %type type_expression; %type > type_expressions; %type traits_expression; -%type expression operand simple_expression return_statement; +%type expression operand simple_expression procedure_return; %type unary_expression; %type binary_expression; %type > expressions actual_parameter_list; @@ -164,13 +164,13 @@ along with GCC; see the file COPYING3. If not see %type > import_declarations import_part; %% program: - import_part constant_part type_part variable_part procedure_part statement_part return_statement "end" "." + import_part constant_part type_part variable_part procedure_part statement_part "end" "." { - boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4, $5, $6, $7); + boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4, $5, $6); driver.tree.reset(tree); } procedure_body: - constant_part variable_part statement_part return_statement "end" + constant_part variable_part statement_part procedure_return { $$ = std::make_unique($1, $2, $3, $4); } statement_part: @@ -233,9 +233,9 @@ elsif_then_statements: $$.emplace($$.begin(), branch); } | /* no branches */ {} -return_statement: +procedure_return: "return" expression { $$ = $2; } - | /* no return statement */ { $$ = nullptr; } + | "return" { $$ = nullptr; } literal: INTEGER { $$ = new boot::literal(boot::make_position(@$), $1); } | WORD { $$ = new boot::literal(boot::make_position(@$), $1); } diff --git a/boot/semantic.cc b/boot/semantic.cc index d7a23be..dd9022b 100644 --- a/boot/semantic.cc +++ b/boot/semantic.cc @@ -177,24 +177,6 @@ namespace elna::boot void type_analysis_visitor::visit(unit *unit) { walking_visitor::visit(unit); - - if (unit->has_body()) - { - if (unit->return_expression != nullptr) - { - type return_type = this->bag.lookup("Int")->is_type()->symbol; - - if (!is_assignable_from(return_type, unit->return_expression->type_decoration)) - { - add_error(type_expectation_error::kind::result, - unit->return_expression->position()); - } - } - else - { - add_error("module", unit->position()); - } - } } void type_analysis_visitor::visit(assign_statement *statement) @@ -773,10 +755,6 @@ namespace elna::boot { statement->accept(this); } - if (unit->return_expression != nullptr) - { - unit->return_expression->accept(this); - } this->bag.leave(); } } -- cgit v1.2.3