| ... | ... | @@ -625,6 +625,14 @@ pub const Decl = struct { |
| 625 | 625 | return try decl.namespace.renderFullyQualifiedName(unqualified_name, writer); |
| 626 | 626 | } |
| 627 | 627 | |
| 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 | 636 | pub fn getFullyQualifiedName(decl: *const Decl, gpa: *Allocator) ![:0]u8 { |
| 629 | 637 | var buffer = std.ArrayList(u8).init(gpa); |
| 630 | 638 | defer buffer.deinit(); |
| ... | ... | @@ -1246,6 +1254,26 @@ pub const Scope = struct { |
| 1246 | 1254 | } |
| 1247 | 1255 | } |
| 1248 | 1256 | |
| 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 | 1277 | pub fn getDecl(ns: Namespace) *Decl { |
| 1250 | 1278 | return ns.ty.getOwnerDecl(); |
| 1251 | 1279 | } |
| ... | ... | @@ -1400,6 +1428,13 @@ pub const Scope = struct { |
| 1400 | 1428 | }; |
| 1401 | 1429 | } |
| 1402 | 1430 | |
| 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 | 1438 | pub fn fullyQualifiedNameZ(file: File, gpa: *Allocator) ![:0]u8 { |
| 1404 | 1439 | var buf = std.ArrayList(u8).init(gpa); |
| 1405 | 1440 | defer buf.deinit(); |