| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const build_options = @import("build_options"); |
| 4 | const Ast = std.zig.Ast; |
| 4 | 5 | const Autodoc = @This(); |
| 5 | 6 | const Compilation = @import("Compilation.zig"); |
| 6 | 7 | const Module = @import("Module.zig"); |
| ... | ... | @@ -47,6 +48,19 @@ const RefPathResumeInfo = struct { |
| 47 | 48 | ref_path: []DocData.Expr, |
| 48 | 49 | }; |
| 49 | 50 | |
| 51 | /// Used to accumulate src_node offsets. |
| 52 | /// In ZIR, all ast node indices are relative to the parent decl. |
| 53 | /// More concretely, `union_decl`, `struct_decl`, `enum_decl` and `opaque_decl` |
| 54 | /// and the value of each of their decls participate in the relative offset |
| 55 | /// counting, and nothing else. |
| 56 | /// We keep track of the line and byte values for these instructions in order |
| 57 | /// to avoid tokenizing every file (on new lines) from the start every time. |
| 58 | const SrcLocInfo = struct { |
| 59 | bytes: u32 = 0, |
| 60 | line: usize = 0, |
| 61 | src_node: i32 = 0, |
| 62 | }; |
| 63 | |
| 50 | 64 | var arena_allocator: std.heap.ArenaAllocator = undefined; |
| 51 | 65 | pub fn init(m: *Module, doc_location: Compilation.EmitLoc) Autodoc { |
| 52 | 66 | arena_allocator = std.heap.ArenaAllocator.init(m.gpa); |
| ... | ... | @@ -202,7 +216,7 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 202 | 216 | |
| 203 | 217 | try self.ast_nodes.append(self.arena, .{ .name = "(root)" }); |
| 204 | 218 | try self.files.put(self.arena, file, main_type_index); |
| 205 | | _ = try self.walkInstruction(file, &root_scope, 1, Zir.main_struct_inst, false); |
| 219 | _ = try self.walkInstruction(file, &root_scope, .{}, Zir.main_struct_inst, false); |
| 206 | 220 | |
| 207 | 221 | if (self.ref_paths_pending_on_decls.count() > 0) { |
| 208 | 222 | @panic("some decl paths were never fully analized (pending on decls)"); |
| ... | ... | @@ -758,8 +772,8 @@ const DocData = struct { |
| 758 | 772 | const AutodocErrors = error{ |
| 759 | 773 | OutOfMemory, |
| 760 | 774 | CurrentWorkingDirectoryUnlinked, |
| 761 | | Unexpected, |
| 762 | | }; |
| 775 | UnexpectedEndOfFile, |
| 776 | } || std.fs.File.OpenError || std.fs.File.ReadError; |
| 763 | 777 | |
| 764 | 778 | /// Called when we need to analyze a Zir instruction. |
| 765 | 779 | /// For example it gets called by `generateZirData` on instruction 0, |
| ... | ... | @@ -773,7 +787,7 @@ fn walkInstruction( |
| 773 | 787 | self: *Autodoc, |
| 774 | 788 | file: *File, |
| 775 | 789 | parent_scope: *Scope, |
| 776 | | parent_line: usize, |
| 790 | parent_src: SrcLocInfo, |
| 777 | 791 | inst_index: usize, |
| 778 | 792 | need_type: bool, // true if the caller needs us to provide also a typeRef |
| 779 | 793 | ) AutodocErrors!DocData.WalkResult { |
| ... | ... | @@ -865,7 +879,7 @@ fn walkInstruction( |
| 865 | 879 | return self.walkInstruction( |
| 866 | 880 | new_file, |
| 867 | 881 | &root_scope, |
| 868 | | 1, |
| 882 | .{}, |
| 869 | 883 | Zir.main_struct_inst, |
| 870 | 884 | false, |
| 871 | 885 | ); |
| ... | ... | @@ -890,14 +904,14 @@ fn walkInstruction( |
| 890 | 904 | return self.walkInstruction( |
| 891 | 905 | new_file.file, |
| 892 | 906 | &new_scope, |
| 893 | | 1, |
| 907 | .{}, |
| 894 | 908 | Zir.main_struct_inst, |
| 895 | 909 | need_type, |
| 896 | 910 | ); |
| 897 | 911 | }, |
| 898 | 912 | .ret_node => { |
| 899 | 913 | const un_node = data[inst_index].un_node; |
| 900 | | return self.walkRef(file, parent_scope, parent_line, un_node.operand, false); |
| 914 | return self.walkRef(file, parent_scope, parent_src, un_node.operand, false); |
| 901 | 915 | }, |
| 902 | 916 | .ret_load => { |
| 903 | 917 | const un_node = data[inst_index].un_node; |
| ... | ... | @@ -928,7 +942,7 @@ fn walkInstruction( |
| 928 | 942 | } |
| 929 | 943 | |
| 930 | 944 | if (result_ref) |rr| { |
| 931 | | return self.walkRef(file, parent_scope, parent_line, rr, need_type); |
| 945 | return self.walkRef(file, parent_scope, parent_src, rr, need_type); |
| 932 | 946 | } |
| 933 | 947 | |
| 934 | 948 | return DocData.WalkResult{ |
| ... | ... | @@ -937,11 +951,11 @@ fn walkInstruction( |
| 937 | 951 | }, |
| 938 | 952 | .closure_get => { |
| 939 | 953 | const inst_node = data[inst_index].inst_node; |
| 940 | | return try self.walkInstruction(file, parent_scope, parent_line, inst_node.inst, need_type); |
| 954 | return try self.walkInstruction(file, parent_scope, parent_src, inst_node.inst, need_type); |
| 941 | 955 | }, |
| 942 | 956 | .closure_capture => { |
| 943 | 957 | const un_tok = data[inst_index].un_tok; |
| 944 | | return try self.walkRef(file, parent_scope, parent_line, un_tok.operand, need_type); |
| 958 | return try self.walkRef(file, parent_scope, parent_src, un_tok.operand, need_type); |
| 945 | 959 | }, |
| 946 | 960 | .cmpxchg_strong, .cmpxchg_weak => { |
| 947 | 961 | const pl_node = data[inst_index].pl_node; |
| ... | ... | @@ -956,7 +970,7 @@ fn walkInstruction( |
| 956 | 970 | var ptr: DocData.WalkResult = try self.walkRef( |
| 957 | 971 | file, |
| 958 | 972 | parent_scope, |
| 959 | | parent_line, |
| 973 | parent_src, |
| 960 | 974 | extra.data.ptr, |
| 961 | 975 | false, |
| 962 | 976 | ); |
| ... | ... | @@ -966,7 +980,7 @@ fn walkInstruction( |
| 966 | 980 | var expected_value: DocData.WalkResult = try self.walkRef( |
| 967 | 981 | file, |
| 968 | 982 | parent_scope, |
| 969 | | parent_line, |
| 983 | parent_src, |
| 970 | 984 | extra.data.expected_value, |
| 971 | 985 | false, |
| 972 | 986 | ); |
| ... | ... | @@ -976,7 +990,7 @@ fn walkInstruction( |
| 976 | 990 | var new_value: DocData.WalkResult = try self.walkRef( |
| 977 | 991 | file, |
| 978 | 992 | parent_scope, |
| 979 | | parent_line, |
| 993 | parent_src, |
| 980 | 994 | extra.data.new_value, |
| 981 | 995 | false, |
| 982 | 996 | ); |
| ... | ... | @@ -986,7 +1000,7 @@ fn walkInstruction( |
| 986 | 1000 | var success_order: DocData.WalkResult = try self.walkRef( |
| 987 | 1001 | file, |
| 988 | 1002 | parent_scope, |
| 989 | | parent_line, |
| 1003 | parent_src, |
| 990 | 1004 | extra.data.success_order, |
| 991 | 1005 | false, |
| 992 | 1006 | ); |
| ... | ... | @@ -996,7 +1010,7 @@ fn walkInstruction( |
| 996 | 1010 | var failure_order: DocData.WalkResult = try self.walkRef( |
| 997 | 1011 | file, |
| 998 | 1012 | parent_scope, |
| 999 | | parent_line, |
| 1013 | parent_src, |
| 1000 | 1014 | extra.data.failure_order, |
| 1001 | 1015 | false, |
| 1002 | 1016 | ); |
| ... | ... | @@ -1047,10 +1061,11 @@ fn walkInstruction( |
| 1047 | 1061 | }, |
| 1048 | 1062 | .compile_error => { |
| 1049 | 1063 | const un_node = data[inst_index].un_node; |
| 1064 | |
| 1050 | 1065 | var operand: DocData.WalkResult = try self.walkRef( |
| 1051 | 1066 | file, |
| 1052 | 1067 | parent_scope, |
| 1053 | | parent_line, |
| 1068 | parent_src, |
| 1054 | 1069 | un_node.operand, |
| 1055 | 1070 | false, |
| 1056 | 1071 | ); |
| ... | ... | @@ -1105,14 +1120,14 @@ fn walkInstruction( |
| 1105 | 1120 | var lhs: DocData.WalkResult = try self.walkRef( |
| 1106 | 1121 | file, |
| 1107 | 1122 | parent_scope, |
| 1108 | | parent_line, |
| 1123 | parent_src, |
| 1109 | 1124 | extra.data.lhs, |
| 1110 | 1125 | false, |
| 1111 | 1126 | ); |
| 1112 | 1127 | var start: DocData.WalkResult = try self.walkRef( |
| 1113 | 1128 | file, |
| 1114 | 1129 | parent_scope, |
| 1115 | | parent_line, |
| 1130 | parent_src, |
| 1116 | 1131 | extra.data.start, |
| 1117 | 1132 | false, |
| 1118 | 1133 | ); |
| ... | ... | @@ -1138,21 +1153,21 @@ fn walkInstruction( |
| 1138 | 1153 | var lhs: DocData.WalkResult = try self.walkRef( |
| 1139 | 1154 | file, |
| 1140 | 1155 | parent_scope, |
| 1141 | | parent_line, |
| 1156 | parent_src, |
| 1142 | 1157 | extra.data.lhs, |
| 1143 | 1158 | false, |
| 1144 | 1159 | ); |
| 1145 | 1160 | var start: DocData.WalkResult = try self.walkRef( |
| 1146 | 1161 | file, |
| 1147 | 1162 | parent_scope, |
| 1148 | | parent_line, |
| 1163 | parent_src, |
| 1149 | 1164 | extra.data.start, |
| 1150 | 1165 | false, |
| 1151 | 1166 | ); |
| 1152 | 1167 | var end: DocData.WalkResult = try self.walkRef( |
| 1153 | 1168 | file, |
| 1154 | 1169 | parent_scope, |
| 1155 | | parent_line, |
| 1170 | parent_src, |
| 1156 | 1171 | extra.data.end, |
| 1157 | 1172 | false, |
| 1158 | 1173 | ); |
| ... | ... | @@ -1180,28 +1195,28 @@ fn walkInstruction( |
| 1180 | 1195 | var lhs: DocData.WalkResult = try self.walkRef( |
| 1181 | 1196 | file, |
| 1182 | 1197 | parent_scope, |
| 1183 | | parent_line, |
| 1198 | parent_src, |
| 1184 | 1199 | extra.data.lhs, |
| 1185 | 1200 | false, |
| 1186 | 1201 | ); |
| 1187 | 1202 | var start: DocData.WalkResult = try self.walkRef( |
| 1188 | 1203 | file, |
| 1189 | 1204 | parent_scope, |
| 1190 | | parent_line, |
| 1205 | parent_src, |
| 1191 | 1206 | extra.data.start, |
| 1192 | 1207 | false, |
| 1193 | 1208 | ); |
| 1194 | 1209 | var end: DocData.WalkResult = try self.walkRef( |
| 1195 | 1210 | file, |
| 1196 | 1211 | parent_scope, |
| 1197 | | parent_line, |
| 1212 | parent_src, |
| 1198 | 1213 | extra.data.end, |
| 1199 | 1214 | false, |
| 1200 | 1215 | ); |
| 1201 | 1216 | var sentinel: DocData.WalkResult = try self.walkRef( |
| 1202 | 1217 | file, |
| 1203 | 1218 | parent_scope, |
| 1204 | | parent_line, |
| 1219 | parent_src, |
| 1205 | 1220 | extra.data.sentinel, |
| 1206 | 1221 | false, |
| 1207 | 1222 | ); |
| ... | ... | @@ -1251,14 +1266,14 @@ fn walkInstruction( |
| 1251 | 1266 | var lhs: DocData.WalkResult = try self.walkRef( |
| 1252 | 1267 | file, |
| 1253 | 1268 | parent_scope, |
| 1254 | | parent_line, |
| 1269 | parent_src, |
| 1255 | 1270 | extra.data.lhs, |
| 1256 | 1271 | false, |
| 1257 | 1272 | ); |
| 1258 | 1273 | var rhs: DocData.WalkResult = try self.walkRef( |
| 1259 | 1274 | file, |
| 1260 | 1275 | parent_scope, |
| 1261 | | parent_line, |
| 1276 | parent_src, |
| 1262 | 1277 | extra.data.rhs, |
| 1263 | 1278 | false, |
| 1264 | 1279 | ); |
| ... | ... | @@ -1319,7 +1334,7 @@ fn walkInstruction( |
| 1319 | 1334 | const un_node = data[inst_index].un_node; |
| 1320 | 1335 | const bin_index = self.exprs.items.len; |
| 1321 | 1336 | try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } }); |
| 1322 | | const param = try self.walkRef(file, parent_scope, parent_line, un_node.operand, false); |
| 1337 | const param = try self.walkRef(file, parent_scope, parent_src, un_node.operand, false); |
| 1323 | 1338 | |
| 1324 | 1339 | const param_index = self.exprs.items.len; |
| 1325 | 1340 | try self.exprs.append(self.arena, param.expr); |
| ... | ... | @@ -1368,14 +1383,14 @@ fn walkInstruction( |
| 1368 | 1383 | var lhs: DocData.WalkResult = try self.walkRef( |
| 1369 | 1384 | file, |
| 1370 | 1385 | parent_scope, |
| 1371 | | parent_line, |
| 1386 | parent_src, |
| 1372 | 1387 | extra.data.lhs, |
| 1373 | 1388 | false, |
| 1374 | 1389 | ); |
| 1375 | 1390 | var rhs: DocData.WalkResult = try self.walkRef( |
| 1376 | 1391 | file, |
| 1377 | 1392 | parent_scope, |
| 1378 | | parent_line, |
| 1393 | parent_src, |
| 1379 | 1394 | extra.data.rhs, |
| 1380 | 1395 | false, |
| 1381 | 1396 | ); |
| ... | ... | @@ -1398,14 +1413,14 @@ fn walkInstruction( |
| 1398 | 1413 | var lhs: DocData.WalkResult = try self.walkRef( |
| 1399 | 1414 | file, |
| 1400 | 1415 | parent_scope, |
| 1401 | | parent_line, |
| 1416 | parent_src, |
| 1402 | 1417 | extra.data.lhs, |
| 1403 | 1418 | false, |
| 1404 | 1419 | ); |
| 1405 | 1420 | var rhs: DocData.WalkResult = try self.walkRef( |
| 1406 | 1421 | file, |
| 1407 | 1422 | parent_scope, |
| 1408 | | parent_line, |
| 1423 | parent_src, |
| 1409 | 1424 | extra.data.rhs, |
| 1410 | 1425 | false, |
| 1411 | 1426 | ); |
| ... | ... | @@ -1428,14 +1443,14 @@ fn walkInstruction( |
| 1428 | 1443 | var lhs: DocData.WalkResult = try self.walkRef( |
| 1429 | 1444 | file, |
| 1430 | 1445 | parent_scope, |
| 1431 | | parent_line, |
| 1446 | parent_src, |
| 1432 | 1447 | extra.data.lhs, |
| 1433 | 1448 | false, |
| 1434 | 1449 | ); |
| 1435 | 1450 | var rhs: DocData.WalkResult = try self.walkRef( |
| 1436 | 1451 | file, |
| 1437 | 1452 | parent_scope, |
| 1438 | | parent_line, |
| 1453 | parent_src, |
| 1439 | 1454 | extra.data.rhs, |
| 1440 | 1455 | false, |
| 1441 | 1456 | ); |
| ... | ... | @@ -1455,7 +1470,7 @@ fn walkInstruction( |
| 1455 | 1470 | |
| 1456 | 1471 | // var operand: DocData.WalkResult = try self.walkRef( |
| 1457 | 1472 | // file, |
| 1458 | | // parent_scope, parent_line, |
| 1473 | // parent_scope, parent_src, |
| 1459 | 1474 | // un_node.operand, |
| 1460 | 1475 | // false, |
| 1461 | 1476 | // ); |
| ... | ... | @@ -1464,7 +1479,8 @@ fn walkInstruction( |
| 1464 | 1479 | // }, |
| 1465 | 1480 | .overflow_arithmetic_ptr => { |
| 1466 | 1481 | const un_node = data[inst_index].un_node; |
| 1467 | | const elem_type_ref = try self.walkRef(file, parent_scope, parent_line, un_node.operand, false); |
| 1482 | |
| 1483 | const elem_type_ref = try self.walkRef(file, parent_scope, parent_src, un_node.operand, false); |
| 1468 | 1484 | const type_slot_index = self.types.items.len; |
| 1469 | 1485 | try self.types.append(self.arena, .{ |
| 1470 | 1486 | .Pointer = .{ |
| ... | ... | @@ -1489,7 +1505,7 @@ fn walkInstruction( |
| 1489 | 1505 | const elem_type_ref = try self.walkRef( |
| 1490 | 1506 | file, |
| 1491 | 1507 | parent_scope, |
| 1492 | | parent_line, |
| 1508 | parent_src, |
| 1493 | 1509 | extra.data.elem_type, |
| 1494 | 1510 | false, |
| 1495 | 1511 | ); |
| ... | ... | @@ -1499,7 +1515,7 @@ fn walkInstruction( |
| 1499 | 1515 | var sentinel: ?DocData.Expr = null; |
| 1500 | 1516 | if (ptr.flags.has_sentinel) { |
| 1501 | 1517 | const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1502 | | const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false); |
| 1518 | const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false); |
| 1503 | 1519 | sentinel = ref_result.expr; |
| 1504 | 1520 | extra_index += 1; |
| 1505 | 1521 | } |
| ... | ... | @@ -1507,21 +1523,21 @@ fn walkInstruction( |
| 1507 | 1523 | var @"align": ?DocData.Expr = null; |
| 1508 | 1524 | if (ptr.flags.has_align) { |
| 1509 | 1525 | const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1510 | | const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false); |
| 1526 | const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false); |
| 1511 | 1527 | @"align" = ref_result.expr; |
| 1512 | 1528 | extra_index += 1; |
| 1513 | 1529 | } |
| 1514 | 1530 | var address_space: ?DocData.Expr = null; |
| 1515 | 1531 | if (ptr.flags.has_addrspace) { |
| 1516 | 1532 | const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1517 | | const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false); |
| 1533 | const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false); |
| 1518 | 1534 | address_space = ref_result.expr; |
| 1519 | 1535 | extra_index += 1; |
| 1520 | 1536 | } |
| 1521 | 1537 | var bit_start: ?DocData.Expr = null; |
| 1522 | 1538 | if (ptr.flags.has_bit_range) { |
| 1523 | 1539 | const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1524 | | const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false); |
| 1540 | const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false); |
| 1525 | 1541 | address_space = ref_result.expr; |
| 1526 | 1542 | extra_index += 1; |
| 1527 | 1543 | } |
| ... | ... | @@ -1529,7 +1545,7 @@ fn walkInstruction( |
| 1529 | 1545 | var host_size: ?DocData.Expr = null; |
| 1530 | 1546 | if (ptr.flags.has_bit_range) { |
| 1531 | 1547 | const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1532 | | const ref_result = try self.walkRef(file, parent_scope, parent_line, ref, false); |
| 1548 | const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false); |
| 1533 | 1549 | host_size = ref_result.expr; |
| 1534 | 1550 | } |
| 1535 | 1551 | |
| ... | ... | @@ -1558,9 +1574,10 @@ fn walkInstruction( |
| 1558 | 1574 | }, |
| 1559 | 1575 | .array_type => { |
| 1560 | 1576 | const pl_node = data[inst_index].pl_node; |
| 1577 | |
| 1561 | 1578 | const bin = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 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); |
| 1579 | const len = try self.walkRef(file, parent_scope, parent_src, bin.lhs, false); |
| 1580 | const child = try self.walkRef(file, parent_scope, parent_src, bin.rhs, false); |
| 1564 | 1581 | |
| 1565 | 1582 | const type_slot_index = self.types.items.len; |
| 1566 | 1583 | try self.types.append(self.arena, .{ |
| ... | ... | @@ -1578,9 +1595,9 @@ fn walkInstruction( |
| 1578 | 1595 | .array_type_sentinel => { |
| 1579 | 1596 | const pl_node = data[inst_index].pl_node; |
| 1580 | 1597 | const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index); |
| 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); |
| 1598 | const len = try self.walkRef(file, parent_scope, parent_src, extra.data.len, false); |
| 1599 | const sentinel = try self.walkRef(file, parent_scope, parent_src, extra.data.sentinel, false); |
| 1600 | const elem_type = try self.walkRef(file, parent_scope, parent_src, extra.data.elem_type, false); |
| 1584 | 1601 | |
| 1585 | 1602 | const type_slot_index = self.types.items.len; |
| 1586 | 1603 | try self.types.append(self.arena, .{ |
| ... | ... | @@ -1602,10 +1619,10 @@ fn walkInstruction( |
| 1602 | 1619 | const array_data = try self.arena.alloc(usize, operands.len - 1); |
| 1603 | 1620 | |
| 1604 | 1621 | std.debug.assert(operands.len > 0); |
| 1605 | | var array_type = try self.walkRef(file, parent_scope, parent_line, operands[0], false); |
| 1622 | var array_type = try self.walkRef(file, parent_scope, parent_src, operands[0], false); |
| 1606 | 1623 | |
| 1607 | 1624 | for (operands[1..]) |op, idx| { |
| 1608 | | const wr = try self.walkRef(file, parent_scope, parent_line, op, false); |
| 1625 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); |
| 1609 | 1626 | const expr_index = self.exprs.items.len; |
| 1610 | 1627 | try self.exprs.append(self.arena, wr.expr); |
| 1611 | 1628 | array_data[idx] = expr_index; |
| ... | ... | @@ -1623,7 +1640,7 @@ fn walkInstruction( |
| 1623 | 1640 | const array_data = try self.arena.alloc(usize, operands.len); |
| 1624 | 1641 | |
| 1625 | 1642 | for (operands) |op, idx| { |
| 1626 | | const wr = try self.walkRef(file, parent_scope, parent_line, op, false); |
| 1643 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); |
| 1627 | 1644 | const expr_index = self.exprs.items.len; |
| 1628 | 1645 | try self.exprs.append(self.arena, wr.expr); |
| 1629 | 1646 | array_data[idx] = expr_index; |
| ... | ... | @@ -1641,10 +1658,10 @@ fn walkInstruction( |
| 1641 | 1658 | const array_data = try self.arena.alloc(usize, operands.len - 1); |
| 1642 | 1659 | |
| 1643 | 1660 | std.debug.assert(operands.len > 0); |
| 1644 | | var array_type = try self.walkRef(file, parent_scope, parent_line, operands[0], false); |
| 1661 | var array_type = try self.walkRef(file, parent_scope, parent_src, operands[0], false); |
| 1645 | 1662 | |
| 1646 | 1663 | for (operands[1..]) |op, idx| { |
| 1647 | | const wr = try self.walkRef(file, parent_scope, parent_line, op, false); |
| 1664 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); |
| 1648 | 1665 | const expr_index = self.exprs.items.len; |
| 1649 | 1666 | try self.exprs.append(self.arena, wr.expr); |
| 1650 | 1667 | array_data[idx] = expr_index; |
| ... | ... | @@ -1673,7 +1690,7 @@ fn walkInstruction( |
| 1673 | 1690 | const array_data = try self.arena.alloc(usize, operands.len); |
| 1674 | 1691 | |
| 1675 | 1692 | for (operands) |op, idx| { |
| 1676 | | const wr = try self.walkRef(file, parent_scope, parent_line, op, false); |
| 1693 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); |
| 1677 | 1694 | const expr_index = self.exprs.items.len; |
| 1678 | 1695 | try self.exprs.append(self.arena, wr.expr); |
| 1679 | 1696 | array_data[idx] = expr_index; |
| ... | ... | @@ -1705,10 +1722,11 @@ fn walkInstruction( |
| 1705 | 1722 | }, |
| 1706 | 1723 | .negate => { |
| 1707 | 1724 | const un_node = data[inst_index].un_node; |
| 1725 | |
| 1708 | 1726 | var operand: DocData.WalkResult = try self.walkRef( |
| 1709 | 1727 | file, |
| 1710 | 1728 | parent_scope, |
| 1711 | | parent_line, |
| 1729 | parent_src, |
| 1712 | 1730 | un_node.operand, |
| 1713 | 1731 | need_type, |
| 1714 | 1732 | ); |
| ... | ... | @@ -1727,10 +1745,11 @@ fn walkInstruction( |
| 1727 | 1745 | }, |
| 1728 | 1746 | .size_of => { |
| 1729 | 1747 | const un_node = data[inst_index].un_node; |
| 1748 | |
| 1730 | 1749 | const operand = try self.walkRef( |
| 1731 | 1750 | file, |
| 1732 | 1751 | parent_scope, |
| 1733 | | parent_line, |
| 1752 | parent_src, |
| 1734 | 1753 | un_node.operand, |
| 1735 | 1754 | false, |
| 1736 | 1755 | ); |
| ... | ... | @@ -1744,10 +1763,11 @@ fn walkInstruction( |
| 1744 | 1763 | .bit_size_of => { |
| 1745 | 1764 | // not working correctly with `align()` |
| 1746 | 1765 | const un_node = data[inst_index].un_node; |
| 1766 | |
| 1747 | 1767 | const operand = try self.walkRef( |
| 1748 | 1768 | file, |
| 1749 | 1769 | parent_scope, |
| 1750 | | parent_line, |
| 1770 | parent_src, |
| 1751 | 1771 | un_node.operand, |
| 1752 | 1772 | need_type, |
| 1753 | 1773 | ); |
| ... | ... | @@ -1765,7 +1785,7 @@ fn walkInstruction( |
| 1765 | 1785 | const operand = try self.walkRef( |
| 1766 | 1786 | file, |
| 1767 | 1787 | parent_scope, |
| 1768 | | parent_line, |
| 1788 | parent_src, |
| 1769 | 1789 | un_node.operand, |
| 1770 | 1790 | false, |
| 1771 | 1791 | ); |
| ... | ... | @@ -1782,7 +1802,8 @@ fn walkInstruction( |
| 1782 | 1802 | const pl_node = data[inst_index].pl_node; |
| 1783 | 1803 | const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index); |
| 1784 | 1804 | const cond_index = self.exprs.items.len; |
| 1785 | | _ = try self.walkRef(file, parent_scope, parent_line, extra.data.operand, false); |
| 1805 | |
| 1806 | _ = try self.walkRef(file, parent_scope, parent_src, extra.data.operand, false); |
| 1786 | 1807 | |
| 1787 | 1808 | const ast_index = self.ast_nodes.items.len; |
| 1788 | 1809 | const type_index = self.types.items.len - 1; |
| ... | ... | @@ -1810,7 +1831,7 @@ fn walkInstruction( |
| 1810 | 1831 | const operand = try self.walkRef( |
| 1811 | 1832 | file, |
| 1812 | 1833 | parent_scope, |
| 1813 | | parent_line, |
| 1834 | parent_src, |
| 1814 | 1835 | un_node.operand, |
| 1815 | 1836 | need_type, |
| 1816 | 1837 | ); |
| ... | ... | @@ -1833,10 +1854,11 @@ fn walkInstruction( |
| 1833 | 1854 | |
| 1834 | 1855 | .typeof => { |
| 1835 | 1856 | const un_node = data[inst_index].un_node; |
| 1857 | |
| 1836 | 1858 | const operand = try self.walkRef( |
| 1837 | 1859 | file, |
| 1838 | 1860 | parent_scope, |
| 1839 | | parent_line, |
| 1861 | parent_src, |
| 1840 | 1862 | un_node.operand, |
| 1841 | 1863 | need_type, |
| 1842 | 1864 | ); |
| ... | ... | @@ -1852,11 +1874,10 @@ fn walkInstruction( |
| 1852 | 1874 | const pl_node = data[inst_index].pl_node; |
| 1853 | 1875 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 1854 | 1876 | const body = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 1855 | | |
| 1856 | 1877 | var operand: DocData.WalkResult = try self.walkRef( |
| 1857 | 1878 | file, |
| 1858 | 1879 | parent_scope, |
| 1859 | | parent_line, |
| 1880 | parent_src, |
| 1860 | 1881 | data[body].@"break".operand, |
| 1861 | 1882 | false, |
| 1862 | 1883 | ); |
| ... | ... | @@ -1872,10 +1893,11 @@ fn walkInstruction( |
| 1872 | 1893 | .type_info => { |
| 1873 | 1894 | // @check |
| 1874 | 1895 | const un_node = data[inst_index].un_node; |
| 1896 | |
| 1875 | 1897 | const operand = try self.walkRef( |
| 1876 | 1898 | file, |
| 1877 | 1899 | parent_scope, |
| 1878 | | parent_line, |
| 1900 | parent_src, |
| 1879 | 1901 | un_node.operand, |
| 1880 | 1902 | need_type, |
| 1881 | 1903 | ); |
| ... | ... | @@ -1894,7 +1916,7 @@ fn walkInstruction( |
| 1894 | 1916 | const dest_type_walk = try self.walkRef( |
| 1895 | 1917 | file, |
| 1896 | 1918 | parent_scope, |
| 1897 | | parent_line, |
| 1919 | parent_src, |
| 1898 | 1920 | extra.data.dest_type, |
| 1899 | 1921 | false, |
| 1900 | 1922 | ); |
| ... | ... | @@ -1902,7 +1924,7 @@ fn walkInstruction( |
| 1902 | 1924 | const operand = try self.walkRef( |
| 1903 | 1925 | file, |
| 1904 | 1926 | parent_scope, |
| 1905 | | parent_line, |
| 1927 | parent_src, |
| 1906 | 1928 | extra.data.operand, |
| 1907 | 1929 | false, |
| 1908 | 1930 | ); |
| ... | ... | @@ -1927,10 +1949,11 @@ fn walkInstruction( |
| 1927 | 1949 | }, |
| 1928 | 1950 | .optional_type => { |
| 1929 | 1951 | const un_node = data[inst_index].un_node; |
| 1952 | |
| 1930 | 1953 | const operand: DocData.WalkResult = try self.walkRef( |
| 1931 | 1954 | file, |
| 1932 | 1955 | parent_scope, |
| 1933 | | parent_line, |
| 1956 | parent_src, |
| 1934 | 1957 | un_node.operand, |
| 1935 | 1958 | false, |
| 1936 | 1959 | ); |
| ... | ... | @@ -2014,7 +2037,7 @@ fn walkInstruction( |
| 2014 | 2037 | } |
| 2015 | 2038 | } |
| 2016 | 2039 | |
| 2017 | | break :blk try self.walkRef(file, parent_scope, parent_line, lhs_ref, false); |
| 2040 | break :blk try self.walkRef(file, parent_scope, parent_src, lhs_ref, false); |
| 2018 | 2041 | }; |
| 2019 | 2042 | try path.append(self.arena, wr.expr); |
| 2020 | 2043 | |
| ... | ... | @@ -2065,7 +2088,7 @@ fn walkInstruction( |
| 2065 | 2088 | return self.walkRef( |
| 2066 | 2089 | file, |
| 2067 | 2090 | parent_scope, |
| 2068 | | parent_line, |
| 2091 | parent_src, |
| 2069 | 2092 | getBlockInlineBreak(file.zir, inst_index), |
| 2070 | 2093 | need_type, |
| 2071 | 2094 | ); |
| ... | ... | @@ -2092,13 +2115,18 @@ fn walkInstruction( |
| 2092 | 2115 | Zir.Inst.FieldType, |
| 2093 | 2116 | field_pl_node.payload_index, |
| 2094 | 2117 | ); |
| 2118 | const field_src = try self.srcLocInfo( |
| 2119 | file, |
| 2120 | field_pl_node.src_node, |
| 2121 | parent_src, |
| 2122 | ); |
| 2095 | 2123 | |
| 2096 | 2124 | // On first iteration use field info to find out the struct type |
| 2097 | 2125 | if (idx == extra.end) { |
| 2098 | 2126 | const wr = try self.walkRef( |
| 2099 | 2127 | file, |
| 2100 | 2128 | parent_scope, |
| 2101 | | parent_line, |
| 2129 | field_src, |
| 2102 | 2130 | field_extra.data.container_type, |
| 2103 | 2131 | false, |
| 2104 | 2132 | ); |
| ... | ... | @@ -2109,7 +2137,7 @@ fn walkInstruction( |
| 2109 | 2137 | const value = try self.walkRef( |
| 2110 | 2138 | file, |
| 2111 | 2139 | parent_scope, |
| 2112 | | parent_line, |
| 2140 | parent_src, |
| 2113 | 2141 | init_extra.data.init, |
| 2114 | 2142 | need_type, |
| 2115 | 2143 | ); |
| ... | ... | @@ -2123,10 +2151,11 @@ fn walkInstruction( |
| 2123 | 2151 | }, |
| 2124 | 2152 | .struct_init_empty => { |
| 2125 | 2153 | const un_node = data[inst_index].un_node; |
| 2154 | |
| 2126 | 2155 | var operand: DocData.WalkResult = try self.walkRef( |
| 2127 | 2156 | file, |
| 2128 | 2157 | parent_scope, |
| 2129 | | parent_line, |
| 2158 | parent_src, |
| 2130 | 2159 | un_node.operand, |
| 2131 | 2160 | false, |
| 2132 | 2161 | ); |
| ... | ... | @@ -2159,7 +2188,7 @@ fn walkInstruction( |
| 2159 | 2188 | const value = try self.walkRef( |
| 2160 | 2189 | file, |
| 2161 | 2190 | parent_scope, |
| 2162 | | parent_line, |
| 2191 | parent_src, |
| 2163 | 2192 | init_extra.data.init, |
| 2164 | 2193 | need_type, |
| 2165 | 2194 | ); |
| ... | ... | @@ -2235,7 +2264,7 @@ fn walkInstruction( |
| 2235 | 2264 | const pl_node = data[inst_index].pl_node; |
| 2236 | 2265 | const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index); |
| 2237 | 2266 | |
| 2238 | | const callee = try self.walkRef(file, parent_scope, parent_line, extra.data.callee, need_type); |
| 2267 | const callee = try self.walkRef(file, parent_scope, parent_src, extra.data.callee, need_type); |
| 2239 | 2268 | |
| 2240 | 2269 | const args_len = extra.data.flags.args_len; |
| 2241 | 2270 | var args = try self.arena.alloc(DocData.Expr, args_len); |
| ... | ... | @@ -2250,7 +2279,7 @@ fn walkInstruction( |
| 2250 | 2279 | // to show discrepancies between the types of provided |
| 2251 | 2280 | // arguments and the types declared in the function |
| 2252 | 2281 | // signature for its parameters. |
| 2253 | | const wr = try self.walkRef(file, parent_scope, parent_line, ref, false); |
| 2282 | const wr = try self.walkRef(file, parent_scope, parent_src, ref, false); |
| 2254 | 2283 | args[i] = wr.expr; |
| 2255 | 2284 | } |
| 2256 | 2285 | |
| ... | ... | @@ -2281,7 +2310,7 @@ fn walkInstruction( |
| 2281 | 2310 | const result = self.analyzeFunction( |
| 2282 | 2311 | file, |
| 2283 | 2312 | parent_scope, |
| 2284 | | parent_line, |
| 2313 | parent_src, |
| 2285 | 2314 | inst_index, |
| 2286 | 2315 | self_ast_node_index, |
| 2287 | 2316 | type_slot_index, |
| ... | ... | @@ -2297,7 +2326,7 @@ fn walkInstruction( |
| 2297 | 2326 | const result = self.analyzeFancyFunction( |
| 2298 | 2327 | file, |
| 2299 | 2328 | parent_scope, |
| 2300 | | parent_line, |
| 2329 | parent_src, |
| 2301 | 2330 | inst_index, |
| 2302 | 2331 | self_ast_node_index, |
| 2303 | 2332 | type_slot_index, |
| ... | ... | @@ -2325,7 +2354,7 @@ fn walkInstruction( |
| 2325 | 2354 | |
| 2326 | 2355 | var array_type: ?DocData.Expr = null; |
| 2327 | 2356 | for (args) |arg, idx| { |
| 2328 | | const wr = try self.walkRef(file, parent_scope, parent_line, arg, idx == 0); |
| 2357 | const wr = try self.walkRef(file, parent_scope, parent_src, arg, idx == 0); |
| 2329 | 2358 | if (idx == 0) { |
| 2330 | 2359 | array_type = wr.typeRef; |
| 2331 | 2360 | } |
| ... | ... | @@ -2357,12 +2386,15 @@ fn walkInstruction( |
| 2357 | 2386 | .opaque_decl => { |
| 2358 | 2387 | const small = @bitCast(Zir.Inst.OpaqueDecl.Small, extended.small); |
| 2359 | 2388 | var extra_index: usize = extended.operand; |
| 2389 | |
| 2360 | 2390 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 2361 | 2391 | const src_node = @bitCast(i32, file.zir.extra[extra_index]); |
| 2362 | 2392 | extra_index += 1; |
| 2363 | 2393 | break :blk src_node; |
| 2364 | 2394 | } else null; |
| 2365 | | _ = src_node; |
| 2395 | |
| 2396 | const src_info = try self.srcLocInfo(file, src_node, parent_src); |
| 2397 | _ = src_info; |
| 2366 | 2398 | |
| 2367 | 2399 | const decls_len = if (small.has_decls_len) blk: { |
| 2368 | 2400 | const decls_len = file.zir.extra[extra_index]; |
| ... | ... | @@ -2419,7 +2451,8 @@ fn walkInstruction( |
| 2419 | 2451 | extra_index += 1; |
| 2420 | 2452 | break :blk src_node; |
| 2421 | 2453 | } else null; |
| 2422 | | _ = src_node; |
| 2454 | |
| 2455 | const src_info = try self.srcLocInfo(file, src_node, parent_src); |
| 2423 | 2456 | |
| 2424 | 2457 | const tag_type: ?Ref = if (small.has_tag_type) blk: { |
| 2425 | 2458 | const tag_type = file.zir.extra[extra_index]; |
| ... | ... | @@ -2470,7 +2503,7 @@ fn walkInstruction( |
| 2470 | 2503 | extra_index = try self.walkDecls( |
| 2471 | 2504 | file, |
| 2472 | 2505 | &scope, |
| 2473 | | parent_line, |
| 2506 | src_info, |
| 2474 | 2507 | decls_first_index, |
| 2475 | 2508 | decls_len, |
| 2476 | 2509 | &decl_indexes, |
| ... | ... | @@ -2491,7 +2524,7 @@ fn walkInstruction( |
| 2491 | 2524 | try self.collectUnionFieldInfo( |
| 2492 | 2525 | file, |
| 2493 | 2526 | &scope, |
| 2494 | | parent_line, |
| 2527 | src_info, |
| 2495 | 2528 | fields_len, |
| 2496 | 2529 | &field_type_refs, |
| 2497 | 2530 | &field_name_indexes, |
| ... | ... | @@ -2541,7 +2574,8 @@ fn walkInstruction( |
| 2541 | 2574 | extra_index += 1; |
| 2542 | 2575 | break :blk src_node; |
| 2543 | 2576 | } else null; |
| 2544 | | _ = src_node; |
| 2577 | |
| 2578 | const src_info = try self.srcLocInfo(file, src_node, parent_src); |
| 2545 | 2579 | |
| 2546 | 2580 | const tag_type: ?Ref = if (small.has_tag_type) blk: { |
| 2547 | 2581 | const tag_type = file.zir.extra[extra_index]; |
| ... | ... | @@ -2592,7 +2626,7 @@ fn walkInstruction( |
| 2592 | 2626 | extra_index = try self.walkDecls( |
| 2593 | 2627 | file, |
| 2594 | 2628 | &scope, |
| 2595 | | parent_line, |
| 2629 | src_info, |
| 2596 | 2630 | decls_first_index, |
| 2597 | 2631 | decls_len, |
| 2598 | 2632 | &decl_indexes, |
| ... | ... | @@ -2687,7 +2721,8 @@ fn walkInstruction( |
| 2687 | 2721 | extra_index += 1; |
| 2688 | 2722 | break :blk src_node; |
| 2689 | 2723 | } else null; |
| 2690 | | _ = src_node; |
| 2724 | |
| 2725 | const src_info = try self.srcLocInfo(file, src_node, parent_src); |
| 2691 | 2726 | |
| 2692 | 2727 | const fields_len = if (small.has_fields_len) blk: { |
| 2693 | 2728 | const fields_len = file.zir.extra[extra_index]; |
| ... | ... | @@ -2736,7 +2771,7 @@ fn walkInstruction( |
| 2736 | 2771 | extra_index = try self.walkDecls( |
| 2737 | 2772 | file, |
| 2738 | 2773 | &scope, |
| 2739 | | parent_line, |
| 2774 | src_info, |
| 2740 | 2775 | decls_first_index, |
| 2741 | 2776 | decls_len, |
| 2742 | 2777 | &decl_indexes, |
| ... | ... | @@ -2749,7 +2784,7 @@ fn walkInstruction( |
| 2749 | 2784 | try self.collectStructFieldInfo( |
| 2750 | 2785 | file, |
| 2751 | 2786 | &scope, |
| 2752 | | parent_line, |
| 2787 | src_info, |
| 2753 | 2788 | fields_len, |
| 2754 | 2789 | &field_type_refs, |
| 2755 | 2790 | &field_name_indexes, |
| ... | ... | @@ -2793,7 +2828,7 @@ fn walkInstruction( |
| 2793 | 2828 | const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 2794 | 2829 | const bin_index = self.exprs.items.len; |
| 2795 | 2830 | try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } }); |
| 2796 | | const param = try self.walkRef(file, parent_scope, parent_line, extra.operand, false); |
| 2831 | const param = try self.walkRef(file, parent_scope, parent_src, extra.operand, false); |
| 2797 | 2832 | |
| 2798 | 2833 | const param_index = self.exprs.items.len; |
| 2799 | 2834 | try self.exprs.append(self.arena, param.expr); |
| ... | ... | @@ -2821,7 +2856,7 @@ fn walkDecls( |
| 2821 | 2856 | self: *Autodoc, |
| 2822 | 2857 | file: *File, |
| 2823 | 2858 | scope: *Scope, |
| 2824 | | parent_line: usize, |
| 2859 | parent_src: SrcLocInfo, |
| 2825 | 2860 | decls_first_index: usize, |
| 2826 | 2861 | decls_len: u32, |
| 2827 | 2862 | decl_indexes: *std.ArrayListUnmanaged(usize), |
| ... | ... | @@ -2854,7 +2889,8 @@ fn walkDecls( |
| 2854 | 2889 | |
| 2855 | 2890 | // const hash_u32s = file.zir.extra[extra_index..][0..4]; |
| 2856 | 2891 | extra_index += 4; |
| 2857 | | const line = parent_line + file.zir.extra[extra_index]; |
| 2892 | |
| 2893 | //const line = file.zir.extra[extra_index]; |
| 2858 | 2894 | extra_index += 1; |
| 2859 | 2895 | const decl_name_index = file.zir.extra[extra_index]; |
| 2860 | 2896 | extra_index += 1; |
| ... | ... | @@ -2989,12 +3025,17 @@ fn walkDecls( |
| 2989 | 3025 | else |
| 2990 | 3026 | null; |
| 2991 | 3027 | |
| 3028 | // This is known to work because decl values are always block_inlines |
| 3029 | const data = file.zir.instructions.items(.data); |
| 3030 | const value_pl_node = data[value_index].pl_node; |
| 3031 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 3032 | |
| 2992 | 3033 | // astnode |
| 2993 | 3034 | const ast_node_index = idx: { |
| 2994 | 3035 | const idx = self.ast_nodes.items.len; |
| 2995 | 3036 | try self.ast_nodes.append(self.arena, .{ |
| 2996 | | .file = self.files.getIndex(file) orelse unreachable, |
| 2997 | | .line = line, |
| 3037 | .file = self.files.getIndex(file).?, |
| 3038 | .line = decl_src.line, |
| 2998 | 3039 | .col = 0, |
| 2999 | 3040 | .docs = doc_comment, |
| 3000 | 3041 | .fields = null, // walkInstruction will fill `fields` if necessary |
| ... | ... | @@ -3005,7 +3046,7 @@ fn walkDecls( |
| 3005 | 3046 | const walk_result = if (is_test) // TODO: decide if tests should show up at all |
| 3006 | 3047 | DocData.WalkResult{ .expr = .{ .void = .{} } } |
| 3007 | 3048 | else |
| 3008 | | try self.walkInstruction(file, scope, line, value_index, true); |
| 3049 | try self.walkInstruction(file, scope, decl_src, value_index, true); |
| 3009 | 3050 | |
| 3010 | 3051 | if (is_pub) { |
| 3011 | 3052 | try decl_indexes.append(self.arena, decls_slot_index); |
| ... | ... | @@ -3401,7 +3442,7 @@ fn analyzeFancyFunction( |
| 3401 | 3442 | self: *Autodoc, |
| 3402 | 3443 | file: *File, |
| 3403 | 3444 | scope: *Scope, |
| 3404 | | parent_line: usize, |
| 3445 | parent_src: SrcLocInfo, |
| 3405 | 3446 | inst_index: usize, |
| 3406 | 3447 | self_ast_node_index: usize, |
| 3407 | 3448 | type_slot_index: usize, |
| ... | ... | @@ -3466,7 +3507,7 @@ fn analyzeFancyFunction( |
| 3466 | 3507 | |
| 3467 | 3508 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 3468 | 3509 | const break_operand = data[break_index].@"break".operand; |
| 3469 | | const param_type_ref = try self.walkRef(file, scope, parent_line, break_operand, false); |
| 3510 | const param_type_ref = try self.walkRef(file, scope, parent_src, break_operand, false); |
| 3470 | 3511 | |
| 3471 | 3512 | param_type_refs.appendAssumeCapacity(param_type_ref.expr); |
| 3472 | 3513 | }, |
| ... | ... | @@ -3475,8 +3516,8 @@ fn analyzeFancyFunction( |
| 3475 | 3516 | |
| 3476 | 3517 | self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items; |
| 3477 | 3518 | |
| 3478 | | const inst_data = data[inst_index].pl_node; |
| 3479 | | const extra = file.zir.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 3519 | const pl_node = data[inst_index].pl_node; |
| 3520 | const extra = file.zir.extraData(Zir.Inst.FuncFancy, pl_node.payload_index); |
| 3480 | 3521 | |
| 3481 | 3522 | var extra_index: usize = extra.end; |
| 3482 | 3523 | |
| ... | ... | @@ -3490,7 +3531,7 @@ fn analyzeFancyFunction( |
| 3490 | 3531 | if (extra.data.bits.has_align_ref) { |
| 3491 | 3532 | const align_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 3492 | 3533 | align_index = self.exprs.items.len; |
| 3493 | | _ = try self.walkRef(file, scope, parent_line, align_ref, false); |
| 3534 | _ = try self.walkRef(file, scope, parent_src, align_ref, false); |
| 3494 | 3535 | extra_index += 1; |
| 3495 | 3536 | } else if (extra.data.bits.has_align_body) { |
| 3496 | 3537 | const align_body_len = file.zir.extra[extra_index]; |
| ... | ... | @@ -3507,7 +3548,7 @@ fn analyzeFancyFunction( |
| 3507 | 3548 | if (extra.data.bits.has_addrspace_ref) { |
| 3508 | 3549 | const addrspace_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 3509 | 3550 | addrspace_index = self.exprs.items.len; |
| 3510 | | _ = try self.walkRef(file, scope, parent_line, addrspace_ref, false); |
| 3551 | _ = try self.walkRef(file, scope, parent_src, addrspace_ref, false); |
| 3511 | 3552 | extra_index += 1; |
| 3512 | 3553 | } else if (extra.data.bits.has_addrspace_body) { |
| 3513 | 3554 | const addrspace_body_len = file.zir.extra[extra_index]; |
| ... | ... | @@ -3524,7 +3565,7 @@ fn analyzeFancyFunction( |
| 3524 | 3565 | if (extra.data.bits.has_section_ref) { |
| 3525 | 3566 | const section_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 3526 | 3567 | section_index = self.exprs.items.len; |
| 3527 | | _ = try self.walkRef(file, scope, parent_line, section_ref, false); |
| 3568 | _ = try self.walkRef(file, scope, parent_src, section_ref, false); |
| 3528 | 3569 | extra_index += 1; |
| 3529 | 3570 | } else if (extra.data.bits.has_section_body) { |
| 3530 | 3571 | const section_body_len = file.zir.extra[extra_index]; |
| ... | ... | @@ -3541,7 +3582,7 @@ fn analyzeFancyFunction( |
| 3541 | 3582 | if (extra.data.bits.has_cc_ref) { |
| 3542 | 3583 | const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 3543 | 3584 | cc_index = self.exprs.items.len; |
| 3544 | | _ = try self.walkRef(file, scope, parent_line, cc_ref, false); |
| 3585 | _ = try self.walkRef(file, scope, parent_src, cc_ref, false); |
| 3545 | 3586 | extra_index += 1; |
| 3546 | 3587 | } else if (extra.data.bits.has_cc_body) { |
| 3547 | 3588 | const cc_body_len = file.zir.extra[extra_index]; |
| ... | ... | @@ -3560,14 +3601,14 @@ fn analyzeFancyFunction( |
| 3560 | 3601 | .none => DocData.Expr{ .void = .{} }, |
| 3561 | 3602 | else => blk: { |
| 3562 | 3603 | const ref = fn_info.ret_ty_ref; |
| 3563 | | const wr = try self.walkRef(file, scope, parent_line, ref, false); |
| 3604 | const wr = try self.walkRef(file, scope, parent_src, ref, false); |
| 3564 | 3605 | break :blk wr.expr; |
| 3565 | 3606 | }, |
| 3566 | 3607 | }, |
| 3567 | 3608 | else => blk: { |
| 3568 | 3609 | const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; |
| 3569 | 3610 | const break_operand = data[last_instr_index].@"break".operand; |
| 3570 | | const wr = try self.walkRef(file, scope, parent_line, break_operand, false); |
| 3611 | const wr = try self.walkRef(file, scope, parent_src, break_operand, false); |
| 3571 | 3612 | break :blk wr.expr; |
| 3572 | 3613 | }, |
| 3573 | 3614 | }; |
| ... | ... | @@ -3582,7 +3623,7 @@ fn analyzeFancyFunction( |
| 3582 | 3623 | break :blk try self.getGenericReturnType( |
| 3583 | 3624 | file, |
| 3584 | 3625 | scope, |
| 3585 | | parent_line, |
| 3626 | parent_src, |
| 3586 | 3627 | fn_info.body[fn_info.body.len - 1], |
| 3587 | 3628 | ); |
| 3588 | 3629 | } else { |
| ... | ... | @@ -3619,7 +3660,7 @@ fn analyzeFunction( |
| 3619 | 3660 | self: *Autodoc, |
| 3620 | 3661 | file: *File, |
| 3621 | 3662 | scope: *Scope, |
| 3622 | | parent_line: usize, |
| 3663 | parent_src: SrcLocInfo, |
| 3623 | 3664 | inst_index: usize, |
| 3624 | 3665 | self_ast_node_index: usize, |
| 3625 | 3666 | type_slot_index: usize, |
| ... | ... | @@ -3685,7 +3726,7 @@ fn analyzeFunction( |
| 3685 | 3726 | |
| 3686 | 3727 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 3687 | 3728 | const break_operand = data[break_index].@"break".operand; |
| 3688 | | const param_type_ref = try self.walkRef(file, scope, parent_line, break_operand, false); |
| 3729 | const param_type_ref = try self.walkRef(file, scope, parent_src, break_operand, false); |
| 3689 | 3730 | |
| 3690 | 3731 | param_type_refs.appendAssumeCapacity(param_type_ref.expr); |
| 3691 | 3732 | }, |
| ... | ... | @@ -3698,14 +3739,14 @@ fn analyzeFunction( |
| 3698 | 3739 | .none => DocData.Expr{ .void = .{} }, |
| 3699 | 3740 | else => blk: { |
| 3700 | 3741 | const ref = fn_info.ret_ty_ref; |
| 3701 | | const wr = try self.walkRef(file, scope, parent_line, ref, false); |
| 3742 | const wr = try self.walkRef(file, scope, parent_src, ref, false); |
| 3702 | 3743 | break :blk wr.expr; |
| 3703 | 3744 | }, |
| 3704 | 3745 | }, |
| 3705 | 3746 | else => blk: { |
| 3706 | 3747 | const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; |
| 3707 | 3748 | const break_operand = data[last_instr_index].@"break".operand; |
| 3708 | | const wr = try self.walkRef(file, scope, parent_line, break_operand, false); |
| 3749 | const wr = try self.walkRef(file, scope, parent_src, break_operand, false); |
| 3709 | 3750 | break :blk wr.expr; |
| 3710 | 3751 | }, |
| 3711 | 3752 | }; |
| ... | ... | @@ -3720,7 +3761,7 @@ fn analyzeFunction( |
| 3720 | 3761 | break :blk try self.getGenericReturnType( |
| 3721 | 3762 | file, |
| 3722 | 3763 | scope, |
| 3723 | | parent_line, |
| 3764 | parent_src, |
| 3724 | 3765 | fn_info.body[fn_info.body.len - 1], |
| 3725 | 3766 | ); |
| 3726 | 3767 | } else { |
| ... | ... | @@ -3761,11 +3802,11 @@ fn getGenericReturnType( |
| 3761 | 3802 | self: *Autodoc, |
| 3762 | 3803 | file: *File, |
| 3763 | 3804 | scope: *Scope, |
| 3764 | | parent_line: usize, // function decl line |
| 3805 | parent_src: SrcLocInfo, // function decl line |
| 3765 | 3806 | body_end: usize, |
| 3766 | 3807 | ) !DocData.Expr { |
| 3767 | 3808 | // TODO: compute the correct line offset |
| 3768 | | const wr = try self.walkInstruction(file, scope, parent_line, body_end, false); |
| 3809 | const wr = try self.walkInstruction(file, scope, parent_src, body_end, false); |
| 3769 | 3810 | return wr.expr; |
| 3770 | 3811 | } |
| 3771 | 3812 | |
| ... | ... | @@ -3773,7 +3814,7 @@ fn collectUnionFieldInfo( |
| 3773 | 3814 | self: *Autodoc, |
| 3774 | 3815 | file: *File, |
| 3775 | 3816 | scope: *Scope, |
| 3776 | | parent_line: usize, |
| 3817 | parent_src: SrcLocInfo, |
| 3777 | 3818 | fields_len: usize, |
| 3778 | 3819 | field_type_refs: *std.ArrayListUnmanaged(DocData.Expr), |
| 3779 | 3820 | field_name_indexes: *std.ArrayListUnmanaged(usize), |
| ... | ... | @@ -3820,7 +3861,7 @@ fn collectUnionFieldInfo( |
| 3820 | 3861 | |
| 3821 | 3862 | // type |
| 3822 | 3863 | { |
| 3823 | | const walk_result = try self.walkRef(file, scope, parent_line, field_type, false); |
| 3864 | const walk_result = try self.walkRef(file, scope, parent_src, field_type, false); |
| 3824 | 3865 | try field_type_refs.append(self.arena, walk_result.expr); |
| 3825 | 3866 | } |
| 3826 | 3867 | |
| ... | ... | @@ -3843,7 +3884,7 @@ fn collectStructFieldInfo( |
| 3843 | 3884 | self: *Autodoc, |
| 3844 | 3885 | file: *File, |
| 3845 | 3886 | scope: *Scope, |
| 3846 | | parent_line: usize, |
| 3887 | parent_src: SrcLocInfo, |
| 3847 | 3888 | fields_len: usize, |
| 3848 | 3889 | field_type_refs: *std.ArrayListUnmanaged(DocData.Expr), |
| 3849 | 3890 | field_name_indexes: *std.ArrayListUnmanaged(usize), |
| ... | ... | @@ -3917,7 +3958,7 @@ fn collectStructFieldInfo( |
| 3917 | 3958 | for (fields) |field| { |
| 3918 | 3959 | const type_expr = expr: { |
| 3919 | 3960 | if (field.type_ref != .none) { |
| 3920 | | const walk_result = try self.walkRef(file, scope, parent_line, field.type_ref, false); |
| 3961 | const walk_result = try self.walkRef(file, scope, parent_src, field.type_ref, false); |
| 3921 | 3962 | break :expr walk_result.expr; |
| 3922 | 3963 | } |
| 3923 | 3964 | |
| ... | ... | @@ -3927,7 +3968,7 @@ fn collectStructFieldInfo( |
| 3927 | 3968 | |
| 3928 | 3969 | const break_inst = body[body.len - 1]; |
| 3929 | 3970 | const operand = data[break_inst].@"break".operand; |
| 3930 | | const walk_result = try self.walkRef(file, scope, parent_line, operand, false); |
| 3971 | const walk_result = try self.walkRef(file, scope, parent_src, operand, false); |
| 3931 | 3972 | break :expr walk_result.expr; |
| 3932 | 3973 | }; |
| 3933 | 3974 | |
| ... | ... | @@ -3957,7 +3998,7 @@ fn walkRef( |
| 3957 | 3998 | self: *Autodoc, |
| 3958 | 3999 | file: *File, |
| 3959 | 4000 | parent_scope: *Scope, |
| 3960 | | parent_line: usize, |
| 4001 | parent_src: SrcLocInfo, |
| 3961 | 4002 | ref: Ref, |
| 3962 | 4003 | need_type: bool, // true when the caller needs also a typeRef for the return value |
| 3963 | 4004 | ) AutodocErrors!DocData.WalkResult { |
| ... | ... | @@ -4069,7 +4110,7 @@ fn walkRef( |
| 4069 | 4110 | } |
| 4070 | 4111 | } else { |
| 4071 | 4112 | const zir_index = enum_value - Ref.typed_value_map.len; |
| 4072 | | return self.walkInstruction(file, parent_scope, parent_line, zir_index, need_type); |
| 4113 | return self.walkInstruction(file, parent_scope, parent_src, zir_index, need_type); |
| 4073 | 4114 | } |
| 4074 | 4115 | } |
| 4075 | 4116 | |
| ... | ... | @@ -4122,3 +4163,28 @@ fn writePackageTableToJson( |
| 4122 | 4163 | } |
| 4123 | 4164 | try jsw.endObject(); |
| 4124 | 4165 | } |
| 4166 | |
| 4167 | fn srcLocInfo( |
| 4168 | self: Autodoc, |
| 4169 | file: *File, |
| 4170 | src_node: ?i32, |
| 4171 | parent_src: SrcLocInfo, |
| 4172 | ) !SrcLocInfo { |
| 4173 | if (src_node) |unwrapped_src_node| { |
| 4174 | const sn = parent_src.src_node + unwrapped_src_node; |
| 4175 | const tree = try file.getTree(self.module.gpa); |
| 4176 | const node_idx = @bitCast(Ast.Node.Index, sn); |
| 4177 | const tokens = tree.nodes.items(.main_token); |
| 4178 | |
| 4179 | const tok_idx = tokens[node_idx]; |
| 4180 | const start = tree.tokens.items(.start)[tok_idx]; |
| 4181 | const loc = tree.tokenLocation(parent_src.bytes, tok_idx); |
| 4182 | return .{ |
| 4183 | .line = parent_src.line + loc.line, |
| 4184 | .bytes = start, |
| 4185 | .src_node = sn, |
| 4186 | }; |
| 4187 | } else { |
| 4188 | return parent_src; |
| 4189 | } |
| 4190 | } |