Add an else to the case statement

This commit is contained in:
2025-04-11 15:28:43 +02:00
parent f68667d5e5
commit 6fd1bda112
6 changed files with 173 additions and 169 deletions

View File

@ -1183,10 +1183,10 @@ namespace elna::gcc
{
make_if_branch(*branch, goto_endif);
}
if (statement->alternative() != nullptr)
if (statement->alternative != nullptr)
{
enter_scope();
visit_statements(*statement->alternative());
visit_statements(*statement->alternative);
tree mapping = leave_scope();
append_statement(mapping);
}
@ -1465,11 +1465,24 @@ namespace elna::gcc
enter_scope();
visit_statements(case_block.statements);
append_to_statement_list(leave_scope(), &switch_statements);
tree goto_end = fold_build1(GOTO_EXPR, void_type_node, end_label_declaration);
tree goto_end = build1(GOTO_EXPR, void_type_node, end_label_declaration);
append_to_statement_list(goto_end, &switch_statements);
TREE_USED(end_label_declaration) = 1;
}
if (statement->alternative != nullptr)
{
tree case_label_declaration = create_artificial_label(UNKNOWN_LOCATION);
tree case_expression = build_case_label(NULL_TREE, NULL_TREE, case_label_declaration);
append_to_statement_list(case_expression, &switch_statements);
enter_scope();
visit_statements(*statement->alternative);
append_to_statement_list(leave_scope(), &switch_statements);
TREE_USED(end_label_declaration) = 1;
}
tree switch_expression = build2(SWITCH_EXPR, TREE_TYPE(condition_expression),
condition_expression, switch_statements);