Add jumps support in do while loops #29
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously
do while
loops were parsed as normalwhile
loops with a copy of body inserted before a loop. If there wasbreak
statement inside a body, the error was thrown:break isn't underneath a loop
. Similar situation was withcontinue
statement. So I created separate node for that kind of loop and I added converting it intowhile
loop in V3LinkJump, whenbreak
andcontinue
statements are handled.Now I explain the change in
addPrev
implementation. Without it, the statementwhilep->addPrev(bodyp->cloneTree(false));
moved
whilep
node at the end of statements in a block.Here is an example:
In the example, the inner
while
is put after postincrementation and break stataments.Here is the AST (without the change, PREADD and POSTADD subtrees are shortened):
And the one after the change (correct one):
So old
addPrev
implementation breaks the order of other nodes, which sometimes may cause a different behavior.