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.

maybeBlockify

If a statement can possibly translate to a Zig assignment (either directly because it's an assignment in C or indirectly via result assignment to _) AND it's the sole statement in the body of an if statement or loop, then we need to put the statement into its own block. The else case here corresponds to statements that could result in an assignment. If a statement class never needs a block, add its enum to the top prong.

Translator.maybeBlockify
fn maybeBlockify(t: *Translator, scope: *Scope, stmt: Node.Index) TransError!ZigNode

File

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

Code

fn maybeBlockify(t: *Translator, scope: *Scope, stmt: Node.Index) TransError!ZigNode {
    switch (stmt.get(t.tree)) {
        .break_stmt,
        .continue_stmt,
        .compound_stmt,
        .decl_ref_expr,
        .enumeration_ref,
        .do_while_stmt,
        .for_stmt,
        .if_stmt,
        .return_stmt,
        .null_stmt,
        .while_stmt,
        => return t.transStmt(scope, stmt),
        else => return t.blockify(scope, stmt),
    }
}