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");...@@ -4,8 +4,8 @@ const build_options = @import("build_options");
4const Ast = std.zig.Ast;4const Ast = std.zig.Ast;
5const Autodoc = @This();5const Autodoc = @This();
6const Compilation = @import("Compilation.zig");6const Compilation = @import("Compilation.zig");
7const CompilationModule = @import("Module.zig");7const Zcu = @import("Module.zig");
8const File = CompilationModule.File;8const File = Zcu.File;
9const Module = @import("Package.zig").Module;9const Module = @import("Package.zig").Module;
10const Tokenizer = std.zig.Tokenizer;10const Tokenizer = std.zig.Tokenizer;
11const InternPool = @import("InternPool.zig");11const InternPool = @import("InternPool.zig");
...@@ -14,7 +14,7 @@ const Ref = Zir.Inst.Ref;...@@ -14,7 +14,7 @@ const Ref = Zir.Inst.Ref;
14const log = std.log.scoped(.autodoc);14const log = std.log.scoped(.autodoc);
15const renderer = @import("autodoc/render_source.zig");15const renderer = @import("autodoc/render_source.zig");
1616
17comp_module: *CompilationModule,17zcu: *Zcu,
18arena: std.mem.Allocator,18arena: std.mem.Allocator,
1919
20// The goal of autodoc is to fill up these arrays20// The goal of autodoc is to fill up these arrays
...@@ -81,16 +81,16 @@ const Section = struct {...@@ -81,16 +81,16 @@ const Section = struct {
81 };81 };
82};82};
8383
84pub fn generate(cm: *CompilationModule, output_dir: std.fs.Dir) !void {84pub fn generate(zcu: *Zcu, output_dir: std.fs.Dir) !void {
85 var arena_allocator = std.heap.ArenaAllocator.init(cm.gpa);85 var arena_allocator = std.heap.ArenaAllocator.init(zcu.gpa);
86 defer arena_allocator.deinit();86 defer arena_allocator.deinit();
87 var autodoc: Autodoc = .{87 var autodoc: Autodoc = .{
88 .comp_module = cm,88 .zcu = zcu,
89 .arena = arena_allocator.allocator(),89 .arena = arena_allocator.allocator(),
90 };90 };
91 try autodoc.generateZirData(output_dir);91 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;
94 try lib_dir.copyFile("docs/main.js", output_dir, "main.js", .{});94 try lib_dir.copyFile("docs/main.js", output_dir, "main.js", .{});
95 try lib_dir.copyFile("docs/ziglexer.js", output_dir, "ziglexer.js", .{});95 try lib_dir.copyFile("docs/ziglexer.js", output_dir, "ziglexer.js", .{});
96 try lib_dir.copyFile("docs/commonmark.js", output_dir, "commonmark.js", .{});96 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 {...@@ -98,14 +98,14 @@ pub fn generate(cm: *CompilationModule, output_dir: std.fs.Dir) !void {
98}98}
9999
100fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {100fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
101 const root_src_path = self.comp_module.main_mod.root_src_path;101 const root_src_path = self.zcu.main_mod.root_src_path;
102 const joined_src_path = try self.comp_module.main_mod.root.joinString(self.arena, root_src_path);102 const joined_src_path = try self.zcu.main_mod.root.joinString(self.arena, root_src_path);
103 defer self.arena.free(joined_src_path);103 defer self.arena.free(joined_src_path);
104104
105 const abs_root_src_path = try std.fs.path.resolve(self.arena, &.{ ".", joined_src_path });105 const abs_root_src_path = try std.fs.path.resolve(self.arena, &.{ ".", joined_src_path });
106 defer self.arena.free(abs_root_src_path);106 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 table108 const file = self.zcu.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table
109 // Append all the types in Zir.Inst.Ref.109 // Append all the types in Zir.Inst.Ref.
110 {110 {
111 comptime std.debug.assert(@intFromEnum(InternPool.Index.first_type) == 0);111 comptime std.debug.assert(@intFromEnum(InternPool.Index.first_type) == 0);
...@@ -117,7 +117,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {...@@ -117,7 +117,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
117 // Not a real type, doesn't have a normal name117 // Not a real type, doesn't have a normal name
118 try tmpbuf.writer().writeAll("(generic poison)");118 try tmpbuf.writer().writeAll("(generic poison)");
119 } else {119 } 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());
121 }121 }
122 try self.types.append(122 try self.types.append(
123 self.arena,123 self.arena,
...@@ -294,20 +294,20 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {...@@ -294,20 +294,20 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
294 }294 }
295295
296 const rootName = blk: {296 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);
298 break :blk rootName[0 .. rootName.len - 4];298 break :blk rootName[0 .. rootName.len - 4];
299 };299 };
300300
301 const main_type_index = self.types.items.len;301 const main_type_index = self.types.items.len;
302 {302 {
303 try self.modules.put(self.arena, self.comp_module.main_mod, .{303 try self.modules.put(self.arena, self.zcu.main_mod, .{
304 .name = rootName,304 .name = rootName,
305 .main = main_type_index,305 .main = main_type_index,
306 .table = .{},306 .table = .{},
307 });307 });
308 try self.modules.entries.items(.value)[0].table.put(308 try self.modules.entries.items(.value)[0].table.put(
309 self.arena,309 self.arena,
310 self.comp_module.main_mod,310 self.zcu.main_mod,
311 .{311 .{
312 .name = rootName,312 .name = rootName,
313 .value = 0,313 .value = 0,
...@@ -435,7 +435,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {...@@ -435,7 +435,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
435435
436 const out = buffer.writer();436 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);
439 try buffer.flush();439 try buffer.flush();
440 }440 }
441 }441 }
...@@ -1036,7 +1036,7 @@ fn walkInstruction(...@@ -1036,7 +1036,7 @@ fn walkInstruction(
1036 });1036 });
1037 defer self.arena.free(abs_root_src_path);1037 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
1041 var root_scope = Scope{1041 var root_scope = Scope{
1042 .parent = null,1042 .parent = null,
...@@ -1058,7 +1058,7 @@ fn walkInstruction(...@@ -1058,7 +1058,7 @@ fn walkInstruction(
1058 );1058 );
1059 }1059 }
10601060
1061 const new_file = self.comp_module.importFile(file, path) catch unreachable;1061 const new_file = self.zcu.importFile(file, path) catch unreachable;
1062 const result = try self.files.getOrPut(self.arena, new_file.file);1062 const result = try self.files.getOrPut(self.arena, new_file.file);
1063 if (result.found_existing) {1063 if (result.found_existing) {
1064 return DocData.WalkResult{1064 return DocData.WalkResult{
...@@ -5951,7 +5951,7 @@ fn srcLocInfo(...@@ -5951,7 +5951,7 @@ fn srcLocInfo(
5951 parent_src: SrcLocInfo,5951 parent_src: SrcLocInfo,
5952) !SrcLocInfo {5952) !SrcLocInfo {
5953 const sn = @as(u32, @intCast(@as(i32, @intCast(parent_src.src_node)) + src_node));5953 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);
5955 const node_idx = @as(Ast.Node.Index, @bitCast(sn));5955 const node_idx = @as(Ast.Node.Index, @bitCast(sn));
5956 const tokens = tree.nodes.items(.main_token);5956 const tokens = tree.nodes.items(.main_token);
59575957
...@@ -5972,7 +5972,7 @@ fn declIsVar(...@@ -5972,7 +5972,7 @@ fn declIsVar(
5972 parent_src: SrcLocInfo,5972 parent_src: SrcLocInfo,
5973) !bool {5973) !bool {
5974 const sn = @as(u32, @intCast(@as(i32, @intCast(parent_src.src_node)) + src_node));5974 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);
5976 const node_idx = @as(Ast.Node.Index, @bitCast(sn));5976 const node_idx = @as(Ast.Node.Index, @bitCast(sn));
5977 const tokens = tree.nodes.items(.main_token);5977 const tokens = tree.nodes.items(.main_token);
5978 const tags = tree.tokens.items(.tag);5978 const tags = tree.tokens.items(.tag);
...@@ -5989,13 +5989,13 @@ fn getBlockSource(...@@ -5989,13 +5989,13 @@ fn getBlockSource(
5989 parent_src: SrcLocInfo,5989 parent_src: SrcLocInfo,
5990 block_src_node: i32,5990 block_src_node: i32,
5991) AutodocErrors![]const u8 {5991) AutodocErrors![]const u8 {
5992 const tree = try file.getTree(self.comp_module.gpa);5992 const tree = try file.getTree(self.zcu.gpa);
5993 const block_src = try self.srcLocInfo(file, block_src_node, parent_src);5993 const block_src = try self.srcLocInfo(file, block_src_node, parent_src);
5994 return tree.getNodeSource(block_src.src_node);5994 return tree.getNodeSource(block_src.src_node);
5995}5995}
59965996
5997fn getTLDocComment(self: *Autodoc, file: *File) ![]const u8 {5997fn 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;
5999 var tokenizer = Tokenizer.init(source);5999 var tokenizer = Tokenizer.init(source);
6000 var tok = tokenizer.next();6000 var tok = tokenizer.next();
6001 var comment = std.ArrayList(u8).init(self.arena);6001 var comment = std.ArrayList(u8).init(self.arena);