fullBodyExpr
Similar to expr, but intended for use when gz corresponds to a body
which will contain only this node's code. Differs from expr in that if the
root expression is an unlabeled block, does not emit an actual block.
Instead, the block contents are emitted directly into gz.
Function parameters
Parameters
- gz:*GenZir
- scope:*Scope
- node:Ast.Node.Index
Functions in this namespace
Functions
Source
Implementation
fn fullBodyExpr(
gz: *GenZir,
scope: *Scope,
ri: ResultInfo,
node: Ast.Node.Index,
block_kind: BlockKind,
) InnerError!Zir.Inst.Ref {
const tree = gz.astgen.tree;
var stmt_buf: [2]Ast.Node.Index = undefined;
const statements = tree.blockStatements(&stmt_buf, node) orelse
return expr(gz, scope, ri, node);
const lbrace = tree.nodeMainToken(node);
if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) {
// Labeled blocks are tricky - forwarding result location information properly is non-trivial,
// plus if this block is exited with a `break_inline` we aren't allowed multiple breaks. This
// case is rare, so just treat it as a normal expression and create a nested block.
return blockExpr(gz, scope, ri, node, statements, block_kind);
}
var sub_gz = gz.makeSubBlock(scope);
try blockExprStmts(&sub_gz, &sub_gz.base, statements, block_kind);
return rvalue(gz, ri, .void_value, node);
}