From d4d5dd71349e498350a56973e82ba41c6da8b388 Mon Sep 17 00:00:00 2001 From: fnhartmann Date: Tue, 19 Dec 2023 10:42:00 +0100 Subject: [PATCH] Added skip testcase for continuation with only constant --- .../test_readability_based_refinement.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/pipeline/controlflowanalysis/test_readability_based_refinement.py b/tests/pipeline/controlflowanalysis/test_readability_based_refinement.py index 4ea3afd99..fe0e7239a 100644 --- a/tests/pipeline/controlflowanalysis/test_readability_based_refinement.py +++ b/tests/pipeline/controlflowanalysis/test_readability_based_refinement.py @@ -1377,3 +1377,52 @@ def test_skip_for_loop_recovery_if_continue_in_while_4(self): WhileLoopReplacer(ast, _generate_options()).run() assert not any(isinstance(loop_node, ForLoopNode) for loop_node in list(ast.get_loop_nodes_post_order())) + + def test_skip_for_loop_recovery_if_continue_in_while_5(self): + """ + Test skip of for loop recovery if a continue occurs in a while loop, because the continuation instruction is + an assignment with a constant and is therefore not a simple binary operation. + + a = 0 + while(a < 10){ + if(a == 2) { + a = a + 1 + continue + } + a = 4 + } + """ + true_value = LogicCondition.initialize_true(context := LogicCondition.generate_new_context()) + ast = AbstractSyntaxTree( + root := SeqNode(true_value), + condition_map={ + logic_cond("x1", context): Condition(OperationType.less, [Variable("a"), Constant(10)]), + logic_cond("x2", context): Condition(OperationType.equal, [Variable("a"), Constant(2)]), + }, + ) + + true_branch = ast._add_code_node( + [Assignment(Variable("a"), BinaryOperation(OperationType.plus, [Variable("a"), Constant(1)])), Continue()] + ) + if_condition = ast._add_condition_node_with(logic_cond("x2", context), true_branch) + + init_code_node = ast._add_code_node([Assignment(Variable("a"), Constant(0))]) + + while_loop = ast.factory.create_while_loop_node(logic_cond("x1", context)) + while_loop_body = ast.factory.create_seq_node() + while_loop_iteration = ast._add_code_node([Assignment(Variable("a"), Constant(4))]) + ast._add_node(while_loop) + ast._add_node(while_loop_body) + + ast._add_edges_from( + [ + (root, init_code_node), + (root, while_loop), + (while_loop, while_loop_body), + (while_loop_body, if_condition), + (while_loop_body, while_loop_iteration), + ] + ) + + WhileLoopReplacer(ast, _generate_options()).run() + assert not any(isinstance(loop_node, ForLoopNode) for loop_node in list(ast.get_loop_nodes_post_order()))