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.

add_file

Walk.add_file
pub fn add_file(file_name: []const u8, bytes: []u8) !File.Index

File

lib/docs/wasm/Walk.zig:388

Code

pub fn add_file(file_name: []const u8, bytes: []u8) !File.Index {
    const ast = try parse(file_name, bytes);
    assert(ast.errors.len == 0);
    const file_index: File.Index = @fromBackingInt(@intCast(files.entries.len));
    try files.put(gpa, file_name, .{ .ast = ast });

    var w: Walk = .{
        .file = file_index,
    };
    const scope = try gpa.create(Scope);
    scope.* = .{ .tag = .top };

    const decl_index = try file_index.add_decl(.root, .none);
    try struct_decl(&w, scope, decl_index, .root, ast.containerDeclRoot());

    const file = file_index.get();
    shrinkToFit(&file.ident_decls);
    shrinkToFit(&file.token_parents);
    shrinkToFit(&file.node_decls);
    shrinkToFit(&file.doctests);
    shrinkToFit(&file.scopes);

    return file_index;
}