Same as transExpr but with the knowledge that the operand will be type coerced, and therefore
an @as would be redundant. This is used to prevent redundant @as in integer literals.
fn transExprCoercing(t: *Translator, scope: *Scope, expr: Node.Index, used: ResultUsed) TransError!ZigNode
fn transExprCoercing(t: *Translator, scope: *Scope, expr: Node.Index, used: ResultUsed) TransError!ZigNode {
switch (expr.get(t.tree)) {
.int_literal => return t.transIntLiteral(scope, expr, used, .no_as),
.char_literal => return t.transCharLiteral(scope, expr, used, .no_as),
.float_literal => return t.transFloatLiteral(scope, expr, used, .no_as),
.cast => |cast| switch (cast.kind) {
.no_op => {
const operand = cast.operand.get(t.tree);
if (operand == .cast) {
return t.transCastExpr(scope, operand.cast, cast.qt, used, .no_as);
}
return t.transExprCoercing(scope, cast.operand, used);
},
.lval_to_rval => return t.transExprCoercing(scope, cast.operand, used),
else => return t.transCastExpr(scope, cast, cast.qt, used, .no_as),
},
.default_init_expr => |default_init| return try t.transDefaultInit(scope, default_init, used, .no_as),
.compound_literal_expr => |literal| {
if (!literal.thread_local and literal.storage_class != .static) {
return t.transExprCoercing(scope, literal.initializer, used);
}
},
else => {},
}
return t.transExpr(scope, expr, used);
}