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 › transIfStmt
transIfStmt
Translator.transIfStmt
fn transIfStmt (t : *Translator , scope : *Scope , if_stmt : Node .IfStmt ) TransError !ZigNode
File
Code
fn transIfStmt (t : *Translator , scope : *Scope , if_stmt : Node .IfStmt ) TransError !ZigNode {
var cond_scope : Scope .Condition = .{
.base = .{
.parent = scope ,
.id = .condition ,
},
};
defer cond_scope .deinit ();
const cond = try t .transBoolExpr (&cond_scope .base , if_stmt .cond );
const must_blockify = (if_stmt .else_body != null ) and switch (if_stmt .then_body .get (t .tree )) {
.while_stmt , .do_while_stmt , .for_stmt => true ,
else => false ,
};
const then_node = if (must_blockify )
try t .blockify (scope , if_stmt .then_body )
else
try t .maybeBlockify (scope , if_stmt .then_body );
const else_node = if (if_stmt .else_body ) |stmt |
try t .maybeBlockify (scope , stmt )
else
null ;
return ZigTag .@"if" .create (t .arena , .{ .cond = cond , .then = then_node , .@"else" = else_node });
}