diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-07-13 18:14:45 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-07-13 18:14:45 +0200 |
| commit | 500c0676b3f6cd5a2297987d5b0dc7ccf34a28d9 (patch) | |
| tree | a394c73de9273489e6045f3d252714b5ac69b17c /gcc | |
| parent | 97741a01323021ccec8b0b60c6f8318c88ac373a (diff) | |
| download | elna-500c0676b3f6cd5a2297987d5b0dc7ccf34a28d9.tar.gz | |
Make return statement part of the body and not a statement
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/gcc/elna-generic.cc | 56 |
1 files changed, 26 insertions, 30 deletions
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(); |
