Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
ebehner committed Jun 27, 2023
1 parent 309e761 commit 0d7cd32
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from typing import Dict, Iterator, Optional, Set, Tuple

from decompiler.structures.ast.ast_nodes import AbstractSyntaxTreeNode, CaseNode, SwitchNode, TrueNode, FalseNode
from decompiler.structures.ast.ast_nodes import AbstractSyntaxTreeNode, CaseNode, FalseNode, SwitchNode, TrueNode
from decompiler.structures.ast.condition_symbol import ConditionHandler
from decompiler.structures.ast.switch_node_handler import ExpressionUsages, SwitchNodeHandler
from decompiler.structures.ast.syntaxforest import AbstractSyntaxForest
Expand All @@ -17,6 +17,7 @@ class CaseNodeCandidate:
-> node is the AST node that we want to have as a case node
-> The condition that the new case node should get.
"""

node: AbstractSyntaxTreeNode
expression: Optional[ExpressionUsages]
condition: LogicCondition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,13 @@ def prepend_empty_cases_to_case_with_or_condition(self, case: CaseNode) -> List[
Given a case node whose reaching condition is a disjunction of literals, we create one case node for each literal and return
the list of new case nodes.
"""
condition_for_constant: Dict[Constant, LogicCondition] = {c: l for l, c in self.asforest.switch_node_handler.get_literal_and_constant_for(case.reaching_condition)}
condition_for_constant: Dict[Constant, LogicCondition] = {
c: l for l, c in self.asforest.switch_node_handler.get_literal_and_constant_for(case.reaching_condition)
}
if None in condition_for_constant:
raise ValueError(
f"The case node should have a reaching-condition that is a disjunction of literals, but it has the clause {condition_for_constant[None]}."
)
f"The case node should have a reaching-condition that is a disjunction of literals, but it has the clause {condition_for_constant[None]}."
)
sorted_constants: List[Constant] = sorted(condition_for_constant, key=lambda constant: constant.value)
fallthrough_cases = self.asforest.split_case_node(case, sorted_constants)
for case in fallthrough_cases:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Set, List, Optional, Tuple
from typing import List, Optional, Set, Tuple

from decompiler.pipeline.controlflowanalysis.restructuring_commons.condition_aware_refinement_commons.base_class_car import (
CaseNodeCandidate,
)
from decompiler.pipeline.controlflowanalysis.restructuring_commons.condition_aware_refinement_commons.missing_case_finder import (
MissingCaseFinder,
)
from decompiler.structures.ast.ast_nodes import CaseNode, SwitchNode, TrueNode, FalseNode
from decompiler.structures.ast.ast_nodes import CaseNode, FalseNode, SwitchNode, TrueNode
from decompiler.structures.ast.reachability_graph import SiblingReachabilityGraph
from decompiler.structures.ast.syntaxforest import AbstractSyntaxForest
from decompiler.structures.pseudo import Constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from decompiler.pipeline.controlflowanalysis.restructuring_commons.condition_aware_refinement_commons.missing_case_finder import (
MissingCaseFinder,
)
from decompiler.pipeline.controlflowanalysis.restructuring_commons.condition_aware_refinement_commons.missing_case_finder_intersecting_constants import \
MissingCaseFinderIntersectingConstants
from decompiler.pipeline.controlflowanalysis.restructuring_commons.condition_aware_refinement_commons.missing_case_finder_intersecting_constants import (
MissingCaseFinderIntersectingConstants,
)
from decompiler.structures.ast.ast_nodes import AbstractSyntaxTreeNode, CaseNode, ConditionNode, FalseNode, SeqNode, SwitchNode, TrueNode
from decompiler.structures.ast.reachability_graph import SiblingReachabilityGraph
from decompiler.structures.ast.switch_node_handler import ExpressionUsages
Expand Down Expand Up @@ -169,12 +170,16 @@ def _add_new_case_nodes_to_switch_node(
switch_node = self._switch_node_of_expression[expression]
cases_of_switch_node: Set[Constant] = {case.constant for case in switch_node.children}
# case_constants_for_node: Dict[AbstractSyntaxTreeNode, Set[Constant]] = dict()
missing_case_finder_intersecting_constants = MissingCaseFinderIntersectingConstants(self.asforest, switch_node, sibling_reachability_graph)
missing_case_finder_intersecting_constants = MissingCaseFinderIntersectingConstants(
self.asforest, switch_node, sibling_reachability_graph
)
# TODO: order may be important!!!
for possible_case in case_node_candidates:
if not self._can_insert_case_node(possible_case, switch_node, sibling_reachability_graph):
continue
if any(case_constant in cases_of_switch_node for case_constant in self._get_case_constants_for_condition(possible_case.condition)):
if any(
case_constant in cases_of_switch_node for case_constant in self._get_case_constants_for_condition(possible_case.condition)
):
missing_case_finder_intersecting_constants.insert(possible_case)
else:
case_constants_for_possible_case_node = set(self._get_case_constants_for_condition(possible_case.condition))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5000,7 +5000,8 @@ def test_hash_eq_problem(task):
],
),
BasicBlock(9, instructions=[Assignment(arg1, Constant(1, Integer.int32_t()))]),
BasicBlock(10, instructions=[Return([arg1])]), ]
BasicBlock(10, instructions=[Return([arg1])]),
]
)
task.graph.add_edges_from(
[
Expand All @@ -5022,12 +5023,14 @@ def test_hash_eq_problem(task):
]
)
PatternIndependentRestructuring().run(task)
from decompiler.util.decoration import DecoratedAST
DecoratedAST.from_ast(task.syntax_tree).export_plot("/home/eva/Projects/dewolf/AST/z_ast.png")
assert any(isinstance(node, SwitchNode) for node in task.syntax_tree)
var_2_conditions = []
for node in task.syntax_tree.get_condition_nodes_post_order():
if not node.condition.is_symbol and node.condition.is_literal and str(task.syntax_tree.condition_map[~node.condition]) in {"var_2 != 0x0"}:
if (
not node.condition.is_symbol
and node.condition.is_literal
and str(task.syntax_tree.condition_map[~node.condition]) in {"var_2 != 0x0"}
):
node.switch_branches()
if node.condition.is_symbol and str(task.syntax_tree.condition_map[node.condition]) in {"var_2 != 0x0"}:
var_2_conditions.append(node)
Expand Down

0 comments on commit 0d7cd32

Please sign in to comment.