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.

transDecl

Translator.transDecl
fn transDecl(t: *Translator, scope: *Scope, decl: Node.Index) !void

File

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

Code

fn transDecl(t: *Translator, scope: *Scope, decl: Node.Index) !void {
    switch (decl.get(t.tree)) {
        .typedef => |typedef_decl| {
            // Implicit typedefs are translated only if referenced.
            if (typedef_decl.implicit) return;
            try t.transTypeDef(scope, decl);
        },

        .struct_decl, .union_decl => |record_decl| {
            try t.transRecordDecl(scope, record_decl.container_qt);
        },

        .struct_forward_decl, .union_forward_decl => |record_decl| {
            if (record_decl.definition) |some| {
                return t.transDecl(scope, some);
            }
            try t.transRecordDecl(scope, record_decl.container_qt);
        },

        .enum_decl => |enum_decl| {
            try t.transEnumDecl(scope, enum_decl.container_qt);
        },

        .enum_forward_decl => |enum_decl| {
            if (enum_decl.definition) |some| {
                return t.transDecl(scope, some);
            }
            try t.transEnumDecl(scope, enum_decl.container_qt);
        },

        .enum_field,
        .record_field,
        => return,

        .function => |function| {
            if (function.definition) |definition| {
                return t.transFnDecl(scope, definition.get(t.tree).function);
            }
            try t.transFnDecl(scope, function);
        },

        .variable => |variable| {
            if (variable.definition != null) return;
            try t.transVarDecl(scope, variable, decl);
        },
        .static_assert => |static_assert| {
            try t.transStaticAssert(&t.global_scope.base, static_assert);
        },
        .global_asm => |global_asm| {
            try t.transGlobalAsm(&t.global_scope.base, global_asm);
        },
        .empty_decl => {},
        else => unreachable,
    }
}