feature. See also
. The project being documented here (as the example) is the Zig library itself.
Translator.transStructInit
fn transStructInit(
t: *Translator,
scope: *Scope,
struct_init: Node.ContainerInit,
used: ResultUsed,
) TransError!ZigNode
File
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;
}