Skip to content

Commit

Permalink
Added skip testcase for continuation with only constant
Browse files Browse the repository at this point in the history
  • Loading branch information
fnhartmann committed Dec 19, 2023
1 parent 795c68e commit d4d5dd7
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

0 comments on commit d4d5dd7

Please sign in to comment.