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.

transExprCoercing

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.

Translator.transExprCoercing
fn transExprCoercing(t: *Translator, scope: *Scope, expr: Node.Index, used: ResultUsed) TransError!ZigNode

File

lib/compiler/translate-c/Translator.zig:2378

Code

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);
}