A struct initialization expression using a struct_init_anon instruction.
fn structInitExprAnon(
gz: *GenZir,
scope: *Scope,
node: Ast.Node.Index,
struct_init: Ast.full.StructInit,
) InnerError!Zir.Inst.Ref
fn structInitExprAnon(
gz: *GenZir,
scope: *Scope,
node: Ast.Node.Index,
struct_init: Ast.full.StructInit,
) InnerError!Zir.Inst.Ref {
const astgen = gz.astgen;
const tree = astgen.tree;
const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{
.abs_node = node,
.abs_line = astgen.source_line,
.fields_len = @intCast(struct_init.ast.fields.len),
});
const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).@"struct".field_names.len;
var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
for (struct_init.ast.fields) |field_init| {
const name_token = tree.firstToken(field_init) - 2;
const str_index = try astgen.identAsString(name_token);
setExtra(astgen, extra_index, Zir.Inst.StructInitAnon.Item{
.field_name = str_index,
.init = try expr(gz, scope, .{ .rl = .none }, field_init),
});
extra_index += field_size;
}
return gz.addPlNodePayloadIndex(.struct_init_anon, node, payload_index);
}