| ... | ... | @@ -628,23 +628,27 @@ pub const Namespace = struct { |
| 628 | 628 | return zcu.fileByIndex(ns.file_scope); |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | pub fn fileScopeIp(ns: Namespace, ip: *InternPool) *File { |
| 632 | return ip.filePtr(ns.file_scope); |
| 633 | } |
| 634 | |
| 631 | 635 | // This renders e.g. "std.fs.Dir.OpenOptions" |
| 632 | 636 | pub fn renderFullyQualifiedName( |
| 633 | 637 | ns: Namespace, |
| 634 | | zcu: *Zcu, |
| 638 | ip: *InternPool, |
| 635 | 639 | name: InternPool.NullTerminatedString, |
| 636 | 640 | writer: anytype, |
| 637 | 641 | ) @TypeOf(writer).Error!void { |
| 638 | 642 | if (ns.parent.unwrap()) |parent| { |
| 639 | | try zcu.namespacePtr(parent).renderFullyQualifiedName( |
| 640 | | zcu, |
| 641 | | zcu.declPtr(ns.decl_index).name, |
| 643 | try ip.namespacePtr(parent).renderFullyQualifiedName( |
| 644 | ip, |
| 645 | ip.declPtr(ns.decl_index).name, |
| 642 | 646 | writer, |
| 643 | 647 | ); |
| 644 | 648 | } else { |
| 645 | | try ns.fileScope(zcu).renderFullyQualifiedName(writer); |
| 649 | try ns.fileScopeIp(ip).renderFullyQualifiedName(writer); |
| 646 | 650 | } |
| 647 | | if (name != .empty) try writer.print(".{}", .{name.fmt(&zcu.intern_pool)}); |
| 651 | if (name != .empty) try writer.print(".{}", .{name.fmt(ip)}); |
| 648 | 652 | } |
| 649 | 653 | |
| 650 | 654 | /// This renders e.g. "std/fs.zig:Dir.OpenOptions" |
| ... | ... | @@ -670,44 +674,43 @@ pub const Namespace = struct { |
| 670 | 674 | |
| 671 | 675 | pub fn internFullyQualifiedName( |
| 672 | 676 | ns: Namespace, |
| 673 | | pt: Zcu.PerThread, |
| 677 | ip: *InternPool, |
| 678 | gpa: Allocator, |
| 679 | tid: Zcu.PerThread.Id, |
| 674 | 680 | name: InternPool.NullTerminatedString, |
| 675 | 681 | ) !InternPool.NullTerminatedString { |
| 676 | | const zcu = pt.zcu; |
| 677 | | const ip = &zcu.intern_pool; |
| 678 | | |
| 679 | | const gpa = zcu.gpa; |
| 680 | | const strings = ip.getLocal(pt.tid).getMutableStrings(gpa); |
| 682 | const strings = ip.getLocal(tid).getMutableStrings(gpa); |
| 681 | 683 | // Protects reads of interned strings from being reallocated during the call to |
| 682 | 684 | // renderFullyQualifiedName. |
| 683 | 685 | const slice = try strings.addManyAsSlice(count: { |
| 684 | 686 | var count: usize = name.length(ip) + 1; |
| 685 | 687 | var cur_ns = &ns; |
| 686 | 688 | while (true) { |
| 687 | | const decl = zcu.declPtr(cur_ns.decl_index); |
| 688 | | cur_ns = zcu.namespacePtr(cur_ns.parent.unwrap() orelse { |
| 689 | | count += ns.fileScope(zcu).fullyQualifiedNameLen(); |
| 689 | const decl = ip.declPtr(cur_ns.decl_index); |
| 690 | cur_ns = ip.namespacePtr(cur_ns.parent.unwrap() orelse { |
| 691 | count += ns.fileScopeIp(ip).fullyQualifiedNameLen(); |
| 690 | 692 | break :count count; |
| 691 | 693 | }); |
| 692 | 694 | count += decl.name.length(ip) + 1; |
| 693 | 695 | } |
| 694 | 696 | }); |
| 695 | 697 | var fbs = std.io.fixedBufferStream(slice[0]); |
| 696 | | ns.renderFullyQualifiedName(zcu, name, fbs.writer()) catch unreachable; |
| 698 | ns.renderFullyQualifiedName(ip, name, fbs.writer()) catch unreachable; |
| 697 | 699 | assert(fbs.pos == slice[0].len); |
| 698 | 700 | |
| 699 | 701 | // Sanitize the name for nvptx which is more restrictive. |
| 700 | 702 | // TODO This should be handled by the backend, not the frontend. Have a |
| 701 | 703 | // look at how the C backend does it for inspiration. |
| 702 | | const cpu_arch = zcu.root_mod.resolved_target.result.cpu.arch; |
| 703 | | if (cpu_arch.isNvptx()) { |
| 704 | | for (slice[0]) |*byte| switch (byte.*) { |
| 705 | | '{', '}', '*', '[', ']', '(', ')', ',', ' ', '\'' => byte.* = '_', |
| 706 | | else => {}, |
| 707 | | }; |
| 708 | | } |
| 709 | | |
| 710 | | return ip.getOrPutTrailingString(gpa, pt.tid, @intCast(slice[0].len), .no_embedded_nulls); |
| 704 | // FIXME This has bitrotted and is no longer able to be implemented here. |
| 705 | //const cpu_arch = zcu.root_mod.resolved_target.result.cpu.arch; |
| 706 | //if (cpu_arch.isNvptx()) { |
| 707 | // for (slice[0]) |*byte| switch (byte.*) { |
| 708 | // '{', '}', '*', '[', ']', '(', ')', ',', ' ', '\'' => byte.* = '_', |
| 709 | // else => {}, |
| 710 | // }; |
| 711 | //} |
| 712 | |
| 713 | return ip.getOrPutTrailingString(gpa, tid, @intCast(slice[0].len), .no_embedded_nulls); |
| 711 | 714 | } |
| 712 | 715 | |
| 713 | 716 | pub fn getType(ns: Namespace, zcu: *Zcu) Type { |