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.

transSwitchProngStmtInline

Collects all statements seen by this case into a block.

Translator.transSwitchProngStmtInline
fn transSwitchProngStmtInline(
    t: *Translator,
    block: *Scope.Block,
    body: []const Node.Index,
) TransError!void

File

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

Code

fn transSwitchProngStmtInline(
    t: *Translator,
    block: *Scope.Block,
    body: []const Node.Index,
) TransError!void {
    for (body) |stmt| {
        switch (stmt.get(t.tree)) {
            .case_stmt => |case_stmt| {
                var sub = case_stmt.body;
                while (true) switch (sub.get(t.tree)) {
                    .case_stmt => |sub_case| sub = sub_case.body,
                    .default_stmt => |sub_default| sub = sub_default.body,
                    else => break,
                };
                const result = try t.transStmt(&block.base, sub);
                assert(result.tag() != .declaration);
                try block.statements.append(t.gpa, result);
                if (result.isNoreturn()) return;
            },
            .default_stmt => |default_stmt| {
                var sub = default_stmt.body;
                while (true) switch (sub.get(t.tree)) {
                    .case_stmt => |sub_case| sub = sub_case.body,
                    .default_stmt => |sub_default| sub = sub_default.body,
                    else => break,
                };
                const result = try t.transStmt(&block.base, sub);
                assert(result.tag() != .declaration);
                try block.statements.append(t.gpa, result);
                if (result.isNoreturn()) return;
            },
            else => {
                const result = try t.transStmt(&block.base, stmt);
                switch (result.tag()) {
                    .declaration, .empty_block => {},
                    else => {
                        try block.statements.append(t.gpa, result);
                        if (result.isNoreturn()) return;
                    },
                }
            },
        }
    }
}