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 standard library.
std › zig › AstGen › arrayInitExprTyped Private Function arrayInitExprTyped Doc Source Private Function std.zig.AstGen.arrayInitExprTyped
fn arrayInitExprTyped (
gz : *GenZir ,
scope : *Scope ,
node : Ast .Node .Index ,
elements : []const Ast .Node .Index ,
ty_inst : Zir .Inst .Ref ,
maybe_elem_ty_inst : Zir .Inst .Ref ,
is_ref : bool ,
) InnerError !Zir .Inst .Ref Params gz : *GenZir scope : *Scope node : Ast .Node .Index elements : []const Ast .Node .Index ty_inst : Zir .Inst .Ref maybe_elem_ty_inst : Zir .Inst .Ref is_ref : bool Errors File zig/AstGen.zig: 1608
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652 fn arrayInitExprTyped (
gz : *GenZir ,
scope : *Scope ,
node : Ast .Node .Index ,
elements : []const Ast .Node .Index ,
ty_inst : Zir .Inst .Ref ,
maybe_elem_ty_inst : Zir .Inst .Ref ,
is_ref : bool ,
) InnerError !Zir .Inst .Ref {
const astgen = gz .astgen ;
const len = elements .len + 1 ; // +1 for type
const payload_index = try addExtra (astgen , Zir .Inst .MultiOp {
.operands_len = @intCast (len ),
});
var extra_index = try reserveExtra (astgen , len );
astgen .extra .items [extra_index ] = @backingInt (ty_inst );
extra_index += 1 ;
if (maybe_elem_ty_inst != .none ) {
const elem_ri : ResultInfo = .{ .rl = .{ .coerced_ty = maybe_elem_ty_inst } };
for (elements ) |elem_init | {
const elem_inst = try expr (gz , scope , elem_ri , elem_init );
astgen .extra .items [extra_index ] = @backingInt (elem_inst );
extra_index += 1 ;
}
} else {
for (elements , 0 ..) |elem_init , i | {
const ri : ResultInfo = .{ .rl = .{ .coerced_ty = try gz .add (.{
.tag = .array_init_elem_type ,
.data = .{ .bin = .{
.lhs = ty_inst ,
.rhs = @fromBackingInt (@intCast (i )),
} },
}) } };
const elem_inst = try expr (gz , scope , ri , elem_init );
astgen .extra .items [extra_index ] = @backingInt (elem_inst );
extra_index += 1 ;
}
}
const tag : Zir .Inst .Tag = if (is_ref ) .array_init_ref else .array_init ;
return try gz .addPlNodePayloadIndex (tag , node , payload_index );
}
An array initialization expression using an
array_initorarray_init_refinstruction.