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.

writeType

Ir.writeType
fn writeType(ir: Ir, ty_ref: Interner.Ref, term: std.Io.Terminal) !void

File

Code

fn writeType(ir: Ir, ty_ref: Interner.Ref, term: std.Io.Terminal) !void {
    const w = term.writer;
    const ty = ir.interner.get(ty_ref);
    try term.setColor(TYPE);
    switch (ty) {
        .ptr_ty, .noreturn_ty, .void_ty, .func_ty => try w.writeAll(@tagName(ty)),
        .int_ty => |bits| try w.print("i{d}", .{bits}),
        .float_ty => |bits| try w.print("f{d}", .{bits}),
        .array_ty => |info| {
            try w.print("[{d} * ", .{info.len});
            try ir.writeType(info.child, .{ .mode = .no_color, .writer = w });
            try w.writeByte(']');
        },
        .vector_ty => |info| {
            try w.print("<{d} * ", .{info.len});
            try ir.writeType(info.child, .{ .mode = .no_color, .writer = w });
            try w.writeByte('>');
        },
        .record_ty => |elems| {
            // TODO collect into buffer and only print once
            try w.writeAll("{ ");
            for (elems, 0..) |elem, i| {
                if (i != 0) try w.writeAll(", ");
                try ir.writeType(elem, .{ .mode = .no_color, .writer = w });
            }
            try w.writeAll(" }");
        },
        else => unreachable, // not a type
    }
}