authorgravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-09-30 21:43:30-05:00
committergravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-10-02 15:21:48-05:00
log0b8ddb4478ebf14811caf8a083ca493f9ed733b2
tree5e80c6730a113eebb2bf245b3ad819d415e6fa06
parent993dc2ae77514e61235f0920755fdb1ccc77c2f7

Improve debug names of decls


2 files changed, 36 insertions(+), 1 deletions(-)

src/Module.zig+35
...@@ -625,6 +625,14 @@ pub const Decl = struct {...@@ -625,6 +625,14 @@ pub const Decl = struct {
625 return try decl.namespace.renderFullyQualifiedName(unqualified_name, writer);625 return try decl.namespace.renderFullyQualifiedName(unqualified_name, writer);
626 }626 }
627627
628 pub fn renderFullyQualifiedDebugName(decl: *const Decl, writer: anytype) @TypeOf(writer).Error!void {
629 // Namespace decls (struct/enum/union/opaque) use their own namespace,
630 // which means the decl name and the namespace name are the same.
631 // In that case we want to omit the decl name, unless this is the root decl.
632 const unqualified_name = if (decl.namespace.getDecl() != decl or decl.namespace.parent == null) mem.spanZ(decl.name) else "";
633 return try decl.namespace.renderFullyQualifiedDebugName(unqualified_name, writer);
634 }
635
628 pub fn getFullyQualifiedName(decl: *const Decl, gpa: *Allocator) ![:0]u8 {636 pub fn getFullyQualifiedName(decl: *const Decl, gpa: *Allocator) ![:0]u8 {
629 var buffer = std.ArrayList(u8).init(gpa);637 var buffer = std.ArrayList(u8).init(gpa);
630 defer buffer.deinit();638 defer buffer.deinit();
...@@ -1246,6 +1254,26 @@ pub const Scope = struct {...@@ -1246,6 +1254,26 @@ pub const Scope = struct {
1246 }1254 }
1247 }1255 }
12481256
1257 // This renders e.g. "std.fs:Dir.OpenOptions"
1258 pub fn renderFullyQualifiedDebugName(
1259 ns: Namespace,
1260 name: []const u8,
1261 writer: anytype,
1262 ) @TypeOf(writer).Error!void {
1263 var separator_char: u8 = '.';
1264 if (ns.parent) |parent| {
1265 const decl = ns.getDecl();
1266 try parent.renderFullyQualifiedDebugName(mem.spanZ(decl.name), writer);
1267 } else {
1268 try ns.file_scope.renderFullyQualifiedDebugName(writer);
1269 separator_char = ':';
1270 }
1271 if (name.len != 0) {
1272 try writer.writeByte(separator_char);
1273 try writer.writeAll(name);
1274 }
1275 }
1276
1249 pub fn getDecl(ns: Namespace) *Decl {1277 pub fn getDecl(ns: Namespace) *Decl {
1250 return ns.ty.getOwnerDecl();1278 return ns.ty.getOwnerDecl();
1251 }1279 }
...@@ -1400,6 +1428,13 @@ pub const Scope = struct {...@@ -1400,6 +1428,13 @@ pub const Scope = struct {
1400 };1428 };
1401 }1429 }
14021430
1431 pub fn renderFullyQualifiedDebugName(file: File, writer: anytype) !void {
1432 for (file.sub_file_path) |byte| switch (byte) {
1433 '/', '\\' => try writer.writeByte('/'),
1434 else => try writer.writeByte(byte),
1435 };
1436 }
1437
1403 pub fn fullyQualifiedNameZ(file: File, gpa: *Allocator) ![:0]u8 {1438 pub fn fullyQualifiedNameZ(file: File, gpa: *Allocator) ![:0]u8 {
1404 var buf = std.ArrayList(u8).init(gpa);1439 var buf = std.ArrayList(u8).init(gpa);
1405 defer buf.deinit();1440 defer buf.deinit();
src/crash_report.zig+1-1
...@@ -150,7 +150,7 @@ fn writeFilePath(file: *Scope.File, stream: anytype) !void {...@@ -150,7 +150,7 @@ fn writeFilePath(file: *Scope.File, stream: anytype) !void {
150fn writeFullyQualifiedDeclWithFile(decl: *Decl, stream: anytype) !void {150fn writeFullyQualifiedDeclWithFile(decl: *Decl, stream: anytype) !void {
151 try writeFilePath(decl.getFileScope(), stream);151 try writeFilePath(decl.getFileScope(), stream);
152 try stream.writeAll(": ");152 try stream.writeAll(": ");
153 try decl.namespace.renderFullyQualifiedName(std.mem.sliceTo(decl.name, 0), stream);153 try decl.renderFullyQualifiedDebugName(stream);
154}154}
155155
156fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {156fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {