pub struct Switch {
pub id: SwitchId,
pub scrutinee: Expr,
pub hoisted: Vec<ObjectId>,
pub prelude: Vec<Stmt>,
pub groups: Vec<SwitchGroup>,
pub default_group: Option<usize>,
pub range: SourceRange,
}Expand description
A switch statement, flattened into the groups its labels delimit.
The body of a switch is a single statement that execution jumps into,
which is why it cannot be a tree here: the labels split it into a sequence
of groups that fall through into one another. See codegen
for how the sequence becomes Rust.
Fields§
§id: SwitchIdThis switch’s identity.
scrutinee: ExprThe controlling expression, after the integer promotions.
hoisted: Vec<ObjectId>Objects declared directly in the switch body.
C keeps them alive for the whole body even though execution may jump past their declaration, so they are defined ahead of the dispatch and zero-initialised; whatever initialiser the source wrote stays where it was written, as an assignment.
prelude: Vec<Stmt>Statements between the { and the first label. C can never reach them.
groups: Vec<SwitchGroup>The groups, in source order.
default_group: Option<usize>The index in groups that default: labels, if any.
range: SourceRangeWhere the statement was written.