authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-02-11 19:11:03+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
logee16eddecfc700e37d1acc5393bc2a2ac4e72250
tree6f3a08c9cbd7e4f23dc83b3f0ce54b2ee44b4d87
parent4a868fa2be1713a5cdc0ae75276c2fdf28a56d94

autodoc: added basic support for `@import`


2 files changed, 120 insertions(+), 115 deletions(-)

lib/docs/main.js+17-21
...@@ -264,15 +264,10 @@...@@ -264,15 +264,10 @@
264 }264 }
265265
266 var childDeclValue = resolveValue(childDecl.value);266 var childDeclValue = resolveValue(childDecl.value);
267 if ("type" in childDeclValue &&267 if ("type" in childDeclValue) {
268 zigAnalysis.types[childDeclValue.type].kind !== typeKinds.Fn){268 childDecl = zigAnalysis.types[childDeclValue.type];
269 if (i + 1 === curNav.declNames.length) {
270 curNav.declObjs.push(zigAnalysis.types[childDeclValue.type]);
271 break;
272 } else {
273 return render404();
274 }
275 }269 }
270
276 currentType = childDecl;271 currentType = childDecl;
277 curNav.declObjs.push(currentType);272 curNav.declObjs.push(currentType);
278 }273 }
...@@ -1458,7 +1453,7 @@...@@ -1458,7 +1453,7 @@
1458 }1453 }
14591454
1460 function findSubDecl(parentType, childName) {1455 function findSubDecl(parentType, childName) {
1461 if (!parentType.pubDecls) throw new Error("parent object has no public decls");1456 if (!parentType.pubDecls) return null;
1462 for (var i = 0; i < parentType.pubDecls.length; i += 1) {1457 for (var i = 0; i < parentType.pubDecls.length; i += 1) {
1463 var declIndex = parentType.pubDecls[i];1458 var declIndex = parentType.pubDecls[i];
1464 var childDecl = zigAnalysis.decls[declIndex];1459 var childDecl = zigAnalysis.decls[declIndex];
...@@ -1523,24 +1518,25 @@...@@ -1523,24 +1518,25 @@
1523 if (list[mainDeclIndex] != null) continue;1518 if (list[mainDeclIndex] != null) continue;
15241519
1525 var decl = zigAnalysis.decls[mainDeclIndex];1520 var decl = zigAnalysis.decls[mainDeclIndex];
1526 var declValTypeId = resolveDeclValueTypeId(decl);1521 var declVal = resolveValue(decl.value);
1527 if (declValTypeId === typeTypeId &&
1528 declCanRepresentTypeKind(zigAnalysis.types[declValTypeId].kind))
1529 {
1530 canonTypeDecls[declValTypeId] = mainDeclIndex;
1531 }
1532 var declNames = item.declNames.concat([decl.name]);1522 var declNames = item.declNames.concat([decl.name]);
1533 list[mainDeclIndex] = {1523 list[mainDeclIndex] = {
1534 pkgNames: pkgNames,1524 pkgNames: pkgNames,
1535 declNames: declNames,1525 declNames: declNames,
1536 };1526 };
1527 if ("type" in declVal) {
1528 var value = zigAnalysis.types[declVal.type];
1529 if (declCanRepresentTypeKind(value.kind))
1530 {
1531 canonTypeDecls[declVal.type] = mainDeclIndex;
1532 }
15371533
1538 var declType = zigAnalysis.types[declValTypeId];1534 if (isContainerType(value)) {
1539 if (isContainerType(declType)) {1535 stack.push({
1540 stack.push({1536 declNames: declNames,
1541 declNames: declNames,1537 type:value,
1542 type: declType,1538 });
1543 });1539 }
1544 }1540 }
1545 }1541 }
1546 }1542 }
src/Autodoc.zig+103-94
...@@ -2,18 +2,19 @@ const std = @import("std");...@@ -2,18 +2,19 @@ const std = @import("std");
2const Autodoc = @This();2const Autodoc = @This();
3const Compilation = @import("Compilation.zig");3const Compilation = @import("Compilation.zig");
4const Module = @import("Module.zig");4const Module = @import("Module.zig");
5const File = Module.File;
5const Zir = @import("Zir.zig");6const Zir = @import("Zir.zig");
6const Ref = Zir.Inst.Ref;7const Ref = Zir.Inst.Ref;
78
8module: *Module,9module: *Module,
9doc_location: ?Compilation.EmitLoc,10doc_location: Compilation.EmitLoc,
10arena: std.mem.Allocator,11arena: std.mem.Allocator,
11types: std.ArrayListUnmanaged(DocData.Type) = .{},12types: std.ArrayListUnmanaged(DocData.Type) = .{},
12decls: std.ArrayListUnmanaged(DocData.Decl) = .{},13decls: std.ArrayListUnmanaged(DocData.Decl) = .{},
13ast_nodes: std.ArrayListUnmanaged(DocData.AstNode) = .{},14ast_nodes: std.ArrayListUnmanaged(DocData.AstNode) = .{},
1415
15var arena_allocator: std.heap.ArenaAllocator = undefined;16var arena_allocator: std.heap.ArenaAllocator = undefined;
16pub fn init(m: *Module, doc_location: ?Compilation.EmitLoc) Autodoc {17pub fn init(m: *Module, doc_location: Compilation.EmitLoc) Autodoc {
17 arena_allocator = std.heap.ArenaAllocator.init(m.gpa);18 arena_allocator = std.heap.ArenaAllocator.init(m.gpa);
18 return .{19 return .{
19 .module = m,20 .module = m,
...@@ -27,11 +28,9 @@ pub fn deinit(_: *Autodoc) void {...@@ -27,11 +28,9 @@ pub fn deinit(_: *Autodoc) void {
27}28}
2829
29pub fn generateZirData(self: *Autodoc) !void {30pub fn generateZirData(self: *Autodoc) !void {
30 if (self.doc_location) |loc| {31 if (self.doc_location.directory) |dir| {
31 if (loc.directory) |dir| {32 if (dir.path) |path| {
32 if (dir.path) |path| {33 std.debug.print("path: {s}\n", .{path});
33 std.debug.print("path: {s}\n", .{path});
34 }
35 }34 }
36 }35 }
37 std.debug.print("basename: {s}\n", .{self.doc_location.basename});36 std.debug.print("basename: {s}\n", .{self.doc_location.basename});
...@@ -45,7 +44,7 @@ pub fn generateZirData(self: *Autodoc) !void {...@@ -45,7 +44,7 @@ pub fn generateZirData(self: *Autodoc) !void {
45 const root_file_path = self.module.main_pkg.root_src_path;44 const root_file_path = self.module.main_pkg.root_src_path;
46 const abs_root_path = try std.fs.path.join(self.arena, &.{ dir, root_file_path });45 const abs_root_path = try std.fs.path.join(self.arena, &.{ dir, root_file_path });
47 defer self.arena.free(abs_root_path);46 defer self.arena.free(abs_root_path);
48 const zir = self.module.import_table.get(abs_root_path).?.zir;47 const file = self.module.import_table.get(abs_root_path).?;
4948
50 // append all the types in Zir.Inst.Ref49 // append all the types in Zir.Inst.Ref
51 {50 {
...@@ -122,7 +121,7 @@ pub fn generateZirData(self: *Autodoc) !void {...@@ -122,7 +121,7 @@ pub fn generateZirData(self: *Autodoc) !void {
122121
123 var root_scope: Scope = .{ .parent = null };122 var root_scope: Scope = .{ .parent = null };
124 try self.ast_nodes.append(self.arena, .{ .name = "(root)" });123 try self.ast_nodes.append(self.arena, .{ .name = "(root)" });
125 const main_type_index = try self.walkInstruction(zir, &root_scope, Zir.main_struct_inst);124 const main_type_index = try self.walkInstruction(file, &root_scope, Zir.main_struct_inst);
126125
127 var data = DocData{126 var data = DocData{
128 .files = &[1][]const u8{root_file_path},127 .files = &[1][]const u8{root_file_path},
...@@ -467,12 +466,12 @@ const DocData = struct {...@@ -467,12 +466,12 @@ const DocData = struct {
467466
468fn walkInstruction(467fn walkInstruction(
469 self: *Autodoc,468 self: *Autodoc,
470 zir: Zir,469 file: *File,
471 parent_scope: *Scope,470 parent_scope: *Scope,
472 inst_index: usize,471 inst_index: usize,
473) error{OutOfMemory}!DocData.WalkResult {472) error{OutOfMemory}!DocData.WalkResult {
474 const tags = zir.instructions.items(.tag);473 const tags = file.zir.instructions.items(.tag);
475 const data = zir.instructions.items(.data);474 const data = file.zir.instructions.items(.data);
476475
477 // We assume that the topmost ast_node entry corresponds to our decl476 // We assume that the topmost ast_node entry corresponds to our decl
478 const self_ast_node_index = self.ast_nodes.items.len - 1;477 const self_ast_node_index = self.ast_nodes.items.len - 1;
...@@ -484,6 +483,16 @@ fn walkInstruction(...@@ -484,6 +483,16 @@ fn walkInstruction(
484 .{@tagName(tags[inst_index])},483 .{@tagName(tags[inst_index])},
485 );484 );
486 },485 },
486 .import => {
487 const str_tok = data[inst_index].str_tok;
488 const path = str_tok.get(file.zir);
489 // importFile cannot error out since all files
490 // are already loaded at this point
491 const new_file = self.module.importFile(file, path) catch unreachable;
492 // TODO: cycles not handled, add file info to outuput
493 var new_scope = Scope{ .parent = null };
494 return self.walkInstruction(new_file.file, &new_scope, Zir.main_struct_inst);
495 },
487 .int => {496 .int => {
488 const int = data[inst_index].int;497 const int = data[inst_index].int;
489 return DocData.WalkResult{498 return DocData.WalkResult{
...@@ -509,7 +518,7 @@ fn walkInstruction(...@@ -509,7 +518,7 @@ fn walkInstruction(
509 .negate => {518 .negate => {
510 const un_node = data[inst_index].un_node;519 const un_node = data[inst_index].un_node;
511 var operand: DocData.WalkResult = try self.walkRef(520 var operand: DocData.WalkResult = try self.walkRef(
512 zir,521 file,
513 parent_scope,522 parent_scope,
514 un_node.operand,523 un_node.operand,
515 );524 );
...@@ -518,11 +527,11 @@ fn walkInstruction(...@@ -518,11 +527,11 @@ fn walkInstruction(
518 },527 },
519 .as_node => {528 .as_node => {
520 const pl_node = data[inst_index].pl_node;529 const pl_node = data[inst_index].pl_node;
521 const extra = zir.extraData(Zir.Inst.As, pl_node.payload_index);530 const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index);
522 const dest_type_walk = try self.walkRef(zir, parent_scope, extra.data.dest_type);531 const dest_type_walk = try self.walkRef(file, parent_scope, extra.data.dest_type);
523 const dest_type_ref = walkResultToTypeRef(dest_type_walk);532 const dest_type_ref = walkResultToTypeRef(dest_type_walk);
524533
525 var operand = try self.walkRef(zir, parent_scope, extra.data.operand);534 var operand = try self.walkRef(file, parent_scope, extra.data.operand);
526535
527 switch (operand) {536 switch (operand) {
528 else => std.debug.panic(537 else => std.debug.panic(
...@@ -562,20 +571,20 @@ fn walkInstruction(...@@ -562,20 +571,20 @@ fn walkInstruction(
562 },571 },
563 //.block => {572 //.block => {
564 //const pl_node = data[inst_index].pl_node;573 //const pl_node = data[inst_index].pl_node;
565 //const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index);574 //const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
566 //const last_instr_index = zir.extra[extra.end..][extra.data.body_len - 1];575 //const last_instr_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
567 //const break_operand = data[break_index].@"break".operand;576 //const break_operand = data[break_index].@"break".operand;
568 //return self.walkRef(zir, parent_scope, break_operand);577 //return self.walkRef(file, parent_scope, break_operand);
569 //},578 //},
570 .block_inline => {579 .block_inline => {
571 const pl_node = data[inst_index].pl_node;580 const pl_node = data[inst_index].pl_node;
572 const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index);581 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
573 const break_index = zir.extra[extra.end..][extra.data.body_len - 1];582 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
574 const break_operand = data[break_index].@"break".operand;583 const break_operand = data[break_index].@"break".operand;
575 return self.walkRef(zir, parent_scope, break_operand);584 return self.walkRef(file, parent_scope, break_operand);
576 },585 },
577 .func => {586 .func => {
578 const fn_info = zir.getFnInfo(@intCast(u32, inst_index));587 const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index));
579588
580 // TODO: change this to a resize and change the appends accordingly589 // TODO: change this to a resize and change the appends accordingly
581 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);590 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);
...@@ -591,21 +600,21 @@ fn walkInstruction(...@@ -591,21 +600,21 @@ fn walkInstruction(
591 for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| {600 for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| {
592 if (tags[param_index] != .param) unreachable; // TODO: handle more param types601 if (tags[param_index] != .param) unreachable; // TODO: handle more param types
593 const pl_tok = data[param_index].pl_tok;602 const pl_tok = data[param_index].pl_tok;
594 const extra = zir.extraData(Zir.Inst.Param, pl_tok.payload_index);603 const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index);
595 const doc_comment = if (extra.data.doc_comment != 0)604 const doc_comment = if (extra.data.doc_comment != 0)
596 zir.nullTerminatedString(extra.data.doc_comment)605 file.zir.nullTerminatedString(extra.data.doc_comment)
597 else606 else
598 "";607 "";
599608
600 param_ast_indexes.appendAssumeCapacity(self.ast_nodes.items.len);609 param_ast_indexes.appendAssumeCapacity(self.ast_nodes.items.len);
601 try self.ast_nodes.append(self.arena, .{610 try self.ast_nodes.append(self.arena, .{
602 .name = zir.nullTerminatedString(extra.data.name),611 .name = file.zir.nullTerminatedString(extra.data.name),
603 .docs = doc_comment,612 .docs = doc_comment,
604 });613 });
605614
606 const break_index = zir.extra[extra.end..][extra.data.body_len - 1];615 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
607 const break_operand = data[break_index].@"break".operand;616 const break_operand = data[break_index].@"break".operand;
608 const param_type_ref = try self.walkRef(zir, parent_scope, break_operand);617 const param_type_ref = try self.walkRef(file, parent_scope, break_operand);
609618
610 param_type_refs.appendAssumeCapacity(619 param_type_refs.appendAssumeCapacity(
611 DocData.TypeRef.fromWalkResult(param_type_ref),620 DocData.TypeRef.fromWalkResult(param_type_ref),
...@@ -616,7 +625,7 @@ fn walkInstruction(...@@ -616,7 +625,7 @@ fn walkInstruction(
616 const ret_type_ref = blk: {625 const ret_type_ref = blk: {
617 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];626 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
618 const break_operand = data[last_instr_index].@"break".operand;627 const break_operand = data[last_instr_index].@"break".operand;
619 const wr = try self.walkRef(zir, parent_scope, break_operand);628 const wr = try self.walkRef(file, parent_scope, break_operand);
620 break :blk DocData.TypeRef.fromWalkResult(wr);629 break :blk DocData.TypeRef.fromWalkResult(wr);
621 };630 };
622631
...@@ -647,34 +656,34 @@ fn walkInstruction(...@@ -647,34 +656,34 @@ fn walkInstruction(
647 var extra_index: usize = extended.operand;656 var extra_index: usize = extended.operand;
648657
649 const src_node: ?i32 = if (small.has_src_node) blk: {658 const src_node: ?i32 = if (small.has_src_node) blk: {
650 const src_node = @bitCast(i32, zir.extra[extra_index]);659 const src_node = @bitCast(i32, file.zir.extra[extra_index]);
651 extra_index += 1;660 extra_index += 1;
652 break :blk src_node;661 break :blk src_node;
653 } else null;662 } else null;
654 _ = src_node;663 _ = src_node;
655664
656 const tag_type: ?Ref = if (small.has_tag_type) blk: {665 const tag_type: ?Ref = if (small.has_tag_type) blk: {
657 const tag_type = zir.extra[extra_index];666 const tag_type = file.zir.extra[extra_index];
658 extra_index += 1;667 extra_index += 1;
659 break :blk @intToEnum(Ref, tag_type);668 break :blk @intToEnum(Ref, tag_type);
660 } else null;669 } else null;
661 _ = tag_type;670 _ = tag_type;
662671
663 const body_len = if (small.has_body_len) blk: {672 const body_len = if (small.has_body_len) blk: {
664 const body_len = zir.extra[extra_index];673 const body_len = file.zir.extra[extra_index];
665 extra_index += 1;674 extra_index += 1;
666 break :blk body_len;675 break :blk body_len;
667 } else 0;676 } else 0;
668677
669 const fields_len = if (small.has_fields_len) blk: {678 const fields_len = if (small.has_fields_len) blk: {
670 const fields_len = zir.extra[extra_index];679 const fields_len = file.zir.extra[extra_index];
671 extra_index += 1;680 extra_index += 1;
672 break :blk fields_len;681 break :blk fields_len;
673 } else 0;682 } else 0;
674 _ = fields_len;683 _ = fields_len;
675684
676 const decls_len = if (small.has_decls_len) blk: {685 const decls_len = if (small.has_decls_len) blk: {
677 const decls_len = zir.extra[extra_index];686 const decls_len = file.zir.extra[extra_index];
678 extra_index += 1;687 extra_index += 1;
679 break :blk decls_len;688 break :blk decls_len;
680 } else 0;689 } else 0;
...@@ -687,17 +696,17 @@ fn walkInstruction(...@@ -687,17 +696,17 @@ fn walkInstruction(
687 // Done to make sure that all decl refs can be resolved correctly,696 // Done to make sure that all decl refs can be resolved correctly,
688 // even if we haven't fully analyzed the decl yet.697 // even if we haven't fully analyzed the decl yet.
689 {698 {
690 var it = zir.declIterator(@intCast(u32, inst_index));699 var it = file.zir.declIterator(@intCast(u32, inst_index));
691 try self.decls.resize(self.arena, decls_first_index + it.decls_len);700 try self.decls.resize(self.arena, decls_first_index + it.decls_len);
692 var decls_slot_index = decls_first_index;701 var decls_slot_index = decls_first_index;
693 while (it.next()) |d| : (decls_slot_index += 1) {702 while (it.next()) |d| : (decls_slot_index += 1) {
694 const decl_name_index = zir.extra[d.sub_index + 5];703 const decl_name_index = file.zir.extra[d.sub_index + 5];
695 try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index);704 try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index);
696 }705 }
697 }706 }
698707
699 extra_index = try self.walkDecls(708 extra_index = try self.walkDecls(
700 zir,709 file,
701 &scope,710 &scope,
702 decls_first_index,711 decls_first_index,
703 decls_len,712 decls_len,
...@@ -706,7 +715,7 @@ fn walkInstruction(...@@ -706,7 +715,7 @@ fn walkInstruction(
706 extra_index,715 extra_index,
707 );716 );
708717
709 // const body = zir.extra[extra_index..][0..body_len];718 // const body = file.zir.extra[extra_index..][0..body_len];
710 extra_index += body_len;719 extra_index += body_len;
711720
712 var field_type_refs = try std.ArrayListUnmanaged(DocData.TypeRef).initCapacity(721 var field_type_refs = try std.ArrayListUnmanaged(DocData.TypeRef).initCapacity(
...@@ -718,7 +727,7 @@ fn walkInstruction(...@@ -718,7 +727,7 @@ fn walkInstruction(
718 fields_len,727 fields_len,
719 );728 );
720 try self.collectUnionFieldInfo(729 try self.collectUnionFieldInfo(
721 zir,730 file,
722 &scope,731 &scope,
723 fields_len,732 fields_len,
724 &field_type_refs,733 &field_type_refs,
...@@ -747,34 +756,34 @@ fn walkInstruction(...@@ -747,34 +756,34 @@ fn walkInstruction(
747 var extra_index: usize = extended.operand;756 var extra_index: usize = extended.operand;
748757
749 const src_node: ?i32 = if (small.has_src_node) blk: {758 const src_node: ?i32 = if (small.has_src_node) blk: {
750 const src_node = @bitCast(i32, zir.extra[extra_index]);759 const src_node = @bitCast(i32, file.zir.extra[extra_index]);
751 extra_index += 1;760 extra_index += 1;
752 break :blk src_node;761 break :blk src_node;
753 } else null;762 } else null;
754 _ = src_node;763 _ = src_node;
755764
756 const tag_type: ?Ref = if (small.has_tag_type) blk: {765 const tag_type: ?Ref = if (small.has_tag_type) blk: {
757 const tag_type = zir.extra[extra_index];766 const tag_type = file.zir.extra[extra_index];
758 extra_index += 1;767 extra_index += 1;
759 break :blk @intToEnum(Ref, tag_type);768 break :blk @intToEnum(Ref, tag_type);
760 } else null;769 } else null;
761 _ = tag_type;770 _ = tag_type;
762771
763 const body_len = if (small.has_body_len) blk: {772 const body_len = if (small.has_body_len) blk: {
764 const body_len = zir.extra[extra_index];773 const body_len = file.zir.extra[extra_index];
765 extra_index += 1;774 extra_index += 1;
766 break :blk body_len;775 break :blk body_len;
767 } else 0;776 } else 0;
768777
769 const fields_len = if (small.has_fields_len) blk: {778 const fields_len = if (small.has_fields_len) blk: {
770 const fields_len = zir.extra[extra_index];779 const fields_len = file.zir.extra[extra_index];
771 extra_index += 1;780 extra_index += 1;
772 break :blk fields_len;781 break :blk fields_len;
773 } else 0;782 } else 0;
774 _ = fields_len;783 _ = fields_len;
775784
776 const decls_len = if (small.has_decls_len) blk: {785 const decls_len = if (small.has_decls_len) blk: {
777 const decls_len = zir.extra[extra_index];786 const decls_len = file.zir.extra[extra_index];
778 extra_index += 1;787 extra_index += 1;
779 break :blk decls_len;788 break :blk decls_len;
780 } else 0;789 } else 0;
...@@ -787,17 +796,17 @@ fn walkInstruction(...@@ -787,17 +796,17 @@ fn walkInstruction(
787 // Done to make sure that all decl refs can be resolved correctly,796 // Done to make sure that all decl refs can be resolved correctly,
788 // even if we haven't fully analyzed the decl yet.797 // even if we haven't fully analyzed the decl yet.
789 {798 {
790 var it = zir.declIterator(@intCast(u32, inst_index));799 var it = file.zir.declIterator(@intCast(u32, inst_index));
791 try self.decls.resize(self.arena, decls_first_index + it.decls_len);800 try self.decls.resize(self.arena, decls_first_index + it.decls_len);
792 var decls_slot_index = decls_first_index;801 var decls_slot_index = decls_first_index;
793 while (it.next()) |d| : (decls_slot_index += 1) {802 while (it.next()) |d| : (decls_slot_index += 1) {
794 const decl_name_index = zir.extra[d.sub_index + 5];803 const decl_name_index = file.zir.extra[d.sub_index + 5];
795 try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index);804 try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index);
796 }805 }
797 }806 }
798807
799 extra_index = try self.walkDecls(808 extra_index = try self.walkDecls(
800 zir,809 file,
801 &scope,810 &scope,
802 decls_first_index,811 decls_first_index,
803 decls_len,812 decls_len,
...@@ -806,7 +815,7 @@ fn walkInstruction(...@@ -806,7 +815,7 @@ fn walkInstruction(
806 extra_index,815 extra_index,
807 );816 );
808817
809 // const body = zir.extra[extra_index..][0..body_len];818 // const body = file.zir.extra[extra_index..][0..body_len];
810 extra_index += body_len;819 extra_index += body_len;
811820
812 var field_name_indexes: std.ArrayListUnmanaged(usize) = .{};821 var field_name_indexes: std.ArrayListUnmanaged(usize) = .{};
...@@ -818,31 +827,31 @@ fn walkInstruction(...@@ -818,31 +827,31 @@ fn walkInstruction(
818 var idx: usize = 0;827 var idx: usize = 0;
819 while (idx < fields_len) : (idx += 1) {828 while (idx < fields_len) : (idx += 1) {
820 if (idx % 32 == 0) {829 if (idx % 32 == 0) {
821 cur_bit_bag = zir.extra[bit_bag_idx];830 cur_bit_bag = file.zir.extra[bit_bag_idx];
822 bit_bag_idx += 1;831 bit_bag_idx += 1;
823 }832 }
824833
825 const has_value = @truncate(u1, cur_bit_bag) != 0;834 const has_value = @truncate(u1, cur_bit_bag) != 0;
826 cur_bit_bag >>= 1;835 cur_bit_bag >>= 1;
827836
828 const field_name_index = zir.extra[extra_index];837 const field_name_index = file.zir.extra[extra_index];
829 extra_index += 1;838 extra_index += 1;
830839
831 const doc_comment_index = zir.extra[extra_index];840 const doc_comment_index = file.zir.extra[extra_index];
832 extra_index += 1;841 extra_index += 1;
833842
834 const value_ref: ?Ref = if (has_value) blk: {843 const value_ref: ?Ref = if (has_value) blk: {
835 const value_ref = zir.extra[extra_index];844 const value_ref = file.zir.extra[extra_index];
836 extra_index += 1;845 extra_index += 1;
837 break :blk @intToEnum(Ref, value_ref);846 break :blk @intToEnum(Ref, value_ref);
838 } else null;847 } else null;
839 _ = value_ref;848 _ = value_ref;
840849
841 const field_name = zir.nullTerminatedString(field_name_index);850 const field_name = file.zir.nullTerminatedString(field_name_index);
842851
843 try field_name_indexes.append(self.arena, self.ast_nodes.items.len);852 try field_name_indexes.append(self.arena, self.ast_nodes.items.len);
844 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)853 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)
845 zir.nullTerminatedString(doc_comment_index)854 file.zir.nullTerminatedString(doc_comment_index)
846 else855 else
847 null;856 null;
848 try self.ast_nodes.append(self.arena, .{857 try self.ast_nodes.append(self.arena, .{
...@@ -872,27 +881,27 @@ fn walkInstruction(...@@ -872,27 +881,27 @@ fn walkInstruction(
872 var extra_index: usize = extended.operand;881 var extra_index: usize = extended.operand;
873882
874 const src_node: ?i32 = if (small.has_src_node) blk: {883 const src_node: ?i32 = if (small.has_src_node) blk: {
875 const src_node = @bitCast(i32, zir.extra[extra_index]);884 const src_node = @bitCast(i32, file.zir.extra[extra_index]);
876 extra_index += 1;885 extra_index += 1;
877 break :blk src_node;886 break :blk src_node;
878 } else null;887 } else null;
879 _ = src_node;888 _ = src_node;
880889
881 const body_len = if (small.has_body_len) blk: {890 const body_len = if (small.has_body_len) blk: {
882 const body_len = zir.extra[extra_index];891 const body_len = file.zir.extra[extra_index];
883 extra_index += 1;892 extra_index += 1;
884 break :blk body_len;893 break :blk body_len;
885 } else 0;894 } else 0;
886895
887 const fields_len = if (small.has_fields_len) blk: {896 const fields_len = if (small.has_fields_len) blk: {
888 const fields_len = zir.extra[extra_index];897 const fields_len = file.zir.extra[extra_index];
889 extra_index += 1;898 extra_index += 1;
890 break :blk fields_len;899 break :blk fields_len;
891 } else 0;900 } else 0;
892 _ = fields_len;901 _ = fields_len;
893902
894 const decls_len = if (small.has_decls_len) blk: {903 const decls_len = if (small.has_decls_len) blk: {
895 const decls_len = zir.extra[extra_index];904 const decls_len = file.zir.extra[extra_index];
896 extra_index += 1;905 extra_index += 1;
897 break :blk decls_len;906 break :blk decls_len;
898 } else 0;907 } else 0;
...@@ -905,17 +914,17 @@ fn walkInstruction(...@@ -905,17 +914,17 @@ fn walkInstruction(
905 // Done to make sure that all decl refs can be resolved correctly,914 // Done to make sure that all decl refs can be resolved correctly,
906 // even if we haven't fully analyzed the decl yet.915 // even if we haven't fully analyzed the decl yet.
907 {916 {
908 var it = zir.declIterator(@intCast(u32, inst_index));917 var it = file.zir.declIterator(@intCast(u32, inst_index));
909 try self.decls.resize(self.arena, decls_first_index + it.decls_len);918 try self.decls.resize(self.arena, decls_first_index + it.decls_len);
910 var decls_slot_index = decls_first_index;919 var decls_slot_index = decls_first_index;
911 while (it.next()) |d| : (decls_slot_index += 1) {920 while (it.next()) |d| : (decls_slot_index += 1) {
912 const decl_name_index = zir.extra[d.sub_index + 5];921 const decl_name_index = file.zir.extra[d.sub_index + 5];
913 try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index);922 try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index);
914 }923 }
915 }924 }
916925
917 extra_index = try self.walkDecls(926 extra_index = try self.walkDecls(
918 zir,927 file,
919 &scope,928 &scope,
920 decls_first_index,929 decls_first_index,
921 decls_len,930 decls_len,
...@@ -924,13 +933,13 @@ fn walkInstruction(...@@ -924,13 +933,13 @@ fn walkInstruction(
924 extra_index,933 extra_index,
925 );934 );
926935
927 // const body = zir.extra[extra_index..][0..body_len];936 // const body = file.zir.extra[extra_index..][0..body_len];
928 extra_index += body_len;937 extra_index += body_len;
929938
930 var field_type_refs: std.ArrayListUnmanaged(DocData.TypeRef) = .{};939 var field_type_refs: std.ArrayListUnmanaged(DocData.TypeRef) = .{};
931 var field_name_indexes: std.ArrayListUnmanaged(usize) = .{};940 var field_name_indexes: std.ArrayListUnmanaged(usize) = .{};
932 try self.collectStructFieldInfo(941 try self.collectStructFieldInfo(
933 zir,942 file,
934 &scope,943 &scope,
935 fields_len,944 fields_len,
936 &field_type_refs,945 &field_type_refs,
...@@ -966,7 +975,7 @@ fn walkInstruction(...@@ -966,7 +975,7 @@ fn walkInstruction(
966/// slots in `self.decls`, which are then filled out by `walkDecls`.975/// slots in `self.decls`, which are then filled out by `walkDecls`.
967fn walkDecls(976fn walkDecls(
968 self: *Autodoc,977 self: *Autodoc,
969 zir: Zir,978 file: *File,
970 scope: *Scope,979 scope: *Scope,
971 decls_first_index: usize,980 decls_first_index: usize,
972 decls_len: u32,981 decls_len: u32,
...@@ -984,7 +993,7 @@ fn walkDecls(...@@ -984,7 +993,7 @@ fn walkDecls(
984 const decls_slot_index = decls_first_index + decl_i;993 const decls_slot_index = decls_first_index + decl_i;
985994
986 if (decl_i % 8 == 0) {995 if (decl_i % 8 == 0) {
987 cur_bit_bag = zir.extra[bit_bag_index];996 cur_bit_bag = file.zir.extra[bit_bag_index];
988 bit_bag_index += 1;997 bit_bag_index += 1;
989 }998 }
990 const is_pub = @truncate(u1, cur_bit_bag) != 0;999 const is_pub = @truncate(u1, cur_bit_bag) != 0;
...@@ -998,29 +1007,29 @@ fn walkDecls(...@@ -998,29 +1007,29 @@ fn walkDecls(
9981007
999 // const sub_index = extra_index;1008 // const sub_index = extra_index;
10001009
1001 // const hash_u32s = zir.extra[extra_index..][0..4];1010 // const hash_u32s = file.zir.extra[extra_index..][0..4];
1002 extra_index += 4;1011 extra_index += 4;
1003 // const line = zir.extra[extra_index];1012 // const line = file.zir.extra[extra_index];
1004 extra_index += 1;1013 extra_index += 1;
1005 const decl_name_index = zir.extra[extra_index];1014 const decl_name_index = file.zir.extra[extra_index];
1006 extra_index += 1;1015 extra_index += 1;
1007 const decl_index = zir.extra[extra_index];1016 const decl_index = file.zir.extra[extra_index];
1008 extra_index += 1;1017 extra_index += 1;
1009 const doc_comment_index = zir.extra[extra_index];1018 const doc_comment_index = file.zir.extra[extra_index];
1010 extra_index += 1;1019 extra_index += 1;
10111020
1012 // const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: {1021 // const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: {
1013 // const inst = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);1022 // const inst = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1014 // extra_index += 1;1023 // extra_index += 1;
1015 // break :inst inst;1024 // break :inst inst;
1016 // };1025 // };
1017 // const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {1026 // const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
1018 // const inst = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);1027 // const inst = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1019 // extra_index += 1;1028 // extra_index += 1;
1020 // break :inst inst;1029 // break :inst inst;
1021 // };1030 // };
1022 // const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {1031 // const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
1023 // const inst = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);1032 // const inst = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1024 // extra_index += 1;1033 // extra_index += 1;
1025 // break :inst inst;1034 // break :inst inst;
1026 // };1035 // };
...@@ -1034,9 +1043,9 @@ fn walkDecls(...@@ -1034,9 +1043,9 @@ fn walkDecls(
1034 } else if (decl_name_index == 1) {1043 } else if (decl_name_index == 1) {
1035 break :blk "test";1044 break :blk "test";
1036 } else {1045 } else {
1037 const raw_decl_name = zir.nullTerminatedString(decl_name_index);1046 const raw_decl_name = file.zir.nullTerminatedString(decl_name_index);
1038 if (raw_decl_name.len == 0) {1047 if (raw_decl_name.len == 0) {
1039 break :blk zir.nullTerminatedString(decl_name_index + 1);1048 break :blk file.zir.nullTerminatedString(decl_name_index + 1);
1040 } else {1049 } else {
1041 break :blk raw_decl_name;1050 break :blk raw_decl_name;
1042 }1051 }
...@@ -1044,7 +1053,7 @@ fn walkDecls(...@@ -1044,7 +1053,7 @@ fn walkDecls(
1044 };1053 };
10451054
1046 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)1055 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)
1047 zir.nullTerminatedString(doc_comment_index)1056 file.zir.nullTerminatedString(doc_comment_index)
1048 else1057 else
1049 null;1058 null;
10501059
...@@ -1061,7 +1070,7 @@ fn walkDecls(...@@ -1061,7 +1070,7 @@ fn walkDecls(
1061 break :idx idx;1070 break :idx idx;
1062 };1071 };
10631072
1064 const walk_result = try self.walkInstruction(zir, scope, decl_index);1073 const walk_result = try self.walkInstruction(file, scope, decl_index);
10651074
1066 if (is_pub) {1075 if (is_pub) {
1067 try decl_indexes.append(self.arena, decls_slot_index);1076 try decl_indexes.append(self.arena, decls_slot_index);
...@@ -1098,7 +1107,7 @@ fn walkDecls(...@@ -1098,7 +1107,7 @@ fn walkDecls(
10981107
1099fn collectUnionFieldInfo(1108fn collectUnionFieldInfo(
1100 self: *Autodoc,1109 self: *Autodoc,
1101 zir: Zir,1110 file: *File,
1102 scope: *Scope,1111 scope: *Scope,
1103 fields_len: usize,1112 fields_len: usize,
1104 field_type_refs: *std.ArrayListUnmanaged(DocData.TypeRef),1113 field_type_refs: *std.ArrayListUnmanaged(DocData.TypeRef),
...@@ -1118,7 +1127,7 @@ fn collectUnionFieldInfo(...@@ -1118,7 +1127,7 @@ fn collectUnionFieldInfo(
1118 var field_i: u32 = 0;1127 var field_i: u32 = 0;
1119 while (field_i < fields_len) : (field_i += 1) {1128 while (field_i < fields_len) : (field_i += 1) {
1120 if (field_i % fields_per_u32 == 0) {1129 if (field_i % fields_per_u32 == 0) {
1121 cur_bit_bag = zir.extra[bit_bag_index];1130 cur_bit_bag = file.zir.extra[bit_bag_index];
1122 bit_bag_index += 1;1131 bit_bag_index += 1;
1123 }1132 }
1124 const has_type = @truncate(u1, cur_bit_bag) != 0;1133 const has_type = @truncate(u1, cur_bit_bag) != 0;
...@@ -1131,12 +1140,12 @@ fn collectUnionFieldInfo(...@@ -1131,12 +1140,12 @@ fn collectUnionFieldInfo(
1131 cur_bit_bag >>= 1;1140 cur_bit_bag >>= 1;
1132 _ = unused;1141 _ = unused;
11331142
1134 const field_name = zir.nullTerminatedString(zir.extra[extra_index]);1143 const field_name = file.zir.nullTerminatedString(file.zir.extra[extra_index]);
1135 extra_index += 1;1144 extra_index += 1;
1136 const doc_comment_index = zir.extra[extra_index];1145 const doc_comment_index = file.zir.extra[extra_index];
1137 extra_index += 1;1146 extra_index += 1;
1138 const field_type = if (has_type)1147 const field_type = if (has_type)
1139 @intToEnum(Zir.Inst.Ref, zir.extra[extra_index])1148 @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index])
1140 else1149 else
1141 .void_type;1150 .void_type;
1142 extra_index += 1;1151 extra_index += 1;
...@@ -1146,7 +1155,7 @@ fn collectUnionFieldInfo(...@@ -1146,7 +1155,7 @@ fn collectUnionFieldInfo(
11461155
1147 // type1156 // type
1148 {1157 {
1149 const walk_result = try self.walkRef(zir, scope, field_type);1158 const walk_result = try self.walkRef(file, scope, field_type);
1150 try field_type_refs.append(1159 try field_type_refs.append(
1151 self.arena,1160 self.arena,
1152 walkResultToTypeRef(walk_result),1161 walkResultToTypeRef(walk_result),
...@@ -1157,7 +1166,7 @@ fn collectUnionFieldInfo(...@@ -1157,7 +1166,7 @@ fn collectUnionFieldInfo(
1157 {1166 {
1158 try field_name_indexes.append(self.arena, self.ast_nodes.items.len);1167 try field_name_indexes.append(self.arena, self.ast_nodes.items.len);
1159 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)1168 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)
1160 zir.nullTerminatedString(doc_comment_index)1169 file.zir.nullTerminatedString(doc_comment_index)
1161 else1170 else
1162 null;1171 null;
1163 try self.ast_nodes.append(self.arena, .{1172 try self.ast_nodes.append(self.arena, .{
...@@ -1170,7 +1179,7 @@ fn collectUnionFieldInfo(...@@ -1170,7 +1179,7 @@ fn collectUnionFieldInfo(
11701179
1171fn collectStructFieldInfo(1180fn collectStructFieldInfo(
1172 self: *Autodoc,1181 self: *Autodoc,
1173 zir: Zir,1182 file: *File,
1174 scope: *Scope,1183 scope: *Scope,
1175 fields_len: usize,1184 fields_len: usize,
1176 field_type_refs: *std.ArrayListUnmanaged(DocData.TypeRef),1185 field_type_refs: *std.ArrayListUnmanaged(DocData.TypeRef),
...@@ -1190,7 +1199,7 @@ fn collectStructFieldInfo(...@@ -1190,7 +1199,7 @@ fn collectStructFieldInfo(
1190 var field_i: u32 = 0;1199 var field_i: u32 = 0;
1191 while (field_i < fields_len) : (field_i += 1) {1200 while (field_i < fields_len) : (field_i += 1) {
1192 if (field_i % fields_per_u32 == 0) {1201 if (field_i % fields_per_u32 == 0) {
1193 cur_bit_bag = zir.extra[bit_bag_index];1202 cur_bit_bag = file.zir.extra[bit_bag_index];
1194 bit_bag_index += 1;1203 bit_bag_index += 1;
1195 }1204 }
1196 const has_align = @truncate(u1, cur_bit_bag) != 0;1205 const has_align = @truncate(u1, cur_bit_bag) != 0;
...@@ -1203,11 +1212,11 @@ fn collectStructFieldInfo(...@@ -1203,11 +1212,11 @@ fn collectStructFieldInfo(
1203 cur_bit_bag >>= 1;1212 cur_bit_bag >>= 1;
1204 _ = unused;1213 _ = unused;
12051214
1206 const field_name = zir.nullTerminatedString(zir.extra[extra_index]);1215 const field_name = file.zir.nullTerminatedString(file.zir.extra[extra_index]);
1207 extra_index += 1;1216 extra_index += 1;
1208 const field_type = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);1217 const field_type = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1209 extra_index += 1;1218 extra_index += 1;
1210 const doc_comment_index = zir.extra[extra_index];1219 const doc_comment_index = file.zir.extra[extra_index];
1211 extra_index += 1;1220 extra_index += 1;
12121221
1213 if (has_align) extra_index += 1;1222 if (has_align) extra_index += 1;
...@@ -1215,7 +1224,7 @@ fn collectStructFieldInfo(...@@ -1215,7 +1224,7 @@ fn collectStructFieldInfo(
12151224
1216 // type1225 // type
1217 {1226 {
1218 const walk_result = try self.walkRef(zir, scope, field_type);1227 const walk_result = try self.walkRef(file, scope, field_type);
1219 try field_type_refs.append(1228 try field_type_refs.append(
1220 self.arena,1229 self.arena,
1221 walkResultToTypeRef(walk_result),1230 walkResultToTypeRef(walk_result),
...@@ -1226,7 +1235,7 @@ fn collectStructFieldInfo(...@@ -1226,7 +1235,7 @@ fn collectStructFieldInfo(
1226 {1235 {
1227 try field_name_indexes.append(self.arena, self.ast_nodes.items.len);1236 try field_name_indexes.append(self.arena, self.ast_nodes.items.len);
1228 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)1237 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)
1229 zir.nullTerminatedString(doc_comment_index)1238 file.zir.nullTerminatedString(doc_comment_index)
1230 else1239 else
1231 null;1240 null;
1232 try self.ast_nodes.append(self.arena, .{1241 try self.ast_nodes.append(self.arena, .{
...@@ -1239,7 +1248,7 @@ fn collectStructFieldInfo(...@@ -1239,7 +1248,7 @@ fn collectStructFieldInfo(
12391248
1240fn walkRef(1249fn walkRef(
1241 self: *Autodoc,1250 self: *Autodoc,
1242 zir: Zir,1251 file: *File,
1243 parent_scope: *Scope,1252 parent_scope: *Scope,
1244 ref: Ref,1253 ref: Ref,
1245) !DocData.WalkResult {1254) !DocData.WalkResult {
...@@ -1327,7 +1336,7 @@ fn walkRef(...@@ -1327,7 +1336,7 @@ fn walkRef(
1327 }1336 }
1328 } else {1337 } else {
1329 const zir_index = enum_value - Ref.typed_value_map.len;1338 const zir_index = enum_value - Ref.typed_value_map.len;
1330 return self.walkInstruction(zir, parent_scope, zir_index);1339 return self.walkInstruction(file, parent_scope, zir_index);
1331 }1340 }
1332}1341}
13331342
...@@ -1343,6 +1352,6 @@ fn walkResultToTypeRef(wr: DocData.WalkResult) DocData.TypeRef {...@@ -1343,6 +1352,6 @@ fn walkResultToTypeRef(wr: DocData.WalkResult) DocData.TypeRef {
1343 };1352 };
1344}1353}
13451354
1346//fn collectParamInfo(self: *Autodoc, zir: Zir, scope: *Scope, inst_idx: Zir.Index) void {1355//fn collectParamInfo(self: *Autodoc, file: *File, scope: *Scope, inst_idx: Zir.Index) void {
13471356
1348//}1357//}