authorgravatar for jcmoyer32@gmail.comJ.C. Moyer <jcmoyer32@gmail.com> 2021-06-24 01:41:54-04:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-27 14:53:46+03:00
log15a030ef3d2d68992835568f2fb9d5deab18f39f
treed41539edd628a4caef049806bd49211e0bf4a6a0
parentf398ac3ee48b35754f51f0bfaff76b6a1e70da77

Include package root dir in stage2 error messages


2 files changed, 10 insertions(+), 6 deletions(-)

src/Compilation.zig+6-6
...@@ -403,10 +403,10 @@ pub const AllErrors = struct {...@@ -403,10 +403,10 @@ pub const AllErrors = struct {
403 const source = try module_note.src_loc.file_scope.getSource(module.gpa);403 const source = try module_note.src_loc.file_scope.getSource(module.gpa);
404 const byte_offset = try module_note.src_loc.byteOffset(module.gpa);404 const byte_offset = try module_note.src_loc.byteOffset(module.gpa);
405 const loc = std.zig.findLineColumn(source, byte_offset);405 const loc = std.zig.findLineColumn(source, byte_offset);
406 const sub_file_path = module_note.src_loc.file_scope.sub_file_path;406 const file_path = try module_note.src_loc.file_scope.fullPath(&arena.allocator);
407 note.* = .{407 note.* = .{
408 .src = .{408 .src = .{
409 .src_path = try arena.allocator.dupe(u8, sub_file_path),409 .src_path = file_path,
410 .msg = try arena.allocator.dupe(u8, module_note.msg),410 .msg = try arena.allocator.dupe(u8, module_note.msg),
411 .byte_offset = byte_offset,411 .byte_offset = byte_offset,
412 .line = @intCast(u32, loc.line),412 .line = @intCast(u32, loc.line),
...@@ -426,10 +426,10 @@ pub const AllErrors = struct {...@@ -426,10 +426,10 @@ pub const AllErrors = struct {
426 const source = try module_err_msg.src_loc.file_scope.getSource(module.gpa);426 const source = try module_err_msg.src_loc.file_scope.getSource(module.gpa);
427 const byte_offset = try module_err_msg.src_loc.byteOffset(module.gpa);427 const byte_offset = try module_err_msg.src_loc.byteOffset(module.gpa);
428 const loc = std.zig.findLineColumn(source, byte_offset);428 const loc = std.zig.findLineColumn(source, byte_offset);
429 const sub_file_path = module_err_msg.src_loc.file_scope.sub_file_path;429 const file_path = try module_err_msg.src_loc.file_scope.fullPath(&arena.allocator);
430 try errors.append(.{430 try errors.append(.{
431 .src = .{431 .src = .{
432 .src_path = try arena.allocator.dupe(u8, sub_file_path),432 .src_path = file_path,
433 .msg = try arena.allocator.dupe(u8, module_err_msg.msg),433 .msg = try arena.allocator.dupe(u8, module_err_msg.msg),
434 .byte_offset = byte_offset,434 .byte_offset = byte_offset,
435 .line = @intCast(u32, loc.line),435 .line = @intCast(u32, loc.line),
...@@ -480,7 +480,7 @@ pub const AllErrors = struct {...@@ -480,7 +480,7 @@ pub const AllErrors = struct {
480480
481 note.* = .{481 note.* = .{
482 .src = .{482 .src = .{
483 .src_path = try arena.dupe(u8, file.sub_file_path),483 .src_path = try file.fullPath(arena),
484 .msg = try arena.dupe(u8, msg),484 .msg = try arena.dupe(u8, msg),
485 .byte_offset = byte_offset,485 .byte_offset = byte_offset,
486 .line = @intCast(u32, loc.line),486 .line = @intCast(u32, loc.line),
...@@ -506,7 +506,7 @@ pub const AllErrors = struct {...@@ -506,7 +506,7 @@ pub const AllErrors = struct {
506506
507 try errors.append(.{507 try errors.append(.{
508 .src = .{508 .src = .{
509 .src_path = try arena.dupe(u8, file.sub_file_path),509 .src_path = try file.fullPath(arena),
510 .msg = try arena.dupe(u8, msg),510 .msg = try arena.dupe(u8, msg),
511 .byte_offset = byte_offset,511 .byte_offset = byte_offset,
512 .line = @intCast(u32, loc.line),512 .line = @intCast(u32, loc.line),
src/Module.zig+4
...@@ -1111,6 +1111,10 @@ pub const Scope = struct {...@@ -1111,6 +1111,10 @@ pub const Scope = struct {
1111 return buf.toOwnedSliceSentinel(0);1111 return buf.toOwnedSliceSentinel(0);
1112 }1112 }
11131113
1114 pub fn fullPath(file: File, ally: *Allocator) ![]u8 {
1115 return file.pkg.root_src_directory.join(ally, &[_][]const u8{file.sub_file_path});
1116 }
1117
1114 pub fn dumpSrc(file: *File, src: LazySrcLoc) void {1118 pub fn dumpSrc(file: *File, src: LazySrcLoc) void {
1115 const loc = std.zig.findLineColumn(file.source.bytes, src);1119 const loc = std.zig.findLineColumn(file.source.bytes, src);
1116 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });1120 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });