feature. See also
. The project being documented here (as the example) is the Zig library itself.
Translator.transStmtExpr
fn transStmtExpr(
t: *Translator,
scope: *Scope,
stmt_expr: Node.Unary,
used: ResultUsed,
) TransError!ZigNode
File
Code
fn transStmtExpr(
t: *Translator,
scope: *Scope,
stmt_expr: Node.Unary,
used: ResultUsed,
) TransError!ZigNode {
const compound_stmt = stmt_expr.operand.get(t.tree).compound_stmt;
if (used == .unused) {
return t.transCompoundStmt(scope, compound_stmt);
}
var block_scope = try Scope.Block.init(t, scope, true);
defer block_scope.deinit();
for (compound_stmt.body[0 .. compound_stmt.body.len - 1]) |stmt| {
const result = try t.transStmt(&block_scope.base, stmt);
switch (result.tag()) {
.declaration, .empty_block => {},
else => try block_scope.statements.append(t.gpa, result),
}
}
const last_result = try t.transExpr(&block_scope.base, compound_stmt.body[compound_stmt.body.len - 1], .used);
switch (last_result.tag()) {
.declaration, .empty_block => {},
else => {
const break_node = try ZigTag.break_val.create(t.arena, .{
.label = block_scope.label,
.val = last_result,
});
try block_scope.statements.append(t.gpa, break_node);
},
}
return block_scope.complete();
}