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 › structInitExprTyped Private Function structInitExprTyped Doc Source Private Function std.zig.AstGen.structInitExprTyped
fn structInitExprTyped (
gz : *GenZir ,
scope : *Scope ,
node : Ast .Node .Index ,
struct_init : Ast .full .StructInit ,
ty_inst : Zir .Inst .Ref ,
is_ref : bool ,
) InnerError !Zir .Inst .Ref Params gz : *GenZir scope : *Scope node : Ast .Node .Index struct_init : Ast .full .StructInit ty_inst : Zir .Inst .Ref is_ref : bool Errors File zig/AstGen.zig: 1908
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944 fn structInitExprTyped (
gz : *GenZir ,
scope : *Scope ,
node : Ast .Node .Index ,
struct_init : Ast .full .StructInit ,
ty_inst : Zir .Inst .Ref ,
is_ref : bool ,
) InnerError !Zir .Inst .Ref {
const astgen = gz .astgen ;
const tree = astgen .tree ;
const payload_index = try addExtra (astgen , Zir .Inst .StructInit {
.abs_node = node ,
.src_line = astgen .source_line ,
.src_column = astgen .source_column ,
.fields_len = @intCast (struct_init .ast .fields .len ),
});
const field_size = @typeInfo (Zir .Inst .StructInit .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 );
const field_ty_inst = try gz .addPlNode (.struct_init_field_type , field_init , Zir .Inst .FieldType {
.container_type = ty_inst ,
.name_start = str_index ,
});
setExtra (astgen , extra_index , Zir .Inst .StructInit .Item {
.field_type = field_ty_inst .toIndex ().?,
.init = try expr (gz , scope , .{ .rl = .{ .coerced_ty = field_ty_inst } }, field_init ),
});
extra_index += field_size ;
}
const tag : Zir .Inst .Tag = if (is_ref ) .struct_init_ref else .struct_init ;
return gz .addPlNodePayloadIndex (tag , node , payload_index );
}
A struct initialization expression using a
struct_initorstruct_init_refinstruction.