diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-02-26 22:11:41 -0500 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2023-02-27 05:37:03 -0500 |
| commit | a3529c2dea579e0a15dcde1b8ee71d9ec9c75330 (patch) | |
| tree | a06d6819520fbecc5c5c8d64de7739ac528ab280 /src/type.zig | |
| parent | 9e519727014fcc484714d8230a0a8bce8744998d (diff) | |
| download | zig-a3529c2dea579e0a15dcde1b8ee71d9ec9c75330.tar.gz zig-a3529c2dea579e0a15dcde1b8ee71d9ec9c75330.zip | |
tools: implement more lldb pretty printers
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig index ec4db8689f..15525f14eb 100644 --- a/src/type.zig +++ b/src/type.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const Value = @import("value.zig").Value; const assert = std.debug.assert; const Allocator = std.mem.Allocator; @@ -6694,4 +6695,33 @@ pub const Type = extern union { /// This is only used for comptime asserts. Bump this number when you make a change /// to packed struct layout to find out all the places in the codebase you need to edit! pub const packed_struct_layout_version = 2; + + /// This function is used in the debugger pretty formatters in tools/ to fetch the + /// Tag to Payload mapping to facilitate fancy debug printing for this type. + fn dbHelper(self: *Type, tag_to_payload_map: *map: { + const tags = @typeInfo(Tag).Enum.fields; + var fields: [tags.len]std.builtin.Type.StructField = undefined; + for (&fields, tags) |*field, t| field.* = .{ + .name = t.name, + .type = *if (t.value < Tag.no_payload_count) void else @field(Tag, t.name).Type(), + .default_value = null, + .is_comptime = false, + .alignment = 0, + }; + break :map @Type(.{ .Struct = .{ + .layout = .Extern, + .fields = &fields, + .decls = &.{}, + .is_tuple = false, + } }); + }) void { + _ = self; + _ = tag_to_payload_map; + } + + comptime { + if (builtin.mode == .Debug) { + _ = dbHelper; + } + } }; |
