Enum naga::back::continue_forward::Nesting
source · enum Nesting {
Loop,
Switch {
variable: Rc<String>,
continue_encountered: bool,
},
}
Expand description
A summary of the code surrounding a statement.
Variants§
Loop
Currently nested in at least one Loop
statement.
Continue
should apply to the innermost loop.
When this entry is on the top of the stack:
-
When entering an inner
Loop
statement, push aLoop
state onto the stack. -
When entering a nested
Switch
statement, push aSwitch
state onto the stack with a new variable name. Before the generatedswitch
, introduce abool
local with that name, initialized tofalse
.
When exiting the Loop
for which this entry was pushed, pop it from
the stack.
Switch
Currently nested in at least one Switch
that may need to forward
Continue
s.
This includes Switch
es rendered as do {} while(false)
loops, but
doesn’t need to include regular Switch
es in backends that can
support continue
within switches.
Continue
should be forwarded to the innermost surrounding Loop
.
When this entry is on the top of the stack:
-
When entering a nested
Loop
, push aLoop
state onto the stack. -
When entering a nested
Switch
, push aSwitch
state onto the stack with a clone of the introducedbool
variable’s name. -
When encountering a
Continue
statement, render it as code to set the introducedbool
local (whose name is held invariable
) totrue
, and thenbreak
. Setcontinue_encountered
totrue
to record that theSwitch
contains aContinue
. -
When exiting this
Switch
, pop its entry from the stack. Ifcontinue_encountered
is set, then we have renderedContinue
statements asbreak
statements that jump to this point. Generate code to checkvariable
, and if it istrue
:
When we exit the Switch
for which this entry was pushed, pop it.
Fields
continue_encountered: bool
Set if we’ve generated code for a Continue
statement with this
entry on the top of the stack.
If this is still clear when we finish rendering the Switch
, then
we know we don’t need to generate branch forwarding code. Omitting
that may make it easier for drivers to tell that the bool
we
introduced ahead of the Switch
is actually unused.