authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-11 14:10:25+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-11 14:16:42+03:00
log2a41b1449b724aa10290b9ec735c89405b627960
tree1ada42bf0d8075544dfacb262da846e4b09b0215
parent0370006c1f5a23e5e2d0993fb71f825791d64957

Compilation: do not repeat AstGen error source line for notes


1 files changed, 15 insertions(+), 16 deletions(-)

src/Compilation.zig+15-16
......@@ -572,6 +572,16 @@ pub const AllErrors = struct {
572572 while (item_i < items_len) : (item_i += 1) {
573573 const item = file.zir.extraData(Zir.Inst.CompileErrors.Item, extra_index);
574574 extra_index = item.end;
575 const err_byte_offset = blk: {
576 const token_starts = file.tree.tokens.items(.start);
577 if (item.data.node != 0) {
578 const main_tokens = file.tree.nodes.items(.main_token);
579 const main_token = main_tokens[item.data.node];
580 break :blk token_starts[main_token];
581 }
582 break :blk token_starts[item.data.token] + item.data.byte_offset;
583 };
584 const err_loc = std.zig.findLineColumn(file.source, err_byte_offset);
575585
576586 var notes: []Message = &[0]Message{};
577587 if (item.data.notes != 0) {
......@@ -600,33 +610,22 @@ pub const AllErrors = struct {
600610 .line = @intCast(u32, loc.line),
601611 .column = @intCast(u32, loc.column),
602612 .notes = &.{}, // TODO rework this function to be recursive
603 .source_line = try arena.dupe(u8, loc.source_line),
613 .source_line = if (loc.eql(err_loc)) null else try arena.dupe(u8, loc.source_line),
604614 },
605615 };
606616 }
607617 }
608618
609619 const msg = file.zir.nullTerminatedString(item.data.msg);
610 const byte_offset = blk: {
611 const token_starts = file.tree.tokens.items(.start);
612 if (item.data.node != 0) {
613 const main_tokens = file.tree.nodes.items(.main_token);
614 const main_token = main_tokens[item.data.node];
615 break :blk token_starts[main_token];
616 }
617 break :blk token_starts[item.data.token] + item.data.byte_offset;
618 };
619 const loc = std.zig.findLineColumn(file.source, byte_offset);
620
621620 try errors.append(.{
622621 .src = .{
623622 .src_path = try file.fullPath(arena),
624623 .msg = try arena.dupe(u8, msg),
625 .byte_offset = byte_offset,
626 .line = @intCast(u32, loc.line),
627 .column = @intCast(u32, loc.column),
624 .byte_offset = err_byte_offset,
625 .line = @intCast(u32, err_loc.line),
626 .column = @intCast(u32, err_loc.column),
628627 .notes = notes,
629 .source_line = try arena.dupe(u8, loc.source_line),
628 .source_line = try arena.dupe(u8, err_loc.source_line),
630629 },
631630 });
632631 }