From f2019491350d4b599e018126299ef3d75b000cea Mon Sep 17 00:00:00 2001 From: rihi <19492038+rihi@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:01:59 +0100 Subject: [PATCH] Fix access to private property of task object --- .../loop_name_generator.py | 4 +- .../controlflowanalysis/restructuring.py | 4 +- .../variable_name_generation.py | 8 +- decompiler/task.py | 5 - .../test_condition_aware_refinement.py | 80 ++++++++-------- .../test_pattern_independent_restructuring.py | 94 +++++++++---------- ...tern_independent_restructuring_blackbox.py | 8 +- 7 files changed, 98 insertions(+), 105 deletions(-) diff --git a/decompiler/pipeline/controlflowanalysis/loop_name_generator.py b/decompiler/pipeline/controlflowanalysis/loop_name_generator.py index 0d9590d6f..16e0f5a42 100644 --- a/decompiler/pipeline/controlflowanalysis/loop_name_generator.py +++ b/decompiler/pipeline/controlflowanalysis/loop_name_generator.py @@ -117,7 +117,7 @@ def run(self, task: DecompilerTask): for_loop_names: List[str] = task.options.getlist("loop-name-generator.for_loop_variable_names", fallback=[]) if rename_while_loops: - WhileLoopVariableRenamer(task._ast).rename() + WhileLoopVariableRenamer(task.ast).rename() if for_loop_names: - ForLoopVariableRenamer(task._ast, for_loop_names).rename() + ForLoopVariableRenamer(task.ast, for_loop_names).rename() diff --git a/decompiler/pipeline/controlflowanalysis/restructuring.py b/decompiler/pipeline/controlflowanalysis/restructuring.py index 949e3e41c..869cc0abf 100644 --- a/decompiler/pipeline/controlflowanalysis/restructuring.py +++ b/decompiler/pipeline/controlflowanalysis/restructuring.py @@ -53,8 +53,8 @@ def run(self, task: DecompilerTask): assert len(self.t_cfg) == 1, f"The Transition Graph can only have one node after the restructuring." self.asforest.set_current_root(self.t_cfg.root.ast) assert (roots := len(self.asforest.get_roots)) == 1, f"After the restructuring the forest should have one root, but it has {roots}!" - task._ast = AbstractSyntaxTree.from_asforest(self.asforest, self.asforest.current_root) - task._cfg = None + task.ast = AbstractSyntaxTree.from_asforest(self.asforest, self.asforest.current_root) + task.cfg = None def restructure_cfg(self) -> None: """ diff --git a/decompiler/pipeline/controlflowanalysis/variable_name_generation.py b/decompiler/pipeline/controlflowanalysis/variable_name_generation.py index 8627c93da..10876adb1 100644 --- a/decompiler/pipeline/controlflowanalysis/variable_name_generation.py +++ b/decompiler/pipeline/controlflowanalysis/variable_name_generation.py @@ -1,7 +1,7 @@ import re from abc import ABC, abstractmethod from enum import Enum -from typing import Dict, List, Optional, Set +from typing import Dict, List, Optional from decompiler.pipeline.stage import PipelineStage from decompiler.structures.ast.ast_nodes import ConditionNode, LoopNode @@ -75,9 +75,9 @@ class RenamingScheme(ABC): def __init__(self, task: DecompilerTask) -> None: """Collets all needed variables for renaming + filters already renamed + function arguments out""" - collector = VariableCollector(task._ast.condition_map) - collector.visit_ast(task._ast) - self._params: List[Variable] = task._function_parameters + collector = VariableCollector(task.ast.condition_map) + collector.visit_ast(task.ast) + self._params: List[Variable] = task.function_parameters self._loop_vars: List[Variable] = collector.get_loop_variables() self._variables: List[Variable] = list(filter(self._filter_variables, collector.get_variables())) diff --git a/decompiler/task.py b/decompiler/task.py index f562053e6..60839132d 100644 --- a/decompiler/task.py +++ b/decompiler/task.py @@ -31,11 +31,6 @@ class DecompilerTask: graph = property(lambda self: self.cfg, lambda self, v: setattr(self, "cfg", v)) syntax_tree = property(lambda self: self.ast, lambda self, v: setattr(self, "ast", v)) - # Properties for backwards compatibility. For some reason some code directly accessed these private fields. - _cfg = property(lambda self: self.cfg, lambda self, v: setattr(self, "cfg", v)) - _ast = property(lambda self: self.ast, lambda self, v: setattr(self, "ast", v)) - _function_parameters = property(lambda self: self.function_parameters, lambda self, v: setattr(self, "function_parameters", v)) - def fail(self, origin: str = ""): """Sets the task to be failed by setting the failure origin.""" if self.failure_origin is not None: diff --git a/tests/pipeline/controlflowanalysis/restructuring_commons/test_condition_aware_refinement.py b/tests/pipeline/controlflowanalysis/restructuring_commons/test_condition_aware_refinement.py index 05fa37dd9..3ad530930 100644 --- a/tests/pipeline/controlflowanalysis/restructuring_commons/test_condition_aware_refinement.py +++ b/tests/pipeline/controlflowanalysis/restructuring_commons/test_condition_aware_refinement.py @@ -530,7 +530,7 @@ def test_basic_switch(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[-1].instructions @@ -623,7 +623,7 @@ def test_switch_cases_without_break_and_no_instruction(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[-1].instructions @@ -787,7 +787,7 @@ def test_switch_one_large_number(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[5].instructions @@ -970,7 +970,7 @@ def test_switch_two_large_numbers(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[3].instructions @@ -1085,7 +1085,7 @@ def test_switch_cases_without_break_and_instructions(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[3].instructions @@ -1204,7 +1204,7 @@ def test_switch_cases_without_break_and_some_instructions(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[7].instructions @@ -1400,7 +1400,7 @@ def test_switch_condition_node_as_case_node_child(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[9].instructions @@ -1422,18 +1422,18 @@ def test_switch_condition_node_as_case_node_child(task): assert isinstance(cond_node1 := case1.child, ConditionNode) assert isinstance(cond_node1.true_branch.child, CodeNode) and isinstance(cond_node1.false_branch.child, CodeNode) if cond_node1.condition.is_symbol: - assert task._ast.condition_map[cond_node1.condition] == vertices[3].instructions[0].condition + assert task.ast.condition_map[cond_node1.condition] == vertices[3].instructions[0].condition assert cond_node1.true_branch_child.instructions == vertices[10].instructions assert cond_node1.false_branch_child.instructions == vertices[11].instructions else: - assert task._ast.condition_map[~cond_node1.condition] == vertices[3].instructions[0].condition + assert task.ast.condition_map[~cond_node1.condition] == vertices[3].instructions[0].condition assert cond_node1.true_branch_child.instructions == vertices[11].instructions assert cond_node1.false_branch_child.instructions == vertices[10].instructions assert isinstance(cond_node2 := case2.child, ConditionNode) assert isinstance(cond_node2.true_branch.child, CodeNode) and cond_node2.false_branch is None assert cond_node2.condition.is_negation and (~cond_node2.condition).is_symbol - assert task._ast.condition_map[~cond_node2.condition] == vertices[4].instructions[0].condition + assert task.ast.condition_map[~cond_node2.condition] == vertices[4].instructions[0].condition assert cond_node2.true_branch_child.instructions == vertices[12].instructions assert isinstance(case3.child, CodeNode) and case3.child.instructions == vertices[5].instructions @@ -1615,7 +1615,7 @@ def test_switch_in_switch_easy(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[-1].instructions @@ -1796,7 +1796,7 @@ def test_switch_in_switch_long(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[10].instructions @@ -1998,7 +1998,7 @@ def test_switch_only_if_else(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[-1].instructions @@ -2086,7 +2086,7 @@ def test_switch_find_case_in_condition(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch_cond := seq_node.children[1], ConditionNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[4].instructions @@ -2094,7 +2094,7 @@ def test_switch_find_case_in_condition(task): # switch condition: assert switch_cond.false_branch is None and isinstance(switch := switch_cond.true_branch_child, SwitchNode) assert switch_cond.condition.is_literal and not switch_cond.condition.is_symbol - assert task._ast.condition_map[~switch_cond.condition] == vertices[1].instructions[-1].condition + assert task.ast.condition_map[~switch_cond.condition] == vertices[1].instructions[-1].condition # switch node: assert switch.expression == var_0_2 and len(switch.children) == 7 @@ -2229,7 +2229,7 @@ def test_two_entries_to_one_case(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[-1].instructions @@ -2260,8 +2260,8 @@ def test_two_entries_to_one_case(task): assert ( cond.condition.is_conjunction and len(operands := cond.condition.operands) == 2 and all(operands[i].is_negation for i in [0, 1]) ) - term_1 = task._ast.condition_map[~operands[0]] - term_2 = task._ast.condition_map[~operands[1]] + term_1 = task.ast.condition_map[~operands[0]] + term_2 = task.ast.condition_map[~operands[1]] assert {term_1, term_2} == { Condition(OperationType.equal, [var_0, Constant(1, Integer(32))]), Condition(OperationType.equal, [var_0, Constant(2, Integer(32))]), @@ -2400,7 +2400,7 @@ def test_two_exits_to_one_case_depend_on_switch(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[-1].instructions @@ -2429,7 +2429,7 @@ def test_two_exits_to_one_case_depend_on_switch(task): # condition nodes exit one: for cond, child in [(cond_1, 5), (cond_2, 6)]: assert cond.condition.is_negation and ~cond.condition.is_symbol - assert task._ast.condition_map[~cond.condition] == Condition(OperationType.equal, [var_0, Constant(2, Integer(32))]) + assert task.ast.condition_map[~cond.condition] == Condition(OperationType.equal, [var_0, Constant(2, Integer(32))]) assert ( isinstance(cond.true_branch_child, CodeNode) and cond.true_branch_child.instructions == vertices[child].instructions @@ -2443,9 +2443,9 @@ def test_two_exits_to_one_case_depend_on_switch(task): and len(operands := cond.condition.operands) == 3 and all(operands[i].is_negation for i in [0, 1, 2]) ) - term_1 = task._ast.condition_map[~operands[0]] - term_2 = task._ast.condition_map[~operands[1]] - term_3 = task._ast.condition_map[~operands[2]] + term_1 = task.ast.condition_map[~operands[0]] + term_2 = task.ast.condition_map[~operands[1]] + term_3 = task.ast.condition_map[~operands[2]] assert {term_1, term_2, term_3} == { Condition(OperationType.equal, [var_0, Constant(1, Integer(32))]), Condition(OperationType.equal, [var_0, Constant(3, Integer(32))]), @@ -2595,7 +2595,7 @@ def test_two_exits_to_one_case_not_depend_on_switch(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[-1].instructions @@ -2625,7 +2625,7 @@ def test_two_exits_to_one_case_not_depend_on_switch(task): assert cond_1.condition.is_disjunction and len(operands := cond_1.condition.operands) == 2 assert any((cc_1 := operands[i]).is_symbol for i in [0, 1]) and any((cc_2 := operands[i]).is_negation for i in [0, 1]) assert (cc_2 := ~cc_2).is_symbol - assert [task._ast.condition_map[cc_1], task._ast.condition_map[cc_2]] == [ + assert [task.ast.condition_map[cc_1], task.ast.condition_map[cc_2]] == [ Condition(OperationType.equal, [var_0, Constant(3, Integer(32))]), Condition(OperationType.not_equal, [var_1, Constant(1, Integer(32, True))]), ] @@ -2638,9 +2638,9 @@ def test_two_exits_to_one_case_not_depend_on_switch(task): # condition nodes exit one - cond_2: assert cond_2.condition.is_disjunction and len(operands := cond_2.condition.operands) == 3 assert any((cc_not := operands[i]).is_negation for i in [0, 1, 2]) and (cc := ~cc_not).is_symbol - assert task._ast.condition_map[cc] == Condition(OperationType.not_equal, [var_1, Constant(1, Integer(32, True))]) + assert task.ast.condition_map[cc] == Condition(OperationType.not_equal, [var_1, Constant(1, Integer(32, True))]) assert all(cc.is_symbol for cc in operands if str(cc) != str(cc_not)) - assert {task._ast.condition_map[cc] for cc in operands if str(cc) != str(cc_not)} == { + assert {task.ast.condition_map[cc] for cc in operands if str(cc) != str(cc_not)} == { Condition(OperationType.equal, [var_0, Constant(3, Integer(32))]), Condition(OperationType.equal, [var_0, Constant(4, Integer(32))]), } @@ -2656,8 +2656,8 @@ def test_two_exits_to_one_case_not_depend_on_switch(task): or_conditions = [arg for arg in operands if arg.is_disjunction] not_conditions = [arg for arg in operands if arg.is_negation] assert len(not_conditions) == 2 - term_1 = task._ast.condition_map[~not_conditions[0]] - term_2 = task._ast.condition_map[~not_conditions[1]] + term_1 = task.ast.condition_map[~not_conditions[0]] + term_2 = task.ast.condition_map[~not_conditions[1]] assert {term_1, term_2} == { Condition(OperationType.equal, [var_0, Constant(3, Integer(32))]), Condition(OperationType.equal, [var_0, Constant(4, Integer(32))]), @@ -2665,15 +2665,15 @@ def test_two_exits_to_one_case_not_depend_on_switch(task): assert len(or_conditions) == 1 or_cond = or_conditions[0] assert len(operands := or_cond.operands) == or_args and all(arg.is_symbol for arg in operands) - term_1 = task._ast.condition_map[operands[0]] - term_2 = task._ast.condition_map[operands[1]] + term_1 = task.ast.condition_map[operands[0]] + term_2 = task.ast.condition_map[operands[1]] if or_args == 2: assert {term_1, term_2} == { Condition(OperationType.not_equal, [var_1, Constant(1, Integer(32, True))]), Condition(OperationType.equal, [var_0, Constant(5, Integer(32))]), } else: - term_3 = task._ast.condition_map[operands[2]] + term_3 = task.ast.condition_map[operands[2]] assert {term_1, term_2, term_3} == { Condition(OperationType.not_equal, [var_1, Constant(1, Integer(32, True))]), Condition(OperationType.equal, [var_0, Constant(5, Integer(32))]), @@ -2691,7 +2691,7 @@ def test_switch_add_existing_cases(task): """test_switch test7_b or 18 -> later: insert case that is already their (but empty)""" # print(DecoratedCFG.from_cfg(task.graph).export_ascii()) # PatternIndependentRestructuring().run(task) - # DecoratedAST.from_ast(task._ast).export_plot("/home/eva/Projects/decompiler/AST/out.png") + # DecoratedAST.from_ast(task.ast).export_plot("/home/eva/Projects/decompiler/AST/out.png") pass @@ -2747,26 +2747,26 @@ def test_no_switch_ssa_variable_wrong(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 4 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 4 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(friday_case := seq_node.children[1], ConditionNode) and friday_case.condition.is_literal assert isinstance(switch_cond := seq_node.children[2], ConditionNode) assert isinstance(seq_node.children[3], CodeNode) and seq_node.children[3].instructions == vertices[11].instructions # friday case - assert task._ast.condition_map[~friday_case.condition] == vertices[0].instructions[-1].condition + assert task.ast.condition_map[~friday_case.condition] == vertices[0].instructions[-1].condition assert isinstance(branch_seq := friday_case.true_branch_child, SeqNode) and friday_case.false_branch is None assert len(branch_seq.children) == 2 assert isinstance(branch_seq.children[0], CodeNode) and branch_seq.children[0].instructions == vertices[2].instructions[:1] assert isinstance(friday := branch_seq.children[1], ConditionNode) - assert task._ast.condition_map[~friday.condition] == vertices[2].instructions[-1].condition + assert task.ast.condition_map[~friday.condition] == vertices[2].instructions[-1].condition assert isinstance(friday.true_branch_child, CodeNode) and friday.false_branch is None assert friday.true_branch_child.instructions == vertices[4].instructions # switch_condition: assert switch_cond.false_branch is None and isinstance(switch := switch_cond.true_branch_child, SwitchNode) assert switch_cond.condition.is_disjunction and len(switch_cond.condition.operands) == 2 - assert {task._ast.condition_map[op] for op in switch_cond.condition.operands} == { + assert {task.ast.condition_map[op] for op in switch_cond.condition.operands} == { vertices[0].instructions[-1].condition, vertices[2].instructions[-1].condition, } @@ -2903,7 +2903,7 @@ def test_switch_with_loop1(task): PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) and len(seq_node.children) == 3 + assert isinstance(seq_node := task.ast.root, SeqNode) and len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions[:-1] assert isinstance(switch := seq_node.children[1], SwitchNode) assert isinstance(return_cond := seq_node.children[2], ConditionNode) @@ -2924,10 +2924,10 @@ def test_switch_with_loop1(task): new_assignment = Assignment(new_variable, Constant(0, Integer.int32_t())) assert isinstance(case1.child, CodeNode) and case1.child.instructions == [new_assignment] assert isinstance(cn2 := case2.child, ConditionNode) and cn2.false_branch is None - assert task._ast.condition_map[~cn2.condition] == Condition(OperationType.equal, [var_0, Constant(1, Integer(32))]) + assert task.ast.condition_map[~cn2.condition] == Condition(OperationType.equal, [var_0, Constant(1, Integer(32))]) assert cn2.true_branch_child.instructions == vertices[4].instructions assert isinstance(cn3 := case3.child, ConditionNode) and cn3.false_branch is None - assert task._ast.condition_map[~cn3.condition] == Condition(OperationType.equal, [var_0, Constant(1, Integer(32))]) + assert task.ast.condition_map[~cn3.condition] == Condition(OperationType.equal, [var_0, Constant(1, Integer(32))]) assert cn3.true_branch_child.instructions == [Assignment(new_variable, Constant(1, Integer.int32_t()))] assert isinstance(loop_seq := case7.child, SeqNode) and len(loop_seq.children) == 2 assert isinstance(case4.child, CodeNode) and case4.child.instructions == vertices[6].instructions diff --git a/tests/pipeline/controlflowanalysis/test_pattern_independent_restructuring.py b/tests/pipeline/controlflowanalysis/test_pattern_independent_restructuring.py index a44ae1cad..cdaf110f2 100644 --- a/tests/pipeline/controlflowanalysis/test_pattern_independent_restructuring.py +++ b/tests/pipeline/controlflowanalysis/test_pattern_independent_restructuring.py @@ -67,7 +67,7 @@ def test_empty_graph_one_basic_block(task): task.graph.add_node(BasicBlock(0, instructions=[])) PatternIndependentRestructuring().run(task) - assert isinstance(task._ast.root, CodeNode) and task._ast.root.instructions == [] + assert isinstance(task.ast.root, CodeNode) and task.ast.root.instructions == [] def test_empty_graph_two_basic_blocks(task): @@ -86,7 +86,7 @@ def test_empty_graph_two_basic_blocks(task): task.graph.add_edge(UnconditionalEdge(vertices[0], vertices[1])) PatternIndependentRestructuring().run(task) - assert isinstance(task._ast.root, CodeNode) and task._ast.root.instructions == [] + assert isinstance(task.ast.root, CodeNode) and task.ast.root.instructions == [] def test_empty_graph_with_conditions_1(task): @@ -136,7 +136,7 @@ def test_empty_graph_with_conditions_1(task): ) PatternIndependentRestructuring().run(task) - assert isinstance(task._ast.root, CodeNode) and task._ast.root.instructions == [] + assert isinstance(task.ast.root, CodeNode) and task.ast.root.instructions == [] def test_empty_graph_with_conditions_2(task): @@ -194,7 +194,7 @@ def test_empty_graph_with_conditions_2(task): ) PatternIndependentRestructuring().run(task) - assert isinstance(task._ast.root, CodeNode) and task._ast.root.instructions == [] + assert isinstance(task.ast.root, CodeNode) and task.ast.root.instructions == [] def test_empty_graph_with_switch(task): @@ -246,7 +246,7 @@ def test_empty_graph_with_switch(task): ) PatternIndependentRestructuring().run(task) - assert isinstance(task._ast.root, CodeNode) and task._ast.root.instructions == [] + assert isinstance(task.ast.root, CodeNode) and task.ast.root.instructions == [] def test_graph_with_switch_empty_nodes1(task): @@ -308,7 +308,7 @@ def test_graph_with_switch_empty_nodes1(task): PatternIndependentRestructuring().run(task) assert ( - isinstance(switch_node := task._ast.root, SwitchNode) and len(switch_node.children) == 3 and switch_node.expression == variable("a") + isinstance(switch_node := task.ast.root, SwitchNode) and len(switch_node.children) == 3 and switch_node.expression == variable("a") ) assert ( isinstance(case1 := switch_node.children[0], CaseNode) @@ -393,7 +393,7 @@ def test_graph_with_switch_empty_nodes2(task): ) PatternIndependentRestructuring().run(task) - assert isinstance(switch_node := task._ast.root, SwitchNode) and len(switch_node.children) == 4 + assert isinstance(switch_node := task.ast.root, SwitchNode) and len(switch_node.children) == 4 assert switch_node.expression == variable("a") assert isinstance(case1 := switch_node.children[0], CaseNode) and case1.constant == Constant(1) and case1.break_case is True @@ -465,7 +465,7 @@ def test_empty_basic_block_after_removing(task): resulting_ast._add_edge(resulting_ast.root, condition_node) resulting_ast.flatten_sequence_node(resulting_ast.root) - assert ASTComparator.compare(task._ast, resulting_ast) and task._ast.condition_map == resulting_ast.condition_map + assert ASTComparator.compare(task.ast, resulting_ast) and task.ast.condition_map == resulting_ast.condition_map def test_empty_graph_with_loop(task): @@ -611,7 +611,7 @@ def test_restructure_cfg_sequence(task): PatternIndependentRestructuring().run(task) # make sure that only SeqNodes or CodeNodes have been created during Restructuring - assert isinstance(code_node := task._ast.root, CodeNode) + assert isinstance(code_node := task.ast.root, CodeNode) assert code_node.instructions == [ Assignment(variable(name="i", version=0), Constant(0)), Assignment(variable(name="x", version=0), Constant(42)), @@ -641,7 +641,7 @@ def test_one_node(task): PatternIndependentRestructuring().run(task) - assert isinstance(code_node := task._ast.root, CodeNode) + assert isinstance(code_node := task.ast.root, CodeNode) assert code_node.instructions == [Assignment(ListOperation([]), Call(imp_function_symbol("printf"), [Constant("a")]))] @@ -950,7 +950,7 @@ def test_restructure_cfg_endless(task): assert ASTComparator.compare(task.syntax_tree, resulting_ast) and task.syntax_tree.condition_map == resulting_ast.condition_map - assert isinstance(seq_node := task._ast.root, SeqNode) + assert isinstance(seq_node := task.ast.root, SeqNode) assert all(not isinstance(n, ConditionNode) for n in seq_node.children) assert all(not isinstance(n, SwitchNode) for n in seq_node.children) assert any(isinstance(loop_node := n, WhileLoopNode) for n in seq_node.children) @@ -1513,7 +1513,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_1(task): assert isinstance(loop_node := seq_node.children[1], WhileLoopNode) # make sure that the loop has the correct type and condition - assert isinstance(cond := task._ast.condition_map[loop_node.condition], Condition) and str(cond) == "i#0 != 0x3" + assert isinstance(cond := task.ast.condition_map[loop_node.condition], Condition) and str(cond) == "i#0 != 0x3" assert isinstance(loop_body := loop_node.body, SeqNode) assert len(loop_body.children) == 3 @@ -1526,7 +1526,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_1(task): # make sure condition node is restructured correctly assert condition_node.condition.is_conjunction and len(operands := condition_node.condition.operands) == 2 - assert all(op.is_negation for op in operands) and {str(task._ast.condition_map[~op]) for op in operands} == {"x#0 != 0x3", "j#0 != 0x3"} + assert all(op.is_negation for op in operands) and {str(task.ast.condition_map[~op]) for op in operands} == {"x#0 != 0x3", "j#0 != 0x3"} assert isinstance(continue_node := condition_node.true_branch_child, CodeNode) and condition_node.false_branch is None assert continue_node.instructions == [Continue()] @@ -1799,12 +1799,12 @@ def test_restructure_cfg_loop_two_back_edges_condition_3(task): # if loop_middle.condition.is_symbol: # assert isinstance(loop_middle_seq := loop_middle.true_branch, SeqNode) # assert loop_middle.false_branch is None - # assert isinstance(cond := task._ast.condition_map[loop_middle.condition], Condition) and str(cond) == "i#0 != 0x3" + # assert isinstance(cond := task.ast.condition_map[loop_middle.condition], Condition) and str(cond) == "i#0 != 0x3" # else: # assert (loop_middle.condition).is_negation # assert isinstance(loop_middle_seq := loop_middle.false_branch, SeqNode) # assert loop_middle.true_branch is None - # assert isinstance(cond := task._ast.condition_map[loop_middle.condition.operands[0]], Condition) and str(cond) == "i#0 != 0x3" + # assert isinstance(cond := task.ast.condition_map[loop_middle.condition.operands[0]], Condition) and str(cond) == "i#0 != 0x3" # # # loop_middle_seq is restructured correctly: # assert len(loop_middle_seq.children) == 4 @@ -1814,12 +1814,12 @@ def test_restructure_cfg_loop_two_back_edges_condition_3(task): # if continue_branch.condition.is_symbol: # assert isinstance(cond_node := continue_branch.false_branch, CodeNode) # assert continue_branch.true_branch is None - # assert isinstance(cond := task._ast.condition_map[continue_branch.condition], Condition) and str(cond) == "x#0 != 0x3" + # assert isinstance(cond := task.ast.condition_map[continue_branch.condition], Condition) and str(cond) == "x#0 != 0x3" # else: # assert (continue_branch.condition).is_negation # assert isinstance(cond_node := continue_branch.true_branch, CodeNode) # assert continue_branch.false_branch is None - # assert isinstance(cond := task._ast.condition_map[continue_branch.condition.operands[0]], Condition) and str(cond) == "x#0 != 0x3" + # assert isinstance(cond := task.ast.condition_map[continue_branch.condition.operands[0]], Condition) and str(cond) == "x#0 != 0x3" # assert cond_node.stmts == vertices[3].instructions + ["continue"] # # assert isinstance(loop_middle_seq.children[2], CodeNode) and loop_middle_seq.children[2].stmts == vertices[4].instructions[:-1] @@ -1828,14 +1828,14 @@ def test_restructure_cfg_loop_two_back_edges_condition_3(task): # if is_and(break_branch.condition): # assert isinstance(break_branch.true_branch, CodeNode) and break_branch.true_branch.stmts == ["break"] # assert break_branch.false_branch is None - # assert isinstance(cond := task._ast.condition_map[break_branch.condition.operands[0]], Condition) and str(cond) == "x#0 != 0x3" - # assert isinstance(cond := task._ast.condition_map[break_branch.condition.operands[1].operands[0]], Condition) and str(cond) == "j#0 != 0x3" + # assert isinstance(cond := task.ast.condition_map[break_branch.condition.operands[0]], Condition) and str(cond) == "x#0 != 0x3" + # assert isinstance(cond := task.ast.condition_map[break_branch.condition.operands[1].operands[0]], Condition) and str(cond) == "j#0 != 0x3" # else: # assert is_or(break_branch.condition) # assert isinstance(break_branch.false_branch, CodeNode) and break_branch.false_branch.stmts == ["break"] # assert break_branch.true_branch is None - # assert isinstance(cond := task._ast.condition_map[break_branch.condition.operands[0].operands[0]], Condition) and str(cond) == "x#0 != 0x3" - # assert isinstance(cond := task._ast.condition_map[break_branch.condition.operands[1]], Condition) and str(cond) == "j#0 != 0x3" + # assert isinstance(cond := task.ast.condition_map[break_branch.condition.operands[0].operands[0]], Condition) and str(cond) == "x#0 != 0x3" + # assert isinstance(cond := task.ast.condition_map[break_branch.condition.operands[1]], Condition) and str(cond) == "j#0 != 0x3" def test_restructure_cfg_loop_two_back_edges_condition_4(task): @@ -1943,7 +1943,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_4(task): PatternIndependentRestructuring().run(task) # make sure that a LoopNode has been created during Restructuring - assert isinstance(seq_node := task._ast.root, SeqNode) + assert isinstance(seq_node := task.ast.root, SeqNode) assert len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[6].instructions @@ -1962,7 +1962,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_4(task): assert loop_middle.condition.is_symbol assert isinstance(loop_middle_seq := loop_middle.true_branch_child, SeqNode) assert loop_middle.false_branch is None - assert isinstance(cond := task._ast.condition_map[loop_middle.condition], Condition) and str(cond) == "i#0 != 0x3" + assert isinstance(cond := task.ast.condition_map[loop_middle.condition], Condition) and str(cond) == "i#0 != 0x3" # loop_middle_seq is restructured correctly: assert len(loop_middle_seq.children) == 4 @@ -1975,7 +1975,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_4(task): assert continue_branch.condition.is_negation assert isinstance(continue_branch.true_branch_child, CodeNode) and continue_branch.true_branch_child.instructions == [Continue()] assert continue_branch.false_branch is None - assert isinstance(cond := task._ast.condition_map[~continue_branch.condition], Condition) and str(cond) == "x#0 != 0x3" + assert isinstance(cond := task.ast.condition_map[~continue_branch.condition], Condition) and str(cond) == "x#0 != 0x3" assert isinstance(loop_middle_seq.children[2], CodeNode) and loop_middle_seq.children[2].instructions == vertices[4].instructions[:-1] # @@ -1983,7 +1983,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_4(task): assert break_branch.condition.is_negation assert isinstance(break_branch.true_branch_child, CodeNode) and break_branch.true_branch_child.instructions == [Break()] assert break_branch.false_branch is None - assert isinstance(cond := task._ast.condition_map[~break_branch.condition], Condition) and str(cond) == "j#0 != 0x3" + assert isinstance(cond := task.ast.condition_map[~break_branch.condition], Condition) and str(cond) == "j#0 != 0x3" def test_restructure_cfg_loop_two_back_edges_condition_5(task): @@ -2092,7 +2092,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_5(task): PatternIndependentRestructuring().run(task) # make sure that a LoopNode has been created during Restructuring - assert isinstance(seq_node := task._ast.root, SeqNode) + assert isinstance(seq_node := task.ast.root, SeqNode) assert len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].instructions == vertices[0].instructions assert isinstance(seq_node.children[2], CodeNode) and seq_node.children[2].instructions == vertices[7].instructions @@ -2113,7 +2113,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_5(task): assert loop_middle.condition.is_symbol assert isinstance(loop_middle_seq := loop_middle.true_branch_child, SeqNode) assert loop_middle.false_branch is None - assert isinstance(cond := task._ast.condition_map[loop_middle.condition], Condition) and str(cond) == "i#0 != 0x3" + assert isinstance(cond := task.ast.condition_map[loop_middle.condition], Condition) and str(cond) == "i#0 != 0x3" # loop_middle_seq is restructured correctly: assert len(loop_middle_seq.children) == 3 @@ -2126,7 +2126,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_5(task): assert continue_branch.condition.is_negation assert isinstance(continue_branch.true_branch_child, CodeNode) and continue_branch.true_branch_child.instructions == [Continue()] assert continue_branch.false_branch is None - assert isinstance(cond := task._ast.condition_map[~continue_branch.condition], Condition) and str(cond) == "x#0 != 0x3" + assert isinstance(cond := task.ast.condition_map[~continue_branch.condition], Condition) and str(cond) == "x#0 != 0x3" assert isinstance(loop_middle_seq.children[2], CodeNode) and loop_middle_seq.children[2].instructions == vertices[4].instructions @@ -2134,7 +2134,7 @@ def test_restructure_cfg_loop_two_back_edges_condition_5(task): assert break_condition.condition.is_negation assert isinstance(break_condition.true_branch_child, CodeNode) and break_condition.true_branch_child.instructions == [Break()] assert break_condition.false_branch is None - assert isinstance(cond := task._ast.condition_map[~break_condition.condition], Condition) and str(cond) == "j#0 != 0x3" + assert isinstance(cond := task.ast.condition_map[~break_condition.condition], Condition) and str(cond) == "j#0 != 0x3" def test_restructure_cfg_nested_loop_not_head(task): @@ -2230,14 +2230,14 @@ def test_restructure_cfg_nested_loop_not_head(task): PatternIndependentRestructuring().run(task) # make sure that a LoopNode has been created during Restructuring - assert isinstance(seq_node := task._ast.root, SeqNode) + assert isinstance(seq_node := task.ast.root, SeqNode) assert len(seq_node.children) == 3 assert isinstance(seq_node.children[0], CodeNode) assert isinstance(loop_node := seq_node.children[1], WhileLoopNode) assert isinstance(seq_node.children[2], CodeNode) # make sure that the loop has the correct type and condition - assert isinstance(cond := task._ast.condition_map[loop_node.condition], Condition) and str(cond) == "i#0 != 0x3" + assert isinstance(cond := task.ast.condition_map[loop_node.condition], Condition) and str(cond) == "i#0 != 0x3" assert isinstance(loop_body := loop_node.body, SeqNode) assert len(loop_body.children) == 2 @@ -2255,7 +2255,7 @@ def test_restructure_cfg_nested_loop_not_head(task): # Check condition node break assert cond_node.condition.is_negation - assert isinstance(cond := task._ast.condition_map[~cond_node.condition], Condition) + assert isinstance(cond := task.ast.condition_map[~cond_node.condition], Condition) assert isinstance(code_node := cond_node.true_branch_child, CodeNode) assert cond_node.false_branch is None assert str(cond) == "j#0 != 0x3" @@ -2381,7 +2381,7 @@ def test_dream_paper_fig3(task): ) PatternIndependentRestructuring().run(task) - assert isinstance(seq_node := task._ast.root, SeqNode) + assert isinstance(seq_node := task.ast.root, SeqNode) assert len(seq_node.children) == 2 assert isinstance(seq_node.children[1], CodeNode) assert isinstance(cond_node := seq_node.children[0], ConditionNode) @@ -2583,14 +2583,14 @@ def test_condition_based_corner_case_complementary_condition_yes(task): # PatternIndependentRestructuring().run(task) # make sure that a LoopNode has been created during Restructuring -# assert isinstance(seq_node := task._ast.root, SeqNode) +# assert isinstance(seq_node := task.ast.root, SeqNode) # assert len(seq_node.children) == 2 # assert isinstance(loop_node := seq_node.children[0], LoopNode) # assert isinstance(seq_node.children[1], CodeNode) and seq_node.children[1].stmts == vertices[6].instructions # make sure that the loop has the correct type and condition # assert loop_node.type == "do_while" -# assert isinstance(cond := task._ast.condition_map[loop_node.condition], Condition) and cond == vertices[5].instructions[-1].condition +# assert isinstance(cond := task.ast.condition_map[loop_node.condition], Condition) and cond == vertices[5].instructions[-1].condition # assert isinstance(loop_body := loop_node.body, SeqNode) # assert len(loop_body.children) == 2 # assert isinstance(complementary_cond := loop_body.children[0], ConditionNode) @@ -2602,19 +2602,19 @@ def test_condition_based_corner_case_complementary_condition_yes(task): # assert is_or(complementary_cond.condition) or is_and(complementary_cond.condition) # arg_1, arg_2 = complementary_cond.condition.operands # if is_or(complementary_cond.condition): -# assert isinstance(cond_1 := task._ast.condition_map[arg_1.operands[0]], Condition) -# assert isinstance(cond_2 := task._ast.condition_map[arg_2.operands[0]], Condition) +# assert isinstance(cond_1 := task.ast.condition_map[arg_1.operands[0]], Condition) +# assert isinstance(cond_2 := task.ast.condition_map[arg_2.operands[0]], Condition) # assert complementary_cond.true_branch.stmts == vertices[4].instructions # assert complementary_cond.false_branch.stmts == vertices[3].instructions # else: -# assert isinstance(cond_1 := task._ast.condition_map[arg_1], Condition) -# assert isinstance(cond_2 := task._ast.condition_map[arg_2], Condition) +# assert isinstance(cond_1 := task.ast.condition_map[arg_1], Condition) +# assert isinstance(cond_2 := task.ast.condition_map[arg_2], Condition) # assert complementary_cond.false_branch.stmts == vertices[4].instructions # assert complementary_cond.true_branch.stmts == vertices[3].instructions # assert {cond_1, cond_2} == {vertices[1].instructions[0].condition, vertices[2].instructions[0].condition} # logging.info(f"Abstract syntax tree of this region:") -# for node in task._ast.topological_order(): +# for node in task.ast.topological_order(): # logging.info(f"Node {node}") # if isinstance(node, CodeNode): # logging.info(f"statements: {[str(inst) for inst in node.stmts]}") @@ -2712,7 +2712,7 @@ def test_condition_based_corner_case_complementary_condition_yes(task): # PatternIndependentRestructuring().run(task) # # # logging.info(f"Abstract syntax tree of this region:") -# # for node in task._ast.topological_order(): +# # for node in task.ast.topological_order(): # # logging.info(f"Node {node}") # # if isinstance(node, CodeNode): # # logging.info(f"statements: {[str(inst) for inst in node.stmts]}") @@ -2760,7 +2760,7 @@ def test_condition_based_corner_case_complementary_condition_yes(task): # PatternIndependentRestructuring().run(task) # # # root node -# assert isinstance(seq_node := task._ast.root, SeqNode) +# assert isinstance(seq_node := task.ast.root, SeqNode) # assert len(seq_node.children) == 4 # assert isinstance(seq_node.children[0], CodeNode) and seq_node.children[0].stmts == [vertices[0].instructions[0]] # assert isinstance(condition_root := seq_node.children[1], ConditionNode) @@ -2769,11 +2769,11 @@ def test_condition_based_corner_case_complementary_condition_yes(task): # # # make sure that the root note condition is restructured correctly # if condition_root.condition.is_negation: -# assert task._ast.condition_map[condition_root.condition.operands[0]] == vertices[0].instructions[-1].condition +# assert task.ast.condition_map[condition_root.condition.operands[0]] == vertices[0].instructions[-1].condition # assert isinstance(condition_root.true_branch, CodeNode) and condition_root.true_branch.stmts == [vertices[2].instructions[0]] # assert isinstance(condition_root.false_branch, CodeNode) and condition_root.false_branch.stmts == vertices[1].instructions # else: -# assert task._ast.condition_map[condition_root.condition] == vertices[0].instructions[-1].condition +# assert task.ast.condition_map[condition_root.condition] == vertices[0].instructions[-1].condition # assert isinstance(condition_root.false_branch, CodeNode) and condition_root.false_branch.stmts == [vertices[2].instructions[0]] # assert isinstance(condition_root.true_branch, CodeNode) and condition_root.true_branch.stmts == vertices[1].instructions # @@ -2781,14 +2781,14 @@ def test_condition_based_corner_case_complementary_condition_yes(task): # cond = complementary_cond.condition # assert len(cond.operands) == 2 and (is_and(cond) or is_or(cond)) # if is_and(cond): -# assert {task._ast.condition_map[cond.arg.operands[0](0)], task._ast.condition_map[cond.arg.operands[0](1)]} == { +# assert {task.ast.condition_map[cond.arg.operands[0](0)], task.ast.condition_map[cond.arg.operands[0](1)]} == { # vertices[0].instructions[-1].condition, # vertices[2].instructions[-1].condition, # } # assert isinstance(complementary_cond.true_branch, CodeNode) and complementary_cond.true_branch.stmts == vertices[7].instructions # assert isinstance(ifelse_node_3 := complementary_cond.false_branch, SeqNode) # else: -# assert {task._ast.condition_map[cond.operands[0]], task._ast.condition_map[cond.operands[1]]} == { +# assert {task.ast.condition_map[cond.operands[0]], task.ast.condition_map[cond.operands[1]]} == { # vertices[0].instructions[-1].condition, # vertices[2].instructions[-1].condition, # } @@ -2802,7 +2802,7 @@ def test_condition_based_corner_case_complementary_condition_yes(task): # assert isinstance(ifelse_node_3.children[2], CodeNode) and ifelse_node_3.children[2].stmts == vertices[6].instructions # # if ifelse_node_3_cond.condition.is_negation: -# assert task._ast.condition_map[ifelse_node_3_cond.condition.operands[0]] == vertices[3].instructions[-1].condition +# assert task.ast.condition_map[ifelse_node_3_cond.condition.operands[0]] == vertices[3].instructions[-1].condition # assert isinstance(ifelse_node_3_cond.true_branch, CodeNode) and ifelse_node_3_cond.true_branch.stmts == vertices[5].instructions # assert isinstance(ifelse_node_3_cond.false_branch, CodeNode) and ifelse_node_3_cond.false_branch.stmts == vertices[4].instructions # else: diff --git a/tests/pipeline/controlflowanalysis/test_pattern_independent_restructuring_blackbox.py b/tests/pipeline/controlflowanalysis/test_pattern_independent_restructuring_blackbox.py index 2677884f2..35e6c521f 100644 --- a/tests/pipeline/controlflowanalysis/test_pattern_independent_restructuring_blackbox.py +++ b/tests/pipeline/controlflowanalysis/test_pattern_independent_restructuring_blackbox.py @@ -12,15 +12,13 @@ from decompiler.structures.ast.ast_nodes import ConditionNode, SeqNode, SwitchNode from decompiler.structures.ast.condition_symbol import ConditionHandler from decompiler.structures.ast.reachability_graph import SiblingReachabilityGraph -from decompiler.structures.ast.switch_node_handler import ExpressionUsages from decompiler.structures.ast.syntaxforest import AbstractSyntaxForest from decompiler.structures.graphs.cfg import BasicBlock, ControlFlowGraph, FalseCase, TrueCase, UnconditionalEdge -from decompiler.structures.pseudo.expressions import Constant, ImportedFunctionSymbol, Variable +from decompiler.structures.pseudo.expressions import Constant, Variable from decompiler.structures.pseudo.instructions import Assignment, Branch, Return from decompiler.structures.pseudo.operations import BinaryOperation, Condition, OperationType from decompiler.structures.pseudo.typing import CustomType, Integer from decompiler.task import DecompilerTask -from decompiler.util.decoration import DecoratedCFG var_b = Variable("b", Integer.int32_t()) var_c = Variable("c", Integer.int32_t()) @@ -45,7 +43,7 @@ def test_no_crash_missing_case_finder(task): var_4 = Variable("var_4", Integer(32, False), ssa_name=Variable("rbx_2", Integer(32, False), 2)) var_5 = Variable("var_5", Integer(32, False), ssa_name=Variable("rax_1", Integer(32, False), 2)) var_6 = Variable("var_6", Integer(32, False), ssa_name=Variable("rax_2", Integer(32, False), 2)) - task._cfg.add_nodes_from( + task.cfg.add_nodes_from( [ b0 := BasicBlock( 0, @@ -76,7 +74,7 @@ def test_no_crash_missing_case_finder(task): ), ] ) - task._cfg.add_edges_from( + task.cfg.add_edges_from( [ TrueCase(b0, b1), FalseCase(b0, b3),