-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Switch Restructuring] Insert CaseNodes #257
[Switch Restructuring] Insert CaseNodes #257
Conversation
0d7cd32
to
b4c110e
Compare
b4c110e
to
fac0f4e
Compare
@@ -197,6 +200,15 @@ def _get_possible_case_candidate_for(self, ast_node: AbstractSyntaxTreeNode) -> | |||
|
|||
return None | |||
|
|||
def _clean_up_reachability(self, possible_switch_node: SwitchNodeCandidate, sibling_reachability): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing a cod string here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
@@ -348,45 +364,26 @@ def _update_reaching_condition_of(self, case_node: CaseNode, considered_conditio | |||
:param case_node: The case node where we want to update the reaching condition. | |||
:param considered_conditions: The conditions (literals) that are already fulfilled when we reach the given case node. | |||
""" | |||
literals_of_case_node = set(case_node.reaching_condition.get_literals()) | |||
# literals_of_case_node = set(case_node.reaching_condition.get_literals()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
literals_of_case_node.remove(literal_of_case) | ||
for constant, literal in considered_conditions.items(): | ||
if constant in constant_of_case_node_literal: | ||
del constant_of_case_node_literal[constant] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use dict.pop(<key>)
instead? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed, but here I think it makes no difference
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed it
if (intersecting_linear_case := self.__get_linear_order_intersection_constants(intersection_cases)) is None: | ||
return | ||
compare_node = possible_case.get_head | ||
# Insert content before case-node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come you didn't divide this into smaller functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your three comments suggest that you have three behaviours that could be their own functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I partially extracted functions, hope this makes it better
self.__resort_cases(common_cases + uncommon_cases, old_children_order) | ||
return common_cases[-1] | ||
|
||
def _add_case_behind(self, intersecting_linear_case: Tuple[CaseNode], possible_case_properties: IntersectingCaseNodeProperties): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*_add_case_after
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, add doc-string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if common_cases or uncommon_cases: | ||
yield common_cases, uncommon_cases | ||
|
||
def __resort_cases(self, new_case_order: List[CaseNode], old_case_children: List[AbstractSyntaxTreeNode]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc-string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
assert (parent := self.have_same_parent(combinable_switch_nodes)) is not None, "All switch nodes must have the same parent." | ||
assert isinstance(parent, SeqNode), "The parent of all switches must be a Sequence node." | ||
self._add_node(new_switch_node := self.factory.create_switch_node(combinable_switch_nodes[0].expression)) | ||
self._add_edge(parent, new_switch_node) | ||
switch_node_cases: Dict[SwitchNode, List[CaseNode]] = dict() | ||
# python decompile.py ../../Downloads/test_condition_for_eva test17 --debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
closes #20