feature. See also
. The project being documented here (as the example) is the Zig library itself.
AstGen.deferStmt
fn deferStmt(
gz: *GenZir,
scope: *Scope,
node: Ast.Node.Index,
block_arena: Allocator,
scope_tag: Scope.Tag,
) InnerError!*Scope
File
Code
fn deferStmt(
gz: *GenZir,
scope: *Scope,
node: Ast.Node.Index,
block_arena: Allocator,
scope_tag: Scope.Tag,
) InnerError!*Scope {
var defer_gen = gz.makeSubBlock(scope);
defer_gen.cur_defer_node = node.toOptional();
defer_gen.any_defer_node = node.toOptional();
defer defer_gen.unstack();
const tree = gz.astgen.tree;
const expr_node = tree.nodeData(node).node;
_ = try unusedResultExpr(&defer_gen, &defer_gen.base, expr_node);
try checkUsed(gz, scope, &defer_gen.base);
_ = try defer_gen.addBreak(.break_inline, @fromBackingInt(@intCast(0)), .void_value);
const body = defer_gen.instructionsSlice();
const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(body, &.{});
const index: u32 = @intCast(gz.astgen.extra.items.len);
try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len);
gz.astgen.appendBodyWithFixupsExtraRefsArrayList(&gz.astgen.extra, body, &.{});
const defer_scope = try block_arena.create(Scope.Defer);
defer_scope.* = .{
.base = .{ .tag = scope_tag },
.parent = scope,
.index = index,
.len = body_len,
};
return &defer_scope.base;
}