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.
This is my attempt at adding support for for-else (issue #1442, according to czgdp1807's comment).
A new ASR node
ForElse
is added. Invisit_For()
atpython_ast_to_asr.cpp
, loops with non-zeron_orelse
are converted toForElse
.An ASR pass
"for_else", &pass_replace_forelse}
is added, which consists of two steps:ForElseVisitor
:ForElse
is visited and converted toDoLoop
with an initial assignment to a boolean flag variable (_no_break_N
), and anIf
block at the end that executesorelse
as long as the flag remains true. The flag variable corresponding to theDoLoop
is recorded indoLoopFlagMap
.ExitVisitor
:Exit
is visited, and its enclosingDoLoop
is recorded in a stack. If anExit
is found, and the enclosingDoLoop
is originally aForElse
, the corresponding flag is set to false.Some tests are added, under
tests/for_else
.