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