From 500c0676b3f6cd5a2297987d5b0dc7ccf34a28d9 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 13 Jul 2026 18:14:45 +0200 Subject: Make return statement part of the body and not a statement --- gcc/gcc/elna-generic.cc | 56 +++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'gcc') diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc index 497bcc6..30dd68b 100644 --- a/gcc/gcc/elna-generic.cc +++ b/gcc/gcc/elna-generic.cc @@ -196,7 +196,7 @@ namespace elna::gcc { procedure->accept(this); } - if (unit->entry_point.has_value()) + if (unit->has_body()) { tree declaration_type = build_function_type_list(elna_int_type_node, elna_int_type_node, @@ -225,11 +225,13 @@ namespace elna::gcc DECL_ARGUMENTS(fndecl) = chainon(DECL_ARGUMENTS(fndecl), declaration_tree); parameter_type = TREE_CHAIN(parameter_type); } - visit_statements(unit->entry_point.value()); + visit_statements(unit->entry_point); + unit->return_expression->accept(this); tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(fndecl), - build_int_cst_type(integer_type_node, 0)); + this->current_expression); tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result); append_statement(return_stmt); + this->current_expression = NULL_TREE; tree mapping = leave_scope(); BLOCK_SUPERCONTEXT(BIND_EXPR_BLOCK(mapping)) = fndecl; @@ -264,15 +266,33 @@ namespace elna::gcc { this->symbols->enter(IDENTIFIER_POINTER(DECL_NAME(argument_chain)), argument_chain); } - for (boot::constant_declaration *const constant : declaration->body.value().constants()) + for (boot::constant_declaration *const constant : declaration->body.value().constants) { constant->accept(this); } - for (boot::variable_declaration *const variable : declaration->body.value().variables()) + for (boot::variable_declaration *const variable : declaration->body.value().variables) { variable->accept(this); } - visit_statements(declaration->body.value().statements()); + visit_statements(declaration->body.value().entry_point); + + if (declaration->body.value().return_expression != nullptr) + { + location_t position = get_location(&declaration->body.value().return_expression->position()); + tree set_result{ NULL_TREE }; + + if (TREE_THIS_VOLATILE(current_function_decl) != 1) + { + declaration->body.value().return_expression->accept(this); + + set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(current_function_decl), + this->current_expression); + } + tree return_stmt = build1_loc(position, RETURN_EXPR, void_type_node, set_result); + append_statement(return_stmt); + + this->current_expression = NULL_TREE; + } tree mapping = leave_scope(); this->bag.leave(); @@ -1066,30 +1086,6 @@ namespace elna::gcc } } - void generic_visitor::visit(boot::return_statement *statement) - { - boot::expression *return_expression = &statement->return_expression(); - location_t statement_position = get_location(&statement->position()); - tree set_result{ NULL_TREE }; - - if (TREE_THIS_VOLATILE(current_function_decl) == 1) - { - error_at(statement_position, "This procedure is not allowed to return"); - return; - } - if (return_expression != nullptr) - { - return_expression->accept(this); - - set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(current_function_decl), - this->current_expression); - } - tree return_stmt = build1_loc(statement_position, RETURN_EXPR, void_type_node, set_result); - append_statement(return_stmt); - - this->current_expression = NULL_TREE; - } - void generic_visitor::visit(boot::defer_statement *statement) { enter_scope(); -- cgit v1.2.3