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.

SourceLocationIndex

Index into coverage_source_locations.

fuzz.SourceLocationIndex
const SourceLocationIndex = enum(u32)

File

lib/build-web/fuzz.zig:93

Code

const SourceLocationIndex = enum(u32) {
    _,

    fn haveCoverage(sli: SourceLocationIndex) bool {
        return @backingInt(sli) < coverage_source_locations.items.len;
    }

    fn ptr(sli: SourceLocationIndex) *Coverage.SourceLocation {
        return &coverage_source_locations.items[@backingInt(sli)];
    }

    fn sourceLocationLinkHtml(
        sli: SourceLocationIndex,
        out: *std.ArrayList(u8),
        focused: bool,
    ) error{OutOfMemory}!void {
        const sl = sli.ptr();
        try out.print(gpa, "<code{s}>", .{
            @as([]const u8, if (focused) " class=\"status-running\"" else ""),
        });
        try sli.appendPath(out);
        try out.print(gpa, ":{d}:{d} </code><button class=\"linkish\" onclick=\"wasm_exports.fuzzSelectSli({d});\">View</button>", .{
            sl.line,
            sl.column,
            @backingInt(sli),
        });
    }

    fn appendPath(sli: SourceLocationIndex, out: *std.ArrayList(u8)) error{OutOfMemory}!void {
        const sl = sli.ptr();
        const file = coverage.fileAt(sl.file);
        const file_name = coverage.stringAt(file.basename);
        const dir_name = coverage.stringAt(coverage.directories.keys()[file.directory_index]);
        try html_render.appendEscaped(out, dir_name);
        try out.appendSlice(gpa, "/");
        try html_render.appendEscaped(out, file_name);
    }

    fn toWalkFile(sli: SourceLocationIndex) ?Walk.File.Index {
        var buf: std.ArrayList(u8) = .empty;
        defer buf.deinit(gpa);
        sli.appendPath(&buf) catch @panic("OOM");
        return @fromBackingInt(@intCast(Walk.files.getIndex(buf.items) orelse return null));
    }

    fn fileHtml(
        sli: SourceLocationIndex,
        out: *std.ArrayList(u8),
    ) error{ OutOfMemory, SourceUnavailable }!void {
        const walk_file_index = sli.toWalkFile() orelse return error.SourceUnavailable;
        const root_node = walk_file_index.findRootDecl().get().ast_node;
        var annotations: std.ArrayList(html_render.Annotation) = .empty;
        defer annotations.deinit(gpa);
        try computeSourceAnnotations(sli.ptr().file, walk_file_index, &annotations, coverage_source_locations.items);
        html_render.fileSourceHtml(walk_file_index, out, root_node, .{
            .source_location_annotations = annotations.items,
        }) catch |err| {
            fatal("unable to render source: {s}", .{@errorName(err)});
        };
    }
}