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.

parseCCastExpr

MacroTranslator.parseCCastExpr
fn parseCCastExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode

File

lib/compiler/translate-c/MacroTranslator.zig:932

Code

fn parseCCastExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode {
    if (mt.eat(.l_paren)) {
        if (try mt.parseCTypeName(scope)) |type_name| {
            while (true) {
                const next_tok = mt.peek();
                if (next_tok == .r_paren) {
                    mt.i += 1;
                    break;
                }
                // Skip trailing blank defined before the RParen.
                if ((next_tok == .identifier or next_tok == .extended_identifier) and
                    mt.t.global_scope.blank_macros.contains(mt.tokSlice()))
                {
                    mt.i += 1;
                    continue;
                }

                try mt.fail(
                    "unable to translate C expr: expected ')' instead got '{s}'",
                    .{next_tok.symbol()},
                );
                return error.ParseError;
            }
            if (mt.peek() == .l_brace) {
                // initializer list
                return mt.parseCPostfixExpr(scope, type_name);
            }
            const node_to_cast = try mt.parseCCastExpr(scope);
            return mt.t.createHelperCallNode(.cast, &.{ type_name, node_to_cast });
        }
        mt.i -= 1; // l_paren
    }
    return mt.parseCUnaryExpr(scope);
}