feature. See also
. The project being documented here (as the example) is the Zig library itself.
Translator.transCondExpr
fn transCondExpr(
t: *Translator,
scope: *Scope,
conditional: Node.Conditional,
used: ResultUsed,
) TransError!ZigNode
File
Code
fn transCondExpr(
t: *Translator,
scope: *Scope,
conditional: Node.Conditional,
used: ResultUsed,
) TransError!ZigNode {
var cond_scope: Scope.Condition = .{
.base = .{
.parent = scope,
.id = .condition,
},
};
defer cond_scope.deinit();
const res_is_bool = conditional.qt.is(t.comp, .bool);
const cond = try t.transBoolExpr(&cond_scope.base, conditional.cond);
var then_body = try t.transExpr(scope, conditional.then_expr, used);
if (!res_is_bool and then_body.isBoolRes()) {
then_body = try ZigTag.int_from_bool.create(t.arena, then_body);
}
var else_body = try t.transExpr(scope, conditional.else_expr, used);
if (!res_is_bool and else_body.isBoolRes()) {
else_body = try ZigTag.int_from_bool.create(t.arena, else_body);
}
return ZigTag.@"if".create(t.arena, .{ .cond = cond, .then = then_body, .@"else" = else_body });
}