authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2023-08-11 23:02:20+03:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-08-14 15:44:21+02:00
log197d9a9eb3557b1feae7580a82ab60defc9e12a1
treea8a428006067d3965af2658c04f93cfb92d0f6ed
parenta1049d4561b9c34dc8787dd09e4de25afee5965b

Autodoc: remove assumption that slice's lhs is always a declRef


1 files changed, 30 insertions(+), 5 deletions(-)

src/Autodoc.zig+30-5
...@@ -1266,8 +1266,13 @@ fn walkInstruction(...@@ -1266,8 +1266,13 @@ fn walkInstruction(
1266 try self.exprs.append(self.arena, start.expr);1266 try self.exprs.append(self.arena, start.expr);
1267 self.exprs.items[slice_index] = .{ .slice = .{ .lhs = lhs_index, .start = start_index } };1267 self.exprs.items[slice_index] = .{ .slice = .{ .lhs = lhs_index, .start = start_index } };
12681268
1269 const typeRef = switch (lhs.expr) {
1270 .declRef => |ref| self.decls.items[ref.Analyzed].value.typeRef,
1271 else => null,
1272 };
1273
1269 return DocData.WalkResult{1274 return DocData.WalkResult{
1270 .typeRef = self.decls.items[lhs.expr.declRef.Analyzed].value.typeRef,1275 .typeRef = typeRef,
1271 .expr = .{ .sliceIndex = slice_index },1276 .expr = .{ .sliceIndex = slice_index },
1272 };1277 };
1273 },1278 },
...@@ -1311,8 +1316,13 @@ fn walkInstruction(...@@ -1311,8 +1316,13 @@ fn walkInstruction(
1311 try self.exprs.append(self.arena, end.expr);1316 try self.exprs.append(self.arena, end.expr);
1312 self.exprs.items[slice_index] = .{ .slice = .{ .lhs = lhs_index, .start = start_index, .end = end_index } };1317 self.exprs.items[slice_index] = .{ .slice = .{ .lhs = lhs_index, .start = start_index, .end = end_index } };
13131318
1319 const typeRef = switch (lhs.expr) {
1320 .declRef => |ref| self.decls.items[ref.Analyzed].value.typeRef,
1321 else => null,
1322 };
1323
1314 return DocData.WalkResult{1324 return DocData.WalkResult{
1315 .typeRef = self.decls.items[lhs.expr.declRef.Analyzed].value.typeRef,1325 .typeRef = typeRef,
1316 .expr = .{ .sliceIndex = slice_index },1326 .expr = .{ .sliceIndex = slice_index },
1317 };1327 };
1318 },1328 },
...@@ -1364,10 +1374,20 @@ fn walkInstruction(...@@ -1364,10 +1374,20 @@ fn walkInstruction(
1364 try self.exprs.append(self.arena, end.expr);1374 try self.exprs.append(self.arena, end.expr);
1365 const sentinel_index = self.exprs.items.len;1375 const sentinel_index = self.exprs.items.len;
1366 try self.exprs.append(self.arena, sentinel.expr);1376 try self.exprs.append(self.arena, sentinel.expr);
1367 self.exprs.items[slice_index] = .{ .slice = .{ .lhs = lhs_index, .start = start_index, .end = end_index, .sentinel = sentinel_index } };1377 self.exprs.items[slice_index] = .{ .slice = .{
1378 .lhs = lhs_index,
1379 .start = start_index,
1380 .end = end_index,
1381 .sentinel = sentinel_index,
1382 } };
1383
1384 const typeRef = switch (lhs.expr) {
1385 .declRef => |ref| self.decls.items[ref.Analyzed].value.typeRef,
1386 else => null,
1387 };
13681388
1369 return DocData.WalkResult{1389 return DocData.WalkResult{
1370 .typeRef = self.decls.items[lhs.expr.declRef.Analyzed].value.typeRef,1390 .typeRef = typeRef,
1371 .expr = .{ .sliceIndex = slice_index },1391 .expr = .{ .sliceIndex = slice_index },
1372 };1392 };
1373 },1393 },
...@@ -1432,8 +1452,13 @@ fn walkInstruction(...@@ -1432,8 +1452,13 @@ fn walkInstruction(
1432 .sentinel = sentinel_index,1452 .sentinel = sentinel_index,
1433 } };1453 } };
14341454
1455 const typeRef = switch (lhs.expr) {
1456 .declRef => |ref| self.decls.items[ref.Analyzed].value.typeRef,
1457 else => null,
1458 };
1459
1435 return DocData.WalkResult{1460 return DocData.WalkResult{
1436 .typeRef = self.decls.items[lhs.expr.declRef.Analyzed].value.typeRef,1461 .typeRef = typeRef,
1437 .expr = .{ .sliceIndex = slice_index },1462 .expr = .{ .sliceIndex = slice_index },
1438 };1463 };
1439 },1464 },