Skip to content
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

Refine Initial Switch Construction #113

Closed
jnhols opened this issue Sep 1, 2022 · 2 comments · Fixed by #114
Closed

Refine Initial Switch Construction #113

jnhols opened this issue Sep 1, 2022 · 2 comments · Fixed by #114
Assignees
Labels
feature-request New feature or request

Comments

@jnhols
Copy link
Collaborator

jnhols commented Sep 1, 2022

Proposal

Detect switch nodes in nested if-conditions.
More precisely, when restructuring test6 of binary test_condition.zip we do not reconstruct a switch, although it would improve readability.
The CFG before the restructuring has the following form:
switch_cfg
The restructuring starts with the region containing nodes 12, 14, and 15 and restructures it as an if-else. Step by step the restructuring adds first nodes 10 & 13, then 8 & 11, and so on to the region. Thus, we never have a sequence node where we start the initial switch node. Therefore, the resulting AST has the following form:
switch_ast

Approach

Improve the InitialSwitchConstructer as follows:

In the function construct we first iterate over all sequence nodes. Add a second iteration over all conditions nodes with a body trying to construct an initial switch node from a condition node, i.e., something like initial_switch_constructor._try_to_construct_initial_switch_from_condition(cond_node).

The condition node must have a concrete structure.

  • Check whether the condition of the condition node is expr == const1 or expr != const2.
  • In the second case switch the branches (condition_node.switch_branches())
  • Check whether the false_branch is also a condition node whose condition is expr == const2 or expr != const2. The compared expression of both conditions must be the same.
  • Again, in the second case, switch the branches.
  • Now, the two true branches are two cases of a switch node and we can construct an initial
    Here, is a possible reconstruction of a sequence node where two children are possible case nodes of a switch node.
    switch_from_comdition
@jnhols jnhols added the feature-request New feature or request label Sep 1, 2022
@jnhols jnhols self-assigned this Sep 1, 2022
@jnhols
Copy link
Collaborator Author

jnhols commented Sep 1, 2022

/cib

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2022

Branch issue-113-Refine_Initial_Switch_Construction created!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant