diff options
Diffstat (limited to 'src/walk.zig')
| -rw-r--r-- | src/walk.zig | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/walk.zig b/src/walk.zig index 3641d327..ffa97af2 100644 --- a/src/walk.zig +++ b/src/walk.zig @@ -1135,6 +1135,13 @@ pub fn Load(comptime roots: []const type) type { l.notes.print(l.own, fmt ++ "\n", args) catch {}; } + /// A note on a type's field, its names given as run-time strings: + /// one instance of `note` (and of std's `print`) a message, where + /// a tuple of the comptime names made one a type, field and message. + fn noteField(l: *Self, comptime what: []const u8, type_name: []const u8, field: []const u8) void { + l.note("{s}.{s}: " ++ what, .{ type_name, field }); + } + fn root(l: *Self) DecodeError!u32 { const ty = try l.scalar(u32); if (ty >= l.src.len) return error.BadDump; @@ -1441,9 +1448,9 @@ pub fn Load(comptime roots: []const type) type { const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?]; if (comptime attr.default_value_ptr) |dp| { @field(out, field) = @as(*const @FieldType(T, field), @ptrCast(@alignCast(dp))).*; - l.note("{s}.{s}: its kind changed; its default taken", .{ @typeName(T), field }); + l.noteField("its kind changed; its default taken", @typeName(T), field); } else if (existing) { - l.note("{s}.{s}: its kind changed; left as it was", .{ @typeName(T), field }); + l.noteField("its kind changed; left as it was", @typeName(T), field); } else failed = true; }; }; @@ -1454,7 +1461,7 @@ pub fn Load(comptime roots: []const type) type { const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?]; if (comptime attr.default_value_ptr == null) { if (!existing) { - l.note("{s}.{s}: not in the dump", .{ @typeName(T), field }); + l.noteField("not in the dump", @typeName(T), field); failed = true; } } @@ -1854,6 +1861,11 @@ pub const Get = struct { l.notes.print(l.own, fmt ++ "\n", args) catch {}; } + /// A note on a type's field, its names given at run time (Load's). + fn noteField(l: *Get, comptime what: []const u8, type_name: []const u8, field: []const u8) void { + l.note("{s}.{s}: " ++ what, .{ type_name, field }); + } + /// The value at `c`, made: what it points at is `gpa`'s. pub fn get(l: *Get, comptime T: type, c: Cursor) Error!T { var out: T = undefined; @@ -2270,9 +2282,9 @@ pub const Get = struct { const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?]; if (comptime attr.default_value_ptr) |dp| { @field(out, field) = @as(*const @FieldType(T, field), @ptrCast(@alignCast(dp))).*; - l.note("{s}.{s}: its kind changed; its default taken", .{ @typeName(T), field }); + l.noteField("its kind changed; its default taken", @typeName(T), field); } else if (existing) { - l.note("{s}.{s}: its kind changed; left as it was", .{ @typeName(T), field }); + l.noteField("its kind changed; left as it was", @typeName(T), field); } else failed = true; }; }; @@ -2284,7 +2296,7 @@ pub const Get = struct { const attr = comptime @typeInfo(T).@"struct".field_attrs[std.meta.fieldIndex(T, field).?]; if (comptime attr.default_value_ptr == null and kindOf(Canon(F)) != .void) { if (!existing) { - l.note("{s}.{s}: not in the dump", .{ @typeName(T), field }); + l.noteField("not in the dump", @typeName(T), field); failed = true; } } else if (comptime @typeInfo(F) == .optional and defaultIsNull(T, field)) if (existing) { |
