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.

renderBuiltinCall

Render.renderBuiltinCall
fn renderBuiltinCall(
    r: *Render,
    builtin_token: Ast.TokenIndex,
    params: []const Ast.Node.Index,
    space: Space,
) Error!void

File

lib/std/zig/Ast/Render.zig:1646

Code

fn renderBuiltinCall(
    r: *Render,
    builtin_token: Ast.TokenIndex,
    params: []const Ast.Node.Index,
    space: Space,
) Error!void {
    const tree = r.tree;
    const ais = r.ais;

    // remove before 0.18.0 is released
    const builtin_token_slice = tree.tokenSlice(builtin_token); // @name
    const lexeme: []const u8, const have_int_cast: bool = lexeme: {
        if (mem.eql(u8, builtin_token_slice, "@intFromEnum"))
            break :lexeme .{ "@backingInt", false };
        if (mem.eql(u8, builtin_token_slice, "@enumFromInt"))
            break :lexeme .{ "@fromBackingInt(@intCast", true };
        break :lexeme .{ builtin_token_slice, false };
    };
    try ais.writeAll(lexeme);
    try renderSpace(r, builtin_token, builtin_token_slice.len, .none);

    if (r.fixups.rebase_imported_paths) |prefix| {
        const slice = tree.tokenSlice(builtin_token);
        if (params.len != 0 and mem.eql(u8, slice, "@import")) f: {
            const param = params[0];
            const str_lit_token = tree.nodeMainToken(param);
            assert(tree.tokenTag(str_lit_token) == .string_literal);
            const token_bytes = tree.tokenSlice(str_lit_token);
            const imported_string = std.zig.string_literal.parseAlloc(r.gpa, token_bytes) catch |err| switch (err) {
                error.OutOfMemory => |e| return e,
                error.InvalidLiteral => break :f,
            };
            defer r.gpa.free(imported_string);
            const new_string = try std.fs.path.resolvePosix(r.gpa, &.{ prefix, imported_string });
            defer r.gpa.free(new_string);

            try renderToken(r, builtin_token + 1, .none); // (
            try ais.print("\"{f}\"", .{std.zig.fmtString(new_string)});
            return renderToken(r, str_lit_token + 1, space); // )
        }
    }

    try renderParamList(r, builtin_token + 1, params, .skip); // space is rendered below
    if (have_int_cast) try ais.writeAll(")");
    const rparen: Ast.TokenIndex = rparen: {
        if (params.len == 0) break :rparen builtin_token + 1 + 1;
        const after_last_param_tok = tree.lastToken(params[params.len - 1]) + 1;
        break :rparen after_last_param_tok + @intFromBool(tree.tokenTag(after_last_param_tok) == .comma);
    };
    return renderSpace(r, rparen, tokenSliceForRender(tree, rparen).len, space);
}