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.

CliNamedModules

Compile.CliNamedModules
const CliNamedModules = struct

File

lib/compiler/Maker/Step/Compile.zig:1111

Code

const CliNamedModules = struct {
    modules: std.array_hash_map.Auto(Configuration.Module.Index, void),
    names: std.array_hash_map.String(void),

    /// Traverse the whole dependency graph and give every module a unique
    /// name, ideally one named after what it's called somewhere in the graph.
    /// It will help here to have both a mapping from module to name and a set
    /// of all the currently-used names.
    fn init(
        arena: Allocator,
        module_graph: *ModuleGraph,
        compile_index: Configuration.Step.Index,
        maker: *const Maker,
    ) Allocator.Error!CliNamedModules {
        const conf = &maker.scanned_config.configuration;
        const conf_compile = compile_index.ptr(conf).extended.get(conf.extra).compile;

        var result: CliNamedModules = .{
            .modules = .{},
            .names = .{},
        };
        const modules = try getModuleList(arena, module_graph, conf_compile.root_module, conf);
        {
            assert(conf_compile.root_module == modules.keys()[0]);
            try result.modules.put(arena, conf_compile.root_module, {});
            try result.names.put(arena, "root", {});
        }
        for (modules.keys()[1..], modules.values()[1..]) |mod, orig_name| {
            const orig_name_slice = orig_name.slice(conf);
            var name: []const u8 = orig_name_slice;
            var n: usize = 0;
            while (true) {
                const gop = try result.names.getOrPut(arena, name);
                if (!gop.found_existing) {
                    try result.modules.putNoClobber(arena, mod, {});
                    break;
                }
                name = try arena.print("{s}{d}", .{ orig_name_slice, n });
                n += 1;
            }
        }
        return result;
    }
}