| ... | ... | @@ -441,8 +441,37 @@ pub const AllErrors = struct { |
| 441 | 441 | const item = file.zir.extraData(Zir.Inst.CompileErrors.Item, extra_index); |
| 442 | 442 | extra_index = item.end; |
| 443 | 443 | |
| 444 | var notes: []Message = &[0]Message{}; |
| 444 | 445 | if (item.data.notes != 0) { |
| 445 | | @panic("TODO implement AllErrors for Zir notes"); |
| 446 | const block = file.zir.extraData(Zir.Inst.Block, item.data.notes); |
| 447 | const body = file.zir.extra[block.end..][0..block.data.body_len]; |
| 448 | notes = try arena.alloc(Message, body.len); |
| 449 | for (notes) |*note, i| { |
| 450 | const note_item = file.zir.extraData(Zir.Inst.CompileErrors.Item, body[i]); |
| 451 | const msg = file.zir.nullTerminatedString(note_item.data.msg); |
| 452 | const byte_offset = blk: { |
| 453 | const token_starts = file.tree.tokens.items(.start); |
| 454 | if (note_item.data.node != 0) { |
| 455 | const main_tokens = file.tree.nodes.items(.main_token); |
| 456 | const main_token = main_tokens[note_item.data.node]; |
| 457 | break :blk token_starts[main_token]; |
| 458 | } |
| 459 | break :blk token_starts[note_item.data.token] + note_item.data.byte_offset; |
| 460 | }; |
| 461 | const loc = std.zig.findLineColumn(source, byte_offset); |
| 462 | |
| 463 | note.* = .{ |
| 464 | .src = .{ |
| 465 | .src_path = try arena.dupe(u8, file.sub_file_path), |
| 466 | .msg = try arena.dupe(u8, msg), |
| 467 | .byte_offset = byte_offset, |
| 468 | .line = @intCast(u32, loc.line), |
| 469 | .column = @intCast(u32, loc.column), |
| 470 | .notes = &.{}, // TODO rework this function to be recursive |
| 471 | .source_line = try arena.dupe(u8, loc.source_line), |
| 472 | }, |
| 473 | }; |
| 474 | } |
| 446 | 475 | } |
| 447 | 476 | |
| 448 | 477 | const msg = file.zir.nullTerminatedString(item.data.msg); |
| ... | ... | @@ -464,7 +493,7 @@ pub const AllErrors = struct { |
| 464 | 493 | .byte_offset = byte_offset, |
| 465 | 494 | .line = @intCast(u32, loc.line), |
| 466 | 495 | .column = @intCast(u32, loc.column), |
| 467 | | .notes = &.{}, // TODO |
| 496 | .notes = notes, |
| 468 | 497 | .source_line = try arena.dupe(u8, loc.source_line), |
| 469 | 498 | }, |
| 470 | 499 | }); |