pub enum Stmt {
Show 18 variants
Error,
Empty,
Expr(ExprId),
Block(StmtList),
Decls(DeclList),
If {
cond: ExprId,
then: StmtId,
otherwise: Option<StmtId>,
},
While {
cond: ExprId,
body: StmtId,
},
DoWhile {
body: StmtId,
cond: ExprId,
},
For {
init: Option<StmtId>,
cond: Option<ExprId>,
step: Option<ExprId>,
body: StmtId,
},
Switch {
cond: ExprId,
body: StmtId,
cases: CaseList,
default: Option<StmtId>,
},
Case {
case: CaseId,
body: StmtId,
},
Default {
body: StmtId,
},
Label {
label: LabelId,
body: StmtId,
},
Goto(LabelId),
IndirectGoto(ExprId),
Break,
Continue,
Return(Option<ExprId>),
}Expand description
A statement.
Variants§
Error
A statement that was already the subject of a diagnostic.
Empty
;, which is a statement and does nothing.
Expr(ExprId)
An expression evaluated for its effects, whose value is discarded.
Block(StmtList)
{ ... }, which is also a scope, though the scope has been resolved by now.
Decls(DeclList)
The declarations of one declaration statement, which introduce objects into the block.
If
if (cond) then else otherwise.
Fields
While
while (cond) body.
DoWhile
do body while (cond);.
Fields
For
for (init; cond; step) body.
Fields
Switch
switch (cond) body.
Fields
cases: CaseListWhere each value goes, collected here so that the walk to the IR builds a jump table from a table rather than by searching the body for labels.
default: Option<StmtId>Where a value that matches nothing goes, absent when there is no default, which
is the same statement the Stmt::Default in the body labels.
Case
case value:, which is a label on the statement it precedes.
The value is in the case table rather than here, because two i128 bounds would make
every statement in the arena the size of the widest one.
Fields
Default
default:, which is a label and not a case, since it has no value to be in a table.
It is here as well as in the enclosing switch because the two say different things:
this says where in the body it was written, and the field on the switch is the entry
of the jump table. A reader that only had the field could not say where default: went.
Label
name: body, with the label resolved.
Goto(LabelId)
goto name;, with the label resolved.
IndirectGoto(ExprId)
goto *expr;, GNU’s computed goto, whose target is a label address.
Break
break;, which leaves the innermost loop or switch.
Continue
continue;, which starts the next iteration of the innermost loop.
Return(Option<ExprId>)
return; or return expr;, with the value already converted to the return type.