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.
Zig › compiler/ › translate-c/ › Translator.zig › getContainer
getContainer
Translator.getContainer
fn getContainer (t : *Translator , node : ZigNode ) ?ZigNode
File
Code
fn getContainer (t : *Translator , node : ZigNode ) ?ZigNode {
switch (node .tag ()) {
.@"union" ,
.@"struct" ,
.address_of ,
.bit_not ,
.not ,
.optional_type ,
.negate ,
.negate_wrap ,
.array_type ,
.c_pointer ,
.single_pointer ,
=> return node ,
.identifier => {
const ident = node .castTag (.identifier ).?;
if (t .global_scope .sym_table .get (ident .data )) |value | {
if (value .castTag (.var_decl )) |var_decl |
return t .getContainer (var_decl .data .init .?);
if (value .castTag (.var_simple ) orelse value .castTag (.pub_var_simple )) |var_decl |
return t .getContainer (var_decl .data .init );
}
},
.field_access => {
const field_access = node .castTag (.field_access ).?;
if (t .getContainerTypeOf (field_access .data .lhs )) |ty_node | {
if (ty_node .castTag (.@"struct" ) orelse ty_node .castTag (.@"union" )) |container | {
for (container .data .fields ) |field | {
if (mem .eql (u8 , field .name , field_access .data .field_name )) {
return t .getContainer (field .type );
}
}
}
}
},
else => {},
}
return null ;
}