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.

transStructInit

Translator.transStructInit
fn transStructInit(
    t: *Translator,
    scope: *Scope,
    struct_init: Node.ContainerInit,
    used: ResultUsed,
) TransError!ZigNode

File

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

Code

fn transStructInit(
    t: *Translator,
    scope: *Scope,
    struct_init: Node.ContainerInit,
    used: ResultUsed,
) TransError!ZigNode {
    assert(used == .used);
    const struct_type = try t.transType(scope, struct_init.container_qt, struct_init.l_brace_tok);
    const field_inits = try t.arena.alloc(ast.Payload.ContainerInit.Initializer, struct_init.items.len);

    const struct_base = struct_init.container_qt.base(t.comp);
    for (
        field_inits,
        struct_init.items,
        struct_base.type.@"struct".fields,
    ) |*init, field_expr, field| {
        const field_name = if (field.name_tok == 0) t.anonymous_record_field_names.get(.{
            .parent = struct_base.qt,
            .field = field.qt,
        }).? else field.name.lookup(t.comp);
        init.* = .{
            .name = field_name,
            .value = try t.toNonBool(try t.transExprCoercing(scope, field_expr, .used), field.qt),
        };
    }

    const container_init = try ZigTag.container_init.create(t.arena, .{
        .lhs = struct_type,
        .inits = field_inits,
    });
    return container_init;
}