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.

transTypeInit

Translator.transTypeInit
fn transTypeInit(
    t: *Translator,
    scope: *Scope,
    qt: QualType,
    init: Node.Index,
    source_loc: TokenIndex,
) TypeError!ZigNode

File

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

Code

fn transTypeInit(
    t: *Translator,
    scope: *Scope,
    qt: QualType,
    init: Node.Index,
    source_loc: TokenIndex,
) TypeError!ZigNode {
    switch (init.get(t.tree)) {
        .string_literal_expr => |literal| {
            const elem_ty = try t.transType(scope, qt.childType(t.comp), source_loc);

            const string_lit_size = literal.qt.arrayLen(t.comp).?;
            const array_size = qt.arrayLen(t.comp).?;

            if (array_size == string_lit_size) {
                return ZigTag.null_sentinel_array_type.create(t.arena, .{ .len = array_size - 1, .elem_type = elem_ty });
            } else {
                return ZigTag.array_type.create(t.arena, .{ .len = array_size, .elem_type = elem_ty });
            }
        },
        else => {},
    }
    return t.transType(scope, qt, source_loc);
}