authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2023-12-07 23:57:59+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-13 23:13:05-08:00
log60d411184ee79e9793b9a4fda59940ccd7c0f0d5
tree8948fbdc081ed6652e6f436f6c149267ae5ba98f
parentbd46410419086acd274e33b47d9ae5dc1f678a1b

autodoc: Rename Module (Compilation Module) to Zcu in preparation for big rename


1 files changed, 21 insertions(+), 21 deletions(-)

src/Autodoc.zig+21-21
......@@ -4,8 +4,8 @@ const build_options = @import("build_options");
44const Ast = std.zig.Ast;
55const Autodoc = @This();
66const Compilation = @import("Compilation.zig");
7const CompilationModule = @import("Module.zig");
8const File = CompilationModule.File;
7const Zcu = @import("Module.zig");
8const File = Zcu.File;
99const Module = @import("Package.zig").Module;
1010const Tokenizer = std.zig.Tokenizer;
1111const InternPool = @import("InternPool.zig");
......@@ -14,7 +14,7 @@ const Ref = Zir.Inst.Ref;
1414const log = std.log.scoped(.autodoc);
1515const renderer = @import("autodoc/render_source.zig");
1616
17comp_module: *CompilationModule,
17zcu: *Zcu,
1818arena: std.mem.Allocator,
1919
2020// The goal of autodoc is to fill up these arrays
......@@ -81,16 +81,16 @@ const Section = struct {
8181 };
8282};
8383
84pub fn generate(cm: *CompilationModule, output_dir: std.fs.Dir) !void {
85 var arena_allocator = std.heap.ArenaAllocator.init(cm.gpa);
84pub fn generate(zcu: *Zcu, output_dir: std.fs.Dir) !void {
85 var arena_allocator = std.heap.ArenaAllocator.init(zcu.gpa);
8686 defer arena_allocator.deinit();
8787 var autodoc: Autodoc = .{
88 .comp_module = cm,
88 .zcu = zcu,
8989 .arena = arena_allocator.allocator(),
9090 };
9191 try autodoc.generateZirData(output_dir);
9292
93 const lib_dir = cm.comp.zig_lib_directory.handle;
93 const lib_dir = zcu.comp.zig_lib_directory.handle;
9494 try lib_dir.copyFile("docs/main.js", output_dir, "main.js", .{});
9595 try lib_dir.copyFile("docs/ziglexer.js", output_dir, "ziglexer.js", .{});
9696 try lib_dir.copyFile("docs/commonmark.js", output_dir, "commonmark.js", .{});
......@@ -98,14 +98,14 @@ pub fn generate(cm: *CompilationModule, output_dir: std.fs.Dir) !void {
9898}
9999
100100fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
101 const root_src_path = self.comp_module.main_mod.root_src_path;
102 const joined_src_path = try self.comp_module.main_mod.root.joinString(self.arena, root_src_path);
101 const root_src_path = self.zcu.main_mod.root_src_path;
102 const joined_src_path = try self.zcu.main_mod.root.joinString(self.arena, root_src_path);
103103 defer self.arena.free(joined_src_path);
104104
105105 const abs_root_src_path = try std.fs.path.resolve(self.arena, &.{ ".", joined_src_path });
106106 defer self.arena.free(abs_root_src_path);
107107
108 const file = self.comp_module.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table
108 const file = self.zcu.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table
109109 // Append all the types in Zir.Inst.Ref.
110110 {
111111 comptime std.debug.assert(@intFromEnum(InternPool.Index.first_type) == 0);
......@@ -117,7 +117,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
117117 // Not a real type, doesn't have a normal name
118118 try tmpbuf.writer().writeAll("(generic poison)");
119119 } else {
120 try @import("type.zig").Type.fromInterned(ip_index).fmt(self.comp_module).format("", .{}, tmpbuf.writer());
120 try @import("type.zig").Type.fromInterned(ip_index).fmt(self.zcu).format("", .{}, tmpbuf.writer());
121121 }
122122 try self.types.append(
123123 self.arena,
......@@ -294,20 +294,20 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
294294 }
295295
296296 const rootName = blk: {
297 const rootName = std.fs.path.basename(self.comp_module.main_mod.root_src_path);
297 const rootName = std.fs.path.basename(self.zcu.main_mod.root_src_path);
298298 break :blk rootName[0 .. rootName.len - 4];
299299 };
300300
301301 const main_type_index = self.types.items.len;
302302 {
303 try self.modules.put(self.arena, self.comp_module.main_mod, .{
303 try self.modules.put(self.arena, self.zcu.main_mod, .{
304304 .name = rootName,
305305 .main = main_type_index,
306306 .table = .{},
307307 });
308308 try self.modules.entries.items(.value)[0].table.put(
309309 self.arena,
310 self.comp_module.main_mod,
310 self.zcu.main_mod,
311311 .{
312312 .name = rootName,
313313 .value = 0,
......@@ -435,7 +435,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
435435
436436 const out = buffer.writer();
437437
438 try renderer.genHtml(self.comp_module.gpa, entry.key_ptr.*, out);
438 try renderer.genHtml(self.zcu.gpa, entry.key_ptr.*, out);
439439 try buffer.flush();
440440 }
441441 }
......@@ -1036,7 +1036,7 @@ fn walkInstruction(
10361036 });
10371037 defer self.arena.free(abs_root_src_path);
10381038
1039 const new_file = self.comp_module.import_table.get(abs_root_src_path).?;
1039 const new_file = self.zcu.import_table.get(abs_root_src_path).?;
10401040
10411041 var root_scope = Scope{
10421042 .parent = null,
......@@ -1058,7 +1058,7 @@ fn walkInstruction(
10581058 );
10591059 }
10601060
1061 const new_file = self.comp_module.importFile(file, path) catch unreachable;
1061 const new_file = self.zcu.importFile(file, path) catch unreachable;
10621062 const result = try self.files.getOrPut(self.arena, new_file.file);
10631063 if (result.found_existing) {
10641064 return DocData.WalkResult{
......@@ -5951,7 +5951,7 @@ fn srcLocInfo(
59515951 parent_src: SrcLocInfo,
59525952) !SrcLocInfo {
59535953 const sn = @as(u32, @intCast(@as(i32, @intCast(parent_src.src_node)) + src_node));
5954 const tree = try file.getTree(self.comp_module.gpa);
5954 const tree = try file.getTree(self.zcu.gpa);
59555955 const node_idx = @as(Ast.Node.Index, @bitCast(sn));
59565956 const tokens = tree.nodes.items(.main_token);
59575957
......@@ -5972,7 +5972,7 @@ fn declIsVar(
59725972 parent_src: SrcLocInfo,
59735973) !bool {
59745974 const sn = @as(u32, @intCast(@as(i32, @intCast(parent_src.src_node)) + src_node));
5975 const tree = try file.getTree(self.comp_module.gpa);
5975 const tree = try file.getTree(self.zcu.gpa);
59765976 const node_idx = @as(Ast.Node.Index, @bitCast(sn));
59775977 const tokens = tree.nodes.items(.main_token);
59785978 const tags = tree.tokens.items(.tag);
......@@ -5989,13 +5989,13 @@ fn getBlockSource(
59895989 parent_src: SrcLocInfo,
59905990 block_src_node: i32,
59915991) AutodocErrors![]const u8 {
5992 const tree = try file.getTree(self.comp_module.gpa);
5992 const tree = try file.getTree(self.zcu.gpa);
59935993 const block_src = try self.srcLocInfo(file, block_src_node, parent_src);
59945994 return tree.getNodeSource(block_src.src_node);
59955995}
59965996
59975997fn getTLDocComment(self: *Autodoc, file: *File) ![]const u8 {
5998 const source = (try file.getSource(self.comp_module.gpa)).bytes;
5998 const source = (try file.getSource(self.zcu.gpa)).bytes;
59995999 var tokenizer = Tokenizer.init(source);
60006000 var tok = tokenizer.next();
60016001 var comment = std.ArrayList(u8).init(self.arena);