dewolf icon indicating copy to clipboard operation
dewolf copied to clipboard

[Restructuring] Constructing initial switch

Open ebehner opened this issue 3 years ago • 0 comments

Proposal

When constructing the initial switch we face two problems:

  1. We only consider the symbol of the condition and not the actual condition
  2. When two switch nodes belong to the same case constant we randomly choose one.

Consider test18 in sample test_condition.zip During the restructuring we have the following AST: 1_00_before Nodes 3, 11, and 12 are possible cases for a switch with variable var_0. However, node 3 and node 12 would belong to case constant 1. Nevertheless, we do not remove one of them, because the conditions belong to two different symbols. The first task would be to change this, such that we already check that these conditions are not the same. When these conditions are considered the same, then we would randomly remove one of them. However, only nodes 11 and 12 can be cases of a switch node due to the reachability of the nodes. One can see this by having a look at the sibling reachability graph of the sequence node (node 1), the green marked nodes belong to the possible switch cases: sibling_reachability2 Now, the second task would be to decide which case to choose when two possible cases have the same condition and only one can be picked.*

Approach

The two problems should be handled in _remove_case_candidates_with_same_condition in initial_switch_node_constructer.

For checking for the same condition, there are two options, either directly compute the possible cases or transform them into the "real" conditions and check for equality.

The second task is a bit more difficult. One could compute the sibling reachability without these nodes and check which could be added or the one that is only a code-node and not a condition node if this is the case. But this part requires a few more considerations.

ebehner avatar Jan 20 '22 11:01 ebehner