| ... | @@ -65,7 +65,6 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -65,7 +65,6 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 65 | std.debug.print("path: {s}\n", .{path}); | 65 | std.debug.print("path: {s}\n", .{path}); |
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | std.debug.print("basename: {s}\n", .{self.doc_location.basename}); | | |
| 69 | | 68 | |
| 70 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; | 69 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| 71 | const dir = | 70 | const dir = |
| ... | @@ -178,9 +177,16 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -178,9 +177,16 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 178 | try self.packages.put(self.arena, self.module.main_pkg, .{ | 177 | try self.packages.put(self.arena, self.module.main_pkg, .{ |
| 179 | .name = "root", | 178 | .name = "root", |
| 180 | .main = main_type_index, | 179 | .main = main_type_index, |
| 181 | .table = std.StringHashMapUnmanaged(usize){}, | 180 | .table = .{}, |
| 182 | }); | 181 | }); |
| 183 | try self.packages.entries.items(.value)[0].table.put(self.arena, "root", 0); | 182 | try self.packages.entries.items(.value)[0].table.put( |
| | 183 | self.arena, |
| | 184 | self.module.main_pkg, |
| | 185 | .{ |
| | 186 | .name = "root", |
| | 187 | .value = 0, |
| | 188 | }, |
| | 189 | ); |
| 184 | } | 190 | } |
| 185 | | 191 | |
| 186 | var root_scope = Scope{ .parent = null, .enclosing_type = main_type_index }; | 192 | var root_scope = Scope{ .parent = null, .enclosing_type = main_type_index }; |
| ... | @@ -377,7 +383,11 @@ const DocData = struct { | ... | @@ -377,7 +383,11 @@ const DocData = struct { |
| 377 | name: []const u8 = "(root)", | 383 | name: []const u8 = "(root)", |
| 378 | file: usize = 0, // index into `files` | 384 | file: usize = 0, // index into `files` |
| 379 | main: usize = 0, // index into `types` | 385 | main: usize = 0, // index into `types` |
| 380 | table: std.StringHashMapUnmanaged(usize), | 386 | table: std.AutoHashMapUnmanaged(*Package, TableEntry), |
| | 387 | pub const TableEntry = struct { |
| | 388 | name: []const u8, |
| | 389 | value: usize, |
| | 390 | }; |
| 381 | | 391 | |
| 382 | pub fn jsonStringify( | 392 | pub fn jsonStringify( |
| 383 | self: DocPackage, | 393 | self: DocPackage, |
| ... | @@ -742,10 +752,19 @@ fn walkInstruction( | ... | @@ -742,10 +752,19 @@ fn walkInstruction( |
| 742 | }, | 752 | }, |
| 743 | .import => { | 753 | .import => { |
| 744 | const str_tok = data[inst_index].str_tok; | 754 | const str_tok = data[inst_index].str_tok; |
| 745 | const path = str_tok.get(file.zir); | 755 | var path = str_tok.get(file.zir); |
| | 756 | |
| | 757 | const maybe_other_package: ?*Package = blk: { |
| | 758 | if (self.module.main_pkg_in_std and std.mem.eql(u8, path, "std")) { |
| | 759 | path = "root"; |
| | 760 | break :blk self.module.main_pkg; |
| | 761 | } else { |
| | 762 | break :blk file.pkg.table.get(path); |
| | 763 | } |
| | 764 | }; |
| 746 | // importFile cannot error out since all files | 765 | // importFile cannot error out since all files |
| 747 | // are already loaded at this point | 766 | // are already loaded at this point |
| 748 | if (file.pkg.table.get(path)) |other_package| { | 767 | if (maybe_other_package) |other_package| { |
| 749 | const result = try self.packages.getOrPut(self.arena, other_package); | 768 | const result = try self.packages.getOrPut(self.arena, other_package); |
| 750 | | 769 | |
| 751 | // Immediately add this package to the import table of our | 770 | // Immediately add this package to the import table of our |
| ... | @@ -758,8 +777,11 @@ fn walkInstruction( | ... | @@ -758,8 +777,11 @@ fn walkInstruction( |
| 758 | // We're bailing for now, but maybe we shouldn't? | 777 | // We're bailing for now, but maybe we shouldn't? |
| 759 | _ = try current_package.table.getOrPutValue( | 778 | _ = try current_package.table.getOrPutValue( |
| 760 | self.arena, | 779 | self.arena, |
| 761 | path, | 780 | other_package, |
| 762 | self.packages.getIndex(other_package).?, | 781 | .{ |
| | 782 | .name = path, |
| | 783 | .value = self.packages.getIndex(other_package).?, |
| | 784 | }, |
| 763 | ); | 785 | ); |
| 764 | } | 786 | } |
| 765 | | 787 | |
| ... | @@ -775,7 +797,7 @@ fn walkInstruction( | ... | @@ -775,7 +797,7 @@ fn walkInstruction( |
| 775 | result.value_ptr.* = .{ | 797 | result.value_ptr.* = .{ |
| 776 | .name = path, | 798 | .name = path, |
| 777 | .main = main_type_index, | 799 | .main = main_type_index, |
| 778 | .table = std.StringHashMapUnmanaged(usize){}, | 800 | .table = .{}, |
| 779 | }; | 801 | }; |
| 780 | | 802 | |
| 781 | // TODO: Add this package as a dependency to the current pakcage | 803 | // TODO: Add this package as a dependency to the current pakcage |
| ... | @@ -3777,12 +3799,15 @@ fn writeFileTableToJson(map: std.AutoArrayHashMapUnmanaged(*File, usize), jsw: a | ... | @@ -3777,12 +3799,15 @@ fn writeFileTableToJson(map: std.AutoArrayHashMapUnmanaged(*File, usize), jsw: a |
| 3777 | try jsw.endObject(); | 3799 | try jsw.endObject(); |
| 3778 | } | 3800 | } |
| 3779 | | 3801 | |
| 3780 | fn writePackageTableToJson(map: std.StringHashMapUnmanaged(usize), jsw: anytype) !void { | 3802 | fn writePackageTableToJson( |
| | 3803 | map: std.AutoHashMapUnmanaged(*Package, DocData.DocPackage.TableEntry), |
| | 3804 | jsw: anytype, |
| | 3805 | ) !void { |
| 3781 | try jsw.beginObject(); | 3806 | try jsw.beginObject(); |
| 3782 | var it = map.iterator(); | 3807 | var it = map.valueIterator(); |
| 3783 | while (it.next()) |entry| { | 3808 | while (it.next()) |entry| { |
| 3784 | try jsw.objectField(entry.key_ptr.*); | 3809 | try jsw.objectField(entry.name); |
| 3785 | try jsw.emitNumber(entry.value_ptr.*); | 3810 | try jsw.emitNumber(entry.value); |
| 3786 | } | 3811 | } |
| 3787 | try jsw.endObject(); | 3812 | try jsw.endObject(); |
| 3788 | } | 3813 | } |