authorgravatar for jcmoyer32@gmail.comJ.C. Moyer <jcmoyer32@gmail.com> 2021-06-28 17:31:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-02 14:08:52-04:00
logd84b386f6034278c8a9e8c3d2b0975ac541584aa
tree279ab79fca1601c226a509b3a3a6bbdf0fbf477c
parent7140bb64e1aa77f6b6de5c7e4f78d880346c0747

stage2: print valid filename in error messages


3 files changed, 23 insertions(+), 6 deletions(-)

src/Compilation.zig+6-6
......@@ -402,10 +402,10 @@ pub const AllErrors = struct {
402402 const source = try module_note.src_loc.file_scope.getSource(module.gpa);
403403 const byte_offset = try module_note.src_loc.byteOffset(module.gpa);
404404 const loc = std.zig.findLineColumn(source, byte_offset);
405 const sub_file_path = module_note.src_loc.file_scope.sub_file_path;
405 const file_path = try module_note.src_loc.file_scope.fullPath(&arena.allocator);
406406 note.* = .{
407407 .src = .{
408 .src_path = try arena.allocator.dupe(u8, sub_file_path),
408 .src_path = file_path,
409409 .msg = try arena.allocator.dupe(u8, module_note.msg),
410410 .byte_offset = byte_offset,
411411 .line = @intCast(u32, loc.line),
......@@ -425,10 +425,10 @@ pub const AllErrors = struct {
425425 const source = try module_err_msg.src_loc.file_scope.getSource(module.gpa);
426426 const byte_offset = try module_err_msg.src_loc.byteOffset(module.gpa);
427427 const loc = std.zig.findLineColumn(source, byte_offset);
428 const sub_file_path = module_err_msg.src_loc.file_scope.sub_file_path;
428 const file_path = try module_err_msg.src_loc.file_scope.fullPath(&arena.allocator);
429429 try errors.append(.{
430430 .src = .{
431 .src_path = try arena.allocator.dupe(u8, sub_file_path),
431 .src_path = file_path,
432432 .msg = try arena.allocator.dupe(u8, module_err_msg.msg),
433433 .byte_offset = byte_offset,
434434 .line = @intCast(u32, loc.line),
......@@ -479,7 +479,7 @@ pub const AllErrors = struct {
479479
480480 note.* = .{
481481 .src = .{
482 .src_path = try arena.dupe(u8, file.sub_file_path),
482 .src_path = try file.fullPath(arena),
483483 .msg = try arena.dupe(u8, msg),
484484 .byte_offset = byte_offset,
485485 .line = @intCast(u32, loc.line),
......@@ -505,7 +505,7 @@ pub const AllErrors = struct {
505505
506506 try errors.append(.{
507507 .src = .{
508 .src_path = try arena.dupe(u8, file.sub_file_path),
508 .src_path = try file.fullPath(arena),
509509 .msg = try arena.dupe(u8, msg),
510510 .byte_offset = byte_offset,
511511 .line = @intCast(u32, loc.line),
src/Module.zig+5
......@@ -1111,6 +1111,11 @@ pub const Scope = struct {
11111111 return buf.toOwnedSliceSentinel(0);
11121112 }
11131113
1114 /// Returns the full path to this file relative to its package.
1115 pub fn fullPath(file: File, ally: *Allocator) ![]u8 {
1116 return file.pkg.root_src_directory.join(ally, &[_][]const u8{file.sub_file_path});
1117 }
1118
11141119 pub fn dumpSrc(file: *File, src: LazySrcLoc) void {
11151120 const loc = std.zig.findLineColumn(file.source.bytes, src);
11161121 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });
src/main.zig+12
......@@ -3117,6 +3117,9 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {
31173117 .root_decl = null,
31183118 };
31193119
3120 file.pkg = try Package.create(gpa, null, file.sub_file_path);
3121 defer file.pkg.destroy(gpa);
3122
31203123 file.zir = try AstGen.generate(gpa, file.tree);
31213124 file.zir_loaded = true;
31223125 defer file.zir.deinit(gpa);
......@@ -3309,6 +3312,9 @@ fn fmtPathFile(
33093312 .root_decl = null,
33103313 };
33113314
3315 file.pkg = try Package.create(fmt.gpa, null, file.sub_file_path);
3316 defer file.pkg.destroy(fmt.gpa);
3317
33123318 if (stat.size > max_src_size)
33133319 return error.FileTooBig;
33143320
......@@ -3901,6 +3907,9 @@ pub fn cmdAstCheck(
39013907 file.stat_size = source.len;
39023908 }
39033909
3910 file.pkg = try Package.create(gpa, null, file.sub_file_path);
3911 defer file.pkg.destroy(gpa);
3912
39043913 file.tree = try std.zig.parse(gpa, file.source);
39053914 file.tree_loaded = true;
39063915 defer file.tree.deinit(gpa);
......@@ -4017,6 +4026,9 @@ pub fn cmdChangelist(
40174026 .root_decl = null,
40184027 };
40194028
4029 file.pkg = try Package.create(gpa, null, file.sub_file_path);
4030 defer file.pkg.destroy(gpa);
4031
40204032 const source = try arena.allocSentinel(u8, @intCast(usize, stat.size), 0);
40214033 const amt = try f.readAll(source);
40224034 if (amt != stat.size)