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