authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-08-27 22:47:58+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-08-27 22:48:18+02:00
loge0103704c5258ef887640df95fa9ccff9c1b331a
tree1b8b7b487756f55ed48b16b5f8921f74ca866ca4
parentee122643872b2a5958233cfeb24172c181d10be6

autodoc: better line counting for decls


2 files changed, 123 insertions(+), 60 deletions(-)

lib/docs/main.js+6-10
......@@ -54,7 +54,6 @@ var zigAnalysis;
5454 const sourceFileUrlTemplate = "src/{{file}}#L{{line}}"
5555 const domLangRefLink = document.getElementById("langRefLink");
5656
57 let lineCounter = 1;
5857 let searchTimer = null;
5958 let searchTrimResults = true;
6059
......@@ -413,8 +412,7 @@ var zigAnalysis;
413412 if (curNavSearch !== "") {
414413 return renderSearch();
415414 }
416
417 lineCounter = 1;
415
418416
419417 let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
420418 let pkg = rootPkg;
......@@ -445,10 +443,6 @@ var zigAnalysis;
445443 }
446444
447445 currentType = childDecl;
448 if ("src" in currentType) {
449 const ast_node = zigAnalysis.astNodes[currentType.src];
450 lineCounter += ast_node.line;
451 }
452446 curNav.declObjs.push(currentType);
453447 }
454448
......@@ -2289,9 +2283,9 @@ var zigAnalysis;
22892283 function renderSourceFileLink(decl) {
22902284 let srcNode = zigAnalysis.astNodes[decl.src];
22912285
2292 return "<a style=\"float: right;\" href=\"" +
2293 sourceFileUrlTemplate.replace("{{file}}",
2294 zigAnalysis.files[srcNode.file]).replace("{{line}}", lineCounter + srcNode.line) + "\">[src]</a>";
2286 return "<a style=\"float: right;\" href=\"" +
2287 sourceFileUrlTemplate.replace("{{file}}",
2288 zigAnalysis.files[srcNode.file]).replace("{{line}}", srcNode.line) + "\">[src]</a>";
22952289 }
22962290
22972291 function renderContainer(container) {
......@@ -3290,6 +3284,8 @@ var zigAnalysis;
32903284 break;
32913285 case "s":
32923286 if (domHelpModal.classList.contains("hidden")) {
3287 if (ev.target == domSearch) break;
3288
32933289 domSearch.focus();
32943290 domSearch.select();
32953291 domDocs.scrollTo(0, 0);
src/Autodoc.zig+117-50
......@@ -195,10 +195,14 @@ pub fn generateZirData(self: *Autodoc) !void {
195195 );
196196 }
197197
198 var root_scope = Scope{ .parent = null, .enclosing_type = main_type_index };
198 var root_scope = Scope{
199 .parent = null,
200 .enclosing_type = main_type_index,
201 };
202
199203 try self.ast_nodes.append(self.arena, .{ .name = "(root)" });
200204 try self.files.put(self.arena, file, main_type_index);
201 _ = try self.walkInstruction(file, &root_scope, Zir.main_struct_inst, false);
205 _ = try self.walkInstruction(file, &root_scope, 1, Zir.main_struct_inst, false);
202206
203207 if (self.ref_paths_pending_on_decls.count() > 0) {
204208 @panic("some decl paths were never fully analized (pending on decls)");
......@@ -769,6 +773,7 @@ fn walkInstruction(
769773 self: *Autodoc,
770774 file: *File,
771775 parent_scope: *Scope,
776 parent_line: usize,
772777 inst_index: usize,
773778 need_type: bool, // true if the caller needs us to provide also a typeRef
774779) AutodocErrors!DocData.WalkResult {
......@@ -851,12 +856,16 @@ fn walkInstruction(
851856
852857 const new_file = self.module.import_table.get(abs_root_src_path).?;
853858
854 var root_scope = Scope{ .parent = null, .enclosing_type = main_type_index };
859 var root_scope = Scope{
860 .parent = null,
861 .enclosing_type = main_type_index,
862 };
855863 try self.ast_nodes.append(self.arena, .{ .name = "(root)" });
856864 try self.files.put(self.arena, new_file, main_type_index);
857865 return self.walkInstruction(
858866 new_file,
859867 &root_scope,
868 1,
860869 Zir.main_struct_inst,
861870 false,
862871 );
......@@ -881,13 +890,14 @@ fn walkInstruction(
881890 return self.walkInstruction(
882891 new_file.file,
883892 &new_scope,
893 1,
884894 Zir.main_struct_inst,
885895 need_type,
886896 );
887897 },
888898 .ret_node => {
889899 const un_node = data[inst_index].un_node;
890 return self.walkRef(file, parent_scope, un_node.operand, false);
900 return self.walkRef(file, parent_scope, parent_line, un_node.operand, false);
891901 },
892902 .ret_load => {
893903 const un_node = data[inst_index].un_node;
......@@ -918,7 +928,7 @@ fn walkInstruction(
918928 }
919929
920930 if (result_ref) |rr| {
921 return self.walkRef(file, parent_scope, rr, need_type);
931 return self.walkRef(file, parent_scope, parent_line, rr, need_type);
922932 }
923933
924934 return DocData.WalkResult{
......@@ -927,11 +937,11 @@ fn walkInstruction(
927937 },
928938 .closure_get => {
929939 const inst_node = data[inst_index].inst_node;
930 return try self.walkInstruction(file, parent_scope, inst_node.inst, need_type);
940 return try self.walkInstruction(file, parent_scope, parent_line, inst_node.inst, need_type);
931941 },
932942 .closure_capture => {
933943 const un_tok = data[inst_index].un_tok;
934 return try self.walkRef(file, parent_scope, un_tok.operand, need_type);
944 return try self.walkRef(file, parent_scope, parent_line, un_tok.operand, need_type);
935945 },
936946 .cmpxchg_strong, .cmpxchg_weak => {
937947 const pl_node = data[inst_index].pl_node;
......@@ -946,6 +956,7 @@ fn walkInstruction(
946956 var ptr: DocData.WalkResult = try self.walkRef(
947957 file,
948958 parent_scope,
959 parent_line,
949960 extra.data.ptr,
950961 false,
951962 );
......@@ -955,6 +966,7 @@ fn walkInstruction(
955966 var expected_value: DocData.WalkResult = try self.walkRef(
956967 file,
957968 parent_scope,
969 parent_line,
958970 extra.data.expected_value,
959971 false,
960972 );
......@@ -964,6 +976,7 @@ fn walkInstruction(
964976 var new_value: DocData.WalkResult = try self.walkRef(
965977 file,
966978 parent_scope,
979 parent_line,
967980 extra.data.new_value,
968981 false,
969982 );
......@@ -973,6 +986,7 @@ fn walkInstruction(
973986 var success_order: DocData.WalkResult = try self.walkRef(
974987 file,
975988 parent_scope,
989 parent_line,
976990 extra.data.success_order,
977991 false,
978992 );
......@@ -982,6 +996,7 @@ fn walkInstruction(
982996 var failure_order: DocData.WalkResult = try self.walkRef(
983997 file,
984998 parent_scope,
999 parent_line,
9851000 extra.data.failure_order,
9861001 false,
9871002 );
......@@ -1035,6 +1050,7 @@ fn walkInstruction(
10351050 var operand: DocData.WalkResult = try self.walkRef(
10361051 file,
10371052 parent_scope,
1053 parent_line,
10381054 un_node.operand,
10391055 false,
10401056 );
......@@ -1089,12 +1105,14 @@ fn walkInstruction(
10891105 var lhs: DocData.WalkResult = try self.walkRef(
10901106 file,
10911107 parent_scope,
1108 parent_line,
10921109 extra.data.lhs,
10931110 false,
10941111 );
10951112 var start: DocData.WalkResult = try self.walkRef(
10961113 file,
10971114 parent_scope,
1115 parent_line,
10981116 extra.data.start,
10991117 false,
11001118 );
......@@ -1120,18 +1138,21 @@ fn walkInstruction(
11201138 var lhs: DocData.WalkResult = try self.walkRef(
11211139 file,
11221140 parent_scope,
1141 parent_line,
11231142 extra.data.lhs,
11241143 false,
11251144 );
11261145 var start: DocData.WalkResult = try self.walkRef(
11271146 file,
11281147 parent_scope,
1148 parent_line,
11291149 extra.data.start,
11301150 false,
11311151 );
11321152 var end: DocData.WalkResult = try self.walkRef(
11331153 file,
11341154 parent_scope,
1155 parent_line,
11351156 extra.data.end,
11361157 false,
11371158 );
......@@ -1159,24 +1180,28 @@ fn walkInstruction(
11591180 var lhs: DocData.WalkResult = try self.walkRef(
11601181 file,
11611182 parent_scope,
1183 parent_line,
11621184 extra.data.lhs,
11631185 false,
11641186 );
11651187 var start: DocData.WalkResult = try self.walkRef(
11661188 file,
11671189 parent_scope,
1190 parent_line,
11681191 extra.data.start,
11691192 false,
11701193 );
11711194 var end: DocData.WalkResult = try self.walkRef(
11721195 file,
11731196 parent_scope,
1197 parent_line,
11741198 extra.data.end,
11751199 false,
11761200 );
11771201 var sentinel: DocData.WalkResult = try self.walkRef(
11781202 file,
11791203 parent_scope,
1204 parent_line,
11801205 extra.data.sentinel,
11811206 false,
11821207 );
......@@ -1226,12 +1251,14 @@ fn walkInstruction(
12261251 var lhs: DocData.WalkResult = try self.walkRef(
12271252 file,
12281253 parent_scope,
1254 parent_line,
12291255 extra.data.lhs,
12301256 false,
12311257 );
12321258 var rhs: DocData.WalkResult = try self.walkRef(
12331259 file,
12341260 parent_scope,
1261 parent_line,
12351262 extra.data.rhs,
12361263 false,
12371264 );
......@@ -1292,7 +1319,7 @@ fn walkInstruction(
12921319 const un_node = data[inst_index].un_node;
12931320 const bin_index = self.exprs.items.len;
12941321 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });
1295 const param = try self.walkRef(file, parent_scope, un_node.operand, false);
1322 const param = try self.walkRef(file, parent_scope, parent_line, un_node.operand, false);
12961323
12971324 const param_index = self.exprs.items.len;
12981325 try self.exprs.append(self.arena, param.expr);
......@@ -1341,12 +1368,14 @@ fn walkInstruction(
13411368 var lhs: DocData.WalkResult = try self.walkRef(
13421369 file,
13431370 parent_scope,
1371 parent_line,
13441372 extra.data.lhs,
13451373 false,
13461374 );
13471375 var rhs: DocData.WalkResult = try self.walkRef(
13481376 file,
13491377 parent_scope,
1378 parent_line,
13501379 extra.data.rhs,
13511380 false,
13521381 );
......@@ -1369,12 +1398,14 @@ fn walkInstruction(
13691398 var lhs: DocData.WalkResult = try self.walkRef(
13701399 file,
13711400 parent_scope,
1401 parent_line,
13721402 extra.data.lhs,
13731403 false,
13741404 );
13751405 var rhs: DocData.WalkResult = try self.walkRef(
13761406 file,
13771407 parent_scope,
1408 parent_line,
13781409 extra.data.rhs,
13791410 false,
13801411 );
......@@ -1397,12 +1428,14 @@ fn walkInstruction(
13971428 var lhs: DocData.WalkResult = try self.walkRef(
13981429 file,
13991430 parent_scope,
1431 parent_line,
14001432 extra.data.lhs,
14011433 false,
14021434 );
14031435 var rhs: DocData.WalkResult = try self.walkRef(
14041436 file,
14051437 parent_scope,
1438 parent_line,
14061439 extra.data.rhs,
14071440 false,
14081441 );
......@@ -1422,7 +1455,7 @@ fn walkInstruction(
14221455
14231456 // var operand: DocData.WalkResult = try self.walkRef(
14241457 // file,
1425 // parent_scope,
1458 // parent_scope, parent_line,
14261459 // un_node.operand,
14271460 // false,
14281461 // );
......@@ -1431,7 +1464,7 @@ fn walkInstruction(
14311464 // },
14321465 .overflow_arithmetic_ptr => {
14331466 const un_node = data[inst_index].un_node;
1434 const elem_type_ref = try self.walkRef(file, parent_scope, un_node.operand, false);
1467 const elem_type_ref = try self.walkRef(file, parent_scope, parent_line, un_node.operand, false);
14351468 const type_slot_index = self.types.items.len;
14361469 try self.types.append(self.arena, .{
14371470 .Pointer = .{
......@@ -1456,6 +1489,7 @@ fn walkInstruction(
14561489 const elem_type_ref = try self.walkRef(
14571490 file,
14581491 parent_scope,
1492 parent_line,
14591493 extra.data.elem_type,
14601494 false,
14611495 );
......@@ -1465,7 +1499,7 @@ fn walkInstruction(
14651499 var sentinel: ?DocData.Expr = null;
14661500 if (ptr.flags.has_sentinel) {
14671501 const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1468 const ref_result = try self.walkRef(file, parent_scope, ref, false);
1502 const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false);
14691503 sentinel = ref_result.expr;
14701504 extra_index += 1;
14711505 }
......@@ -1473,21 +1507,21 @@ fn walkInstruction(
14731507 var @"align": ?DocData.Expr = null;
14741508 if (ptr.flags.has_align) {
14751509 const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1476 const ref_result = try self.walkRef(file, parent_scope, ref, false);
1510 const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false);
14771511 @"align" = ref_result.expr;
14781512 extra_index += 1;
14791513 }
14801514 var address_space: ?DocData.Expr = null;
14811515 if (ptr.flags.has_addrspace) {
14821516 const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1483 const ref_result = try self.walkRef(file, parent_scope, ref, false);
1517 const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false);
14841518 address_space = ref_result.expr;
14851519 extra_index += 1;
14861520 }
14871521 var bit_start: ?DocData.Expr = null;
14881522 if (ptr.flags.has_bit_range) {
14891523 const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1490 const ref_result = try self.walkRef(file, parent_scope, ref, false);
1524 const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false);
14911525 address_space = ref_result.expr;
14921526 extra_index += 1;
14931527 }
......@@ -1495,7 +1529,7 @@ fn walkInstruction(
14951529 var host_size: ?DocData.Expr = null;
14961530 if (ptr.flags.has_bit_range) {
14971531 const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
1498 const ref_result = try self.walkRef(file, parent_scope, ref, false);
1532 const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false);
14991533 host_size = ref_result.expr;
15001534 }
15011535
......@@ -1525,8 +1559,8 @@ fn walkInstruction(
15251559 .array_type => {
15261560 const pl_node = data[inst_index].pl_node;
15271561 const bin = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
1528 const len = try self.walkRef(file, parent_scope, bin.lhs, false);
1529 const child = try self.walkRef(file, parent_scope, bin.rhs, false);
1562 const len = try self.walkRef(file, parent_scope, parent_line, bin.lhs, false);
1563 const child = try self.walkRef(file, parent_scope, parent_line, bin.rhs, false);
15301564
15311565 const type_slot_index = self.types.items.len;
15321566 try self.types.append(self.arena, .{
......@@ -1544,9 +1578,9 @@ fn walkInstruction(
15441578 .array_type_sentinel => {
15451579 const pl_node = data[inst_index].pl_node;
15461580 const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index);
1547 const len = try self.walkRef(file, parent_scope, extra.data.len, false);
1548 const sentinel = try self.walkRef(file, parent_scope, extra.data.sentinel, false);
1549 const elem_type = try self.walkRef(file, parent_scope, extra.data.elem_type, false);
1581 const len = try self.walkRef(file, parent_scope, parent_line, extra.data.len, false);
1582 const sentinel = try self.walkRef(file, parent_scope, parent_line, extra.data.sentinel, false);
1583 const elem_type = try self.walkRef(file, parent_scope, parent_line, extra.data.elem_type, false);
15501584
15511585 const type_slot_index = self.types.items.len;
15521586 try self.types.append(self.arena, .{
......@@ -1568,10 +1602,10 @@ fn walkInstruction(
15681602 const array_data = try self.arena.alloc(usize, operands.len - 1);
15691603
15701604 std.debug.assert(operands.len > 0);
1571 var array_type = try self.walkRef(file, parent_scope, operands[0], false);
1605 var array_type = try self.walkRef(file, parent_scope, parent_line, operands[0], false);
15721606
15731607 for (operands[1..]) |op, idx| {
1574 const wr = try self.walkRef(file, parent_scope, op, false);
1608 const wr = try self.walkRef(file, parent_scope, parent_line, op, false);
15751609 const expr_index = self.exprs.items.len;
15761610 try self.exprs.append(self.arena, wr.expr);
15771611 array_data[idx] = expr_index;
......@@ -1589,7 +1623,7 @@ fn walkInstruction(
15891623 const array_data = try self.arena.alloc(usize, operands.len);
15901624
15911625 for (operands) |op, idx| {
1592 const wr = try self.walkRef(file, parent_scope, op, false);
1626 const wr = try self.walkRef(file, parent_scope, parent_line, op, false);
15931627 const expr_index = self.exprs.items.len;
15941628 try self.exprs.append(self.arena, wr.expr);
15951629 array_data[idx] = expr_index;
......@@ -1607,10 +1641,10 @@ fn walkInstruction(
16071641 const array_data = try self.arena.alloc(usize, operands.len - 1);
16081642
16091643 std.debug.assert(operands.len > 0);
1610 var array_type = try self.walkRef(file, parent_scope, operands[0], false);
1644 var array_type = try self.walkRef(file, parent_scope, parent_line, operands[0], false);
16111645
16121646 for (operands[1..]) |op, idx| {
1613 const wr = try self.walkRef(file, parent_scope, op, false);
1647 const wr = try self.walkRef(file, parent_scope, parent_line, op, false);
16141648 const expr_index = self.exprs.items.len;
16151649 try self.exprs.append(self.arena, wr.expr);
16161650 array_data[idx] = expr_index;
......@@ -1639,7 +1673,7 @@ fn walkInstruction(
16391673 const array_data = try self.arena.alloc(usize, operands.len);
16401674
16411675 for (operands) |op, idx| {
1642 const wr = try self.walkRef(file, parent_scope, op, false);
1676 const wr = try self.walkRef(file, parent_scope, parent_line, op, false);
16431677 const expr_index = self.exprs.items.len;
16441678 try self.exprs.append(self.arena, wr.expr);
16451679 array_data[idx] = expr_index;
......@@ -1674,6 +1708,7 @@ fn walkInstruction(
16741708 var operand: DocData.WalkResult = try self.walkRef(
16751709 file,
16761710 parent_scope,
1711 parent_line,
16771712 un_node.operand,
16781713 need_type,
16791714 );
......@@ -1695,6 +1730,7 @@ fn walkInstruction(
16951730 const operand = try self.walkRef(
16961731 file,
16971732 parent_scope,
1733 parent_line,
16981734 un_node.operand,
16991735 false,
17001736 );
......@@ -1711,6 +1747,7 @@ fn walkInstruction(
17111747 const operand = try self.walkRef(
17121748 file,
17131749 parent_scope,
1750 parent_line,
17141751 un_node.operand,
17151752 need_type,
17161753 );
......@@ -1728,6 +1765,7 @@ fn walkInstruction(
17281765 const operand = try self.walkRef(
17291766 file,
17301767 parent_scope,
1768 parent_line,
17311769 un_node.operand,
17321770 false,
17331771 );
......@@ -1744,7 +1782,7 @@ fn walkInstruction(
17441782 const pl_node = data[inst_index].pl_node;
17451783 const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index);
17461784 const cond_index = self.exprs.items.len;
1747 _ = try self.walkRef(file, parent_scope, extra.data.operand, false);
1785 _ = try self.walkRef(file, parent_scope, parent_line, extra.data.operand, false);
17481786
17491787 const ast_index = self.ast_nodes.items.len;
17501788 const type_index = self.types.items.len - 1;
......@@ -1772,6 +1810,7 @@ fn walkInstruction(
17721810 const operand = try self.walkRef(
17731811 file,
17741812 parent_scope,
1813 parent_line,
17751814 un_node.operand,
17761815 need_type,
17771816 );
......@@ -1797,6 +1836,7 @@ fn walkInstruction(
17971836 const operand = try self.walkRef(
17981837 file,
17991838 parent_scope,
1839 parent_line,
18001840 un_node.operand,
18011841 need_type,
18021842 );
......@@ -1816,6 +1856,7 @@ fn walkInstruction(
18161856 var operand: DocData.WalkResult = try self.walkRef(
18171857 file,
18181858 parent_scope,
1859 parent_line,
18191860 data[body].@"break".operand,
18201861 false,
18211862 );
......@@ -1834,6 +1875,7 @@ fn walkInstruction(
18341875 const operand = try self.walkRef(
18351876 file,
18361877 parent_scope,
1878 parent_line,
18371879 un_node.operand,
18381880 need_type,
18391881 );
......@@ -1852,6 +1894,7 @@ fn walkInstruction(
18521894 const dest_type_walk = try self.walkRef(
18531895 file,
18541896 parent_scope,
1897 parent_line,
18551898 extra.data.dest_type,
18561899 false,
18571900 );
......@@ -1859,6 +1902,7 @@ fn walkInstruction(
18591902 const operand = try self.walkRef(
18601903 file,
18611904 parent_scope,
1905 parent_line,
18621906 extra.data.operand,
18631907 false,
18641908 );
......@@ -1886,6 +1930,7 @@ fn walkInstruction(
18861930 const operand: DocData.WalkResult = try self.walkRef(
18871931 file,
18881932 parent_scope,
1933 parent_line,
18891934 un_node.operand,
18901935 false,
18911936 );
......@@ -1969,7 +2014,7 @@ fn walkInstruction(
19692014 }
19702015 }
19712016
1972 break :blk try self.walkRef(file, parent_scope, lhs_ref, false);
2017 break :blk try self.walkRef(file, parent_scope, parent_line, lhs_ref, false);
19732018 };
19742019 try path.append(self.arena, wr.expr);
19752020
......@@ -2020,6 +2065,7 @@ fn walkInstruction(
20202065 return self.walkRef(
20212066 file,
20222067 parent_scope,
2068 parent_line,
20232069 getBlockInlineBreak(file.zir, inst_index),
20242070 need_type,
20252071 );
......@@ -2052,6 +2098,7 @@ fn walkInstruction(
20522098 const wr = try self.walkRef(
20532099 file,
20542100 parent_scope,
2101 parent_line,
20552102 field_extra.data.container_type,
20562103 false,
20572104 );
......@@ -2062,6 +2109,7 @@ fn walkInstruction(
20622109 const value = try self.walkRef(
20632110 file,
20642111 parent_scope,
2112 parent_line,
20652113 init_extra.data.init,
20662114 need_type,
20672115 );
......@@ -2078,6 +2126,7 @@ fn walkInstruction(
20782126 var operand: DocData.WalkResult = try self.walkRef(
20792127 file,
20802128 parent_scope,
2129 parent_line,
20812130 un_node.operand,
20822131 false,
20832132 );
......@@ -2110,6 +2159,7 @@ fn walkInstruction(
21102159 const value = try self.walkRef(
21112160 file,
21122161 parent_scope,
2162 parent_line,
21132163 init_extra.data.init,
21142164 need_type,
21152165 );
......@@ -2185,7 +2235,7 @@ fn walkInstruction(
21852235 const pl_node = data[inst_index].pl_node;
21862236 const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index);
21872237
2188 const callee = try self.walkRef(file, parent_scope, extra.data.callee, need_type);
2238 const callee = try self.walkRef(file, parent_scope, parent_line, extra.data.callee, need_type);
21892239
21902240 const args_len = extra.data.flags.args_len;
21912241 var args = try self.arena.alloc(DocData.Expr, args_len);
......@@ -2200,7 +2250,7 @@ fn walkInstruction(
22002250 // to show discrepancies between the types of provided
22012251 // arguments and the types declared in the function
22022252 // signature for its parameters.
2203 const wr = try self.walkRef(file, parent_scope, ref, false);
2253 const wr = try self.walkRef(file, parent_scope, parent_line, ref, false);
22042254 args[i] = wr.expr;
22052255 }
22062256
......@@ -2231,6 +2281,7 @@ fn walkInstruction(
22312281 const result = self.analyzeFunction(
22322282 file,
22332283 parent_scope,
2284 parent_line,
22342285 inst_index,
22352286 self_ast_node_index,
22362287 type_slot_index,
......@@ -2246,6 +2297,7 @@ fn walkInstruction(
22462297 const result = self.analyzeFancyFunction(
22472298 file,
22482299 parent_scope,
2300 parent_line,
22492301 inst_index,
22502302 self_ast_node_index,
22512303 type_slot_index,
......@@ -2273,7 +2325,7 @@ fn walkInstruction(
22732325
22742326 var array_type: ?DocData.Expr = null;
22752327 for (args) |arg, idx| {
2276 const wr = try self.walkRef(file, parent_scope, arg, idx == 0);
2328 const wr = try self.walkRef(file, parent_scope, parent_line, arg, idx == 0);
22772329 if (idx == 0) {
22782330 array_type = wr.typeRef;
22792331 }
......@@ -2418,6 +2470,7 @@ fn walkInstruction(
24182470 extra_index = try self.walkDecls(
24192471 file,
24202472 &scope,
2473 parent_line,
24212474 decls_first_index,
24222475 decls_len,
24232476 &decl_indexes,
......@@ -2438,6 +2491,7 @@ fn walkInstruction(
24382491 try self.collectUnionFieldInfo(
24392492 file,
24402493 &scope,
2494 parent_line,
24412495 fields_len,
24422496 &field_type_refs,
24432497 &field_name_indexes,
......@@ -2538,6 +2592,7 @@ fn walkInstruction(
25382592 extra_index = try self.walkDecls(
25392593 file,
25402594 &scope,
2595 parent_line,
25412596 decls_first_index,
25422597 decls_len,
25432598 &decl_indexes,
......@@ -2681,6 +2736,7 @@ fn walkInstruction(
26812736 extra_index = try self.walkDecls(
26822737 file,
26832738 &scope,
2739 parent_line,
26842740 decls_first_index,
26852741 decls_len,
26862742 &decl_indexes,
......@@ -2693,6 +2749,7 @@ fn walkInstruction(
26932749 try self.collectStructFieldInfo(
26942750 file,
26952751 &scope,
2752 parent_line,
26962753 fields_len,
26972754 &field_type_refs,
26982755 &field_name_indexes,
......@@ -2736,7 +2793,7 @@ fn walkInstruction(
27362793 const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data;
27372794 const bin_index = self.exprs.items.len;
27382795 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });
2739 const param = try self.walkRef(file, parent_scope, extra.operand, false);
2796 const param = try self.walkRef(file, parent_scope, parent_line, extra.operand, false);
27402797
27412798 const param_index = self.exprs.items.len;
27422799 try self.exprs.append(self.arena, param.expr);
......@@ -2764,6 +2821,7 @@ fn walkDecls(
27642821 self: *Autodoc,
27652822 file: *File,
27662823 scope: *Scope,
2824 parent_line: usize,
27672825 decls_first_index: usize,
27682826 decls_len: u32,
27692827 decl_indexes: *std.ArrayListUnmanaged(usize),
......@@ -2796,7 +2854,7 @@ fn walkDecls(
27962854
27972855 // const hash_u32s = file.zir.extra[extra_index..][0..4];
27982856 extra_index += 4;
2799 const line = file.zir.extra[extra_index];
2857 const line = parent_line + file.zir.extra[extra_index];
28002858 extra_index += 1;
28012859 const decl_name_index = file.zir.extra[extra_index];
28022860 extra_index += 1;
......@@ -2936,7 +2994,7 @@ fn walkDecls(
29362994 const idx = self.ast_nodes.items.len;
29372995 try self.ast_nodes.append(self.arena, .{
29382996 .file = self.files.getIndex(file) orelse unreachable,
2939 .line = line, // TODO: calculate absolute line
2997 .line = line,
29402998 .col = 0,
29412999 .docs = doc_comment,
29423000 .fields = null, // walkInstruction will fill `fields` if necessary
......@@ -2947,7 +3005,7 @@ fn walkDecls(
29473005 const walk_result = if (is_test) // TODO: decide if tests should show up at all
29483006 DocData.WalkResult{ .expr = .{ .void = .{} } }
29493007 else
2950 try self.walkInstruction(file, scope, value_index, true);
3008 try self.walkInstruction(file, scope, line, value_index, true);
29513009
29523010 if (is_pub) {
29533011 try decl_indexes.append(self.arena, decls_slot_index);
......@@ -3343,6 +3401,7 @@ fn analyzeFancyFunction(
33433401 self: *Autodoc,
33443402 file: *File,
33453403 scope: *Scope,
3404 parent_line: usize,
33463405 inst_index: usize,
33473406 self_ast_node_index: usize,
33483407 type_slot_index: usize,
......@@ -3407,7 +3466,7 @@ fn analyzeFancyFunction(
34073466
34083467 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
34093468 const break_operand = data[break_index].@"break".operand;
3410 const param_type_ref = try self.walkRef(file, scope, break_operand, false);
3469 const param_type_ref = try self.walkRef(file, scope, parent_line, break_operand, false);
34113470
34123471 param_type_refs.appendAssumeCapacity(param_type_ref.expr);
34133472 },
......@@ -3431,7 +3490,7 @@ fn analyzeFancyFunction(
34313490 if (extra.data.bits.has_align_ref) {
34323491 const align_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
34333492 align_index = self.exprs.items.len;
3434 _ = try self.walkRef(file, scope, align_ref, false);
3493 _ = try self.walkRef(file, scope, parent_line, align_ref, false);
34353494 extra_index += 1;
34363495 } else if (extra.data.bits.has_align_body) {
34373496 const align_body_len = file.zir.extra[extra_index];
......@@ -3448,7 +3507,7 @@ fn analyzeFancyFunction(
34483507 if (extra.data.bits.has_addrspace_ref) {
34493508 const addrspace_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
34503509 addrspace_index = self.exprs.items.len;
3451 _ = try self.walkRef(file, scope, addrspace_ref, false);
3510 _ = try self.walkRef(file, scope, parent_line, addrspace_ref, false);
34523511 extra_index += 1;
34533512 } else if (extra.data.bits.has_addrspace_body) {
34543513 const addrspace_body_len = file.zir.extra[extra_index];
......@@ -3465,7 +3524,7 @@ fn analyzeFancyFunction(
34653524 if (extra.data.bits.has_section_ref) {
34663525 const section_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
34673526 section_index = self.exprs.items.len;
3468 _ = try self.walkRef(file, scope, section_ref, false);
3527 _ = try self.walkRef(file, scope, parent_line, section_ref, false);
34693528 extra_index += 1;
34703529 } else if (extra.data.bits.has_section_body) {
34713530 const section_body_len = file.zir.extra[extra_index];
......@@ -3482,7 +3541,7 @@ fn analyzeFancyFunction(
34823541 if (extra.data.bits.has_cc_ref) {
34833542 const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
34843543 cc_index = self.exprs.items.len;
3485 _ = try self.walkRef(file, scope, cc_ref, false);
3544 _ = try self.walkRef(file, scope, parent_line, cc_ref, false);
34863545 extra_index += 1;
34873546 } else if (extra.data.bits.has_cc_body) {
34883547 const cc_body_len = file.zir.extra[extra_index];
......@@ -3501,14 +3560,14 @@ fn analyzeFancyFunction(
35013560 .none => DocData.Expr{ .void = .{} },
35023561 else => blk: {
35033562 const ref = fn_info.ret_ty_ref;
3504 const wr = try self.walkRef(file, scope, ref, false);
3563 const wr = try self.walkRef(file, scope, parent_line, ref, false);
35053564 break :blk wr.expr;
35063565 },
35073566 },
35083567 else => blk: {
35093568 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
35103569 const break_operand = data[last_instr_index].@"break".operand;
3511 const wr = try self.walkRef(file, scope, break_operand, false);
3570 const wr = try self.walkRef(file, scope, parent_line, break_operand, false);
35123571 break :blk wr.expr;
35133572 },
35143573 };
......@@ -3523,6 +3582,7 @@ fn analyzeFancyFunction(
35233582 break :blk try self.getGenericReturnType(
35243583 file,
35253584 scope,
3585 parent_line,
35263586 fn_info.body[fn_info.body.len - 1],
35273587 );
35283588 } else {
......@@ -3559,6 +3619,7 @@ fn analyzeFunction(
35593619 self: *Autodoc,
35603620 file: *File,
35613621 scope: *Scope,
3622 parent_line: usize,
35623623 inst_index: usize,
35633624 self_ast_node_index: usize,
35643625 type_slot_index: usize,
......@@ -3624,7 +3685,7 @@ fn analyzeFunction(
36243685
36253686 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
36263687 const break_operand = data[break_index].@"break".operand;
3627 const param_type_ref = try self.walkRef(file, scope, break_operand, false);
3688 const param_type_ref = try self.walkRef(file, scope, parent_line, break_operand, false);
36283689
36293690 param_type_refs.appendAssumeCapacity(param_type_ref.expr);
36303691 },
......@@ -3637,14 +3698,14 @@ fn analyzeFunction(
36373698 .none => DocData.Expr{ .void = .{} },
36383699 else => blk: {
36393700 const ref = fn_info.ret_ty_ref;
3640 const wr = try self.walkRef(file, scope, ref, false);
3701 const wr = try self.walkRef(file, scope, parent_line, ref, false);
36413702 break :blk wr.expr;
36423703 },
36433704 },
36443705 else => blk: {
36453706 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
36463707 const break_operand = data[last_instr_index].@"break".operand;
3647 const wr = try self.walkRef(file, scope, break_operand, false);
3708 const wr = try self.walkRef(file, scope, parent_line, break_operand, false);
36483709 break :blk wr.expr;
36493710 },
36503711 };
......@@ -3659,6 +3720,7 @@ fn analyzeFunction(
36593720 break :blk try self.getGenericReturnType(
36603721 file,
36613722 scope,
3723 parent_line,
36623724 fn_info.body[fn_info.body.len - 1],
36633725 );
36643726 } else {
......@@ -3699,9 +3761,11 @@ fn getGenericReturnType(
36993761 self: *Autodoc,
37003762 file: *File,
37013763 scope: *Scope,
3764 parent_line: usize, // function decl line
37023765 body_end: usize,
37033766) !DocData.Expr {
3704 const wr = try self.walkInstruction(file, scope, body_end, false);
3767 // TODO: compute the correct line offset
3768 const wr = try self.walkInstruction(file, scope, parent_line, body_end, false);
37053769 return wr.expr;
37063770}
37073771
......@@ -3709,6 +3773,7 @@ fn collectUnionFieldInfo(
37093773 self: *Autodoc,
37103774 file: *File,
37113775 scope: *Scope,
3776 parent_line: usize,
37123777 fields_len: usize,
37133778 field_type_refs: *std.ArrayListUnmanaged(DocData.Expr),
37143779 field_name_indexes: *std.ArrayListUnmanaged(usize),
......@@ -3755,7 +3820,7 @@ fn collectUnionFieldInfo(
37553820
37563821 // type
37573822 {
3758 const walk_result = try self.walkRef(file, scope, field_type, false);
3823 const walk_result = try self.walkRef(file, scope, parent_line, field_type, false);
37593824 try field_type_refs.append(self.arena, walk_result.expr);
37603825 }
37613826
......@@ -3778,6 +3843,7 @@ fn collectStructFieldInfo(
37783843 self: *Autodoc,
37793844 file: *File,
37803845 scope: *Scope,
3846 parent_line: usize,
37813847 fields_len: usize,
37823848 field_type_refs: *std.ArrayListUnmanaged(DocData.Expr),
37833849 field_name_indexes: *std.ArrayListUnmanaged(usize),
......@@ -3851,7 +3917,7 @@ fn collectStructFieldInfo(
38513917 for (fields) |field| {
38523918 const type_expr = expr: {
38533919 if (field.type_ref != .none) {
3854 const walk_result = try self.walkRef(file, scope, field.type_ref, false);
3920 const walk_result = try self.walkRef(file, scope, parent_line, field.type_ref, false);
38553921 break :expr walk_result.expr;
38563922 }
38573923
......@@ -3861,7 +3927,7 @@ fn collectStructFieldInfo(
38613927
38623928 const break_inst = body[body.len - 1];
38633929 const operand = data[break_inst].@"break".operand;
3864 const walk_result = try self.walkRef(file, scope, operand, false);
3930 const walk_result = try self.walkRef(file, scope, parent_line, operand, false);
38653931 break :expr walk_result.expr;
38663932 };
38673933
......@@ -3891,6 +3957,7 @@ fn walkRef(
38913957 self: *Autodoc,
38923958 file: *File,
38933959 parent_scope: *Scope,
3960 parent_line: usize,
38943961 ref: Ref,
38953962 need_type: bool, // true when the caller needs also a typeRef for the return value
38963963) AutodocErrors!DocData.WalkResult {
......@@ -4002,7 +4069,7 @@ fn walkRef(
40024069 }
40034070 } else {
40044071 const zir_index = enum_value - Ref.typed_value_map.len;
4005 return self.walkInstruction(file, parent_scope, zir_index, need_type);
4072 return self.walkInstruction(file, parent_scope, parent_line, zir_index, need_type);
40064073 }
40074074}
40084075