| ... | @@ -4,8 +4,8 @@ const build_options = @import("build_options"); | ... | @@ -4,8 +4,8 @@ const build_options = @import("build_options"); |
| 4 | const Ast = std.zig.Ast; | 4 | const Ast = std.zig.Ast; |
| 5 | const Autodoc = @This(); | 5 | const Autodoc = @This(); |
| 6 | const Compilation = @import("Compilation.zig"); | 6 | const Compilation = @import("Compilation.zig"); |
| 7 | const CompilationModule = @import("Module.zig"); | 7 | const Zcu = @import("Module.zig"); |
| 8 | const File = CompilationModule.File; | 8 | const File = Zcu.File; |
| 9 | const Module = @import("Package.zig").Module; | 9 | const Module = @import("Package.zig").Module; |
| 10 | const Tokenizer = std.zig.Tokenizer; | 10 | const Tokenizer = std.zig.Tokenizer; |
| 11 | const InternPool = @import("InternPool.zig"); | 11 | const InternPool = @import("InternPool.zig"); |
| ... | @@ -14,7 +14,7 @@ const Ref = Zir.Inst.Ref; | ... | @@ -14,7 +14,7 @@ const Ref = Zir.Inst.Ref; |
| 14 | const log = std.log.scoped(.autodoc); | 14 | const log = std.log.scoped(.autodoc); |
| 15 | const renderer = @import("autodoc/render_source.zig"); | 15 | const renderer = @import("autodoc/render_source.zig"); |
| 16 | | 16 | |
| 17 | comp_module: *CompilationModule, | 17 | zcu: *Zcu, |
| 18 | arena: std.mem.Allocator, | 18 | arena: std.mem.Allocator, |
| 19 | | 19 | |
| 20 | // The goal of autodoc is to fill up these arrays | 20 | // 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 | }; |
| 83 | | 83 | |
| 84 | pub fn generate(cm: *CompilationModule, output_dir: std.fs.Dir) !void { | 84 | pub 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); |
| 92 | | 92 | |
| 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 | } |
| 99 | | 99 | |
| 100 | fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void { | 100 | fn 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); |
| 104 | | 104 | |
| 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); |
| 107 | | 107 | |
| 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 |
| 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 name | 117 | // 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 | } |
| 295 | | 295 | |
| 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 | }; |
| 300 | | 300 | |
| 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 { |
| 435 | | 435 | |
| 436 | const out = buffer.writer(); | 436 | const out = buffer.writer(); |
| 437 | | 437 | |
| 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); |
| 1038 | | 1038 | |
| 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).?; |
| 1040 | | 1040 | |
| 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 | } |
| 1060 | | 1060 | |
| 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); |
| 5957 | | 5957 | |
| ... | @@ -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 | } |
| 5996 | | 5996 | |
| 5997 | fn getTLDocComment(self: *Autodoc, file: *File) ![]const u8 { | 5997 | fn 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); |