Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

transStmtExpr

Translator.transStmtExpr
fn transStmtExpr(
    t: *Translator,
    scope: *Scope,
    stmt_expr: Node.Unary,
    used: ResultUsed,
) TransError!ZigNode

File

lib/compiler/translate-c/Translator.zig:3933

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();
}