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.

transStmt

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

File

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

Code

fn transStmt(t: *Translator, scope: *Scope, stmt: Node.Index) TransError!ZigNode {
    switch (stmt.get(t.tree)) {
        .compound_stmt => |compound| {
            return t.transCompoundStmt(scope, compound);
        },
        .static_assert => |static_assert| {
            try t.transStaticAssert(scope, static_assert);
            return ZigTag.declaration.init();
        },
        .return_stmt => |return_stmt| return t.transReturnStmt(scope, return_stmt),
        .null_stmt => return ZigTag.empty_block.init(),
        .if_stmt => |if_stmt| return t.transIfStmt(scope, if_stmt),
        .while_stmt => |while_stmt| return t.transWhileStmt(scope, while_stmt),
        .do_while_stmt => |do_while_stmt| return t.transDoWhileStmt(scope, do_while_stmt),
        .for_stmt => |for_stmt| return t.transForStmt(scope, for_stmt),
        .continue_stmt => return ZigTag.@"continue".init(),
        .break_stmt => return ZigTag.@"break".init(),
        .typedef => |typedef_decl| {
            assert(!typedef_decl.implicit);
            try t.transTypeDef(scope, stmt);
            return ZigTag.declaration.init();
        },
        .struct_decl, .union_decl => |record_decl| {
            try t.transRecordDecl(scope, record_decl.container_qt);
            return ZigTag.declaration.init();
        },
        .struct_forward_decl, .union_forward_decl => |record_decl| {
            if (record_decl.definition) |some| {
                return t.transStmt(scope, some);
            }
            try t.transRecordDecl(scope, record_decl.container_qt);
            return ZigTag.declaration.init();
        },
        .enum_decl => |enum_decl| {
            try t.transEnumDecl(scope, enum_decl.container_qt);
            return ZigTag.declaration.init();
        },
        .enum_forward_decl => |enum_decl| {
            if (enum_decl.definition) |some| {
                return t.transStmt(scope, some);
            }
            try t.transEnumDecl(scope, enum_decl.container_qt);
            return ZigTag.declaration.init();
        },
        .function => |function| {
            try t.transFnDecl(scope, function);
            return ZigTag.declaration.init();
        },
        .variable => |variable| {
            try t.transVarDecl(scope, variable, stmt);
            return ZigTag.declaration.init();
        },
        .switch_stmt => |switch_stmt| return t.transSwitch(scope, switch_stmt),
        .case_stmt, .default_stmt => {
            return t.fail(error.UnsupportedTranslation, stmt.tok(t.tree), "TODO complex switch", .{});
        },
        .goto_stmt, .computed_goto_stmt, .labeled_stmt => {
            return t.fail(error.UnsupportedTranslation, stmt.tok(t.tree), "TODO goto", .{});
        },
        .asm_stmt => {
            return t.fail(error.UnsupportedTranslation, stmt.tok(t.tree), "TODO asm stmt", .{});
        },
        else => return t.transExprCoercing(scope, stmt, .unused),
    }
}