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 {...@@ -572,6 +572,16 @@ pub const AllErrors = struct {
572 while (item_i < items_len) : (item_i += 1) {572 while (item_i < items_len) : (item_i += 1) {
573 const item = file.zir.extraData(Zir.Inst.CompileErrors.Item, extra_index);573 const item = file.zir.extraData(Zir.Inst.CompileErrors.Item, extra_index);
574 extra_index = item.end;574 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
576 var notes: []Message = &[0]Message{};586 var notes: []Message = &[0]Message{};
577 if (item.data.notes != 0) {587 if (item.data.notes != 0) {
...@@ -600,33 +610,22 @@ pub const AllErrors = struct {...@@ -600,33 +610,22 @@ pub const AllErrors = struct {
600 .line = @intCast(u32, loc.line),610 .line = @intCast(u32, loc.line),
601 .column = @intCast(u32, loc.column),611 .column = @intCast(u32, loc.column),
602 .notes = &.{}, // TODO rework this function to be recursive612 .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),
604 },614 },
605 };615 };
606 }616 }
607 }617 }
608618
609 const msg = file.zir.nullTerminatedString(item.data.msg);619 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
621 try errors.append(.{620 try errors.append(.{
622 .src = .{621 .src = .{
623 .src_path = try file.fullPath(arena),622 .src_path = try file.fullPath(arena),
624 .msg = try arena.dupe(u8, msg),623 .msg = try arena.dupe(u8, msg),
625 .byte_offset = byte_offset,624 .byte_offset = err_byte_offset,
626 .line = @intCast(u32, loc.line),625 .line = @intCast(u32, err_loc.line),
627 .column = @intCast(u32, loc.column),626 .column = @intCast(u32, err_loc.column),
628 .notes = notes,627 .notes = notes,
629 .source_line = try arena.dupe(u8, loc.source_line),628 .source_line = try arena.dupe(u8, err_loc.source_line),
630 },629 },
631 });630 });
632 }631 }