summaryrefslogtreecommitdiff
path: root/core/walk.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/walk.zig')
-rw-r--r--core/walk.zig55
1 files changed, 39 insertions, 16 deletions
diff --git a/core/walk.zig b/core/walk.zig
index 25e4bdc3..51b0a384 100644
--- a/core/walk.zig
+++ b/core/walk.zig
@@ -249,8 +249,6 @@ const Past = struct { name: []const u8, says: usize, holds: usize };
/// its own.
fn pastHeld(comptime T: type, v: *const T, held: ?*const [pairs(T)]usize) ?Past {
inline for (0..comptime pairs(T)) |i| {
- // A buffer no dump carries (derived) is made again, not read.
- if (comptime excluded(T, T.replica.len[i][0])) continue;
const buffer = @field(v, T.replica.len[i][0]);
const holds = if (comptime @typeInfo(@TypeOf(buffer)) == .array) (if (held) |h| @min(h[i], buffer.len) else buffer.len) else buffer.len;
const says = lengthIn(v, T.replica.len[i][1]);
@@ -276,6 +274,10 @@ fn pastHeld(comptime T: type, v: *const T, held: ?*const [pairs(T)]usize) ?Past
// // Its last place, a function of the struct (`fn (*const T) usize`),
// // or its first and last (`[2]usize`).
// .place = .{ .{ "scroll", "lastLine" } },
+// // Where each of its entries (as far as its length says) may be,
+// // a predicate of the struct by the entry's place in the field
+// // (`fn (*const T, usize) bool`): a view's rects on its screen.
+// .within = .{ .{ "rects", "onScreen" } },
// // What a load that left one of its things out (another build's
// // pane) does to what names it (`fn (*T) void`), before its indexes
// // are held.
@@ -286,18 +288,20 @@ fn pastHeld(comptime T: type, v: *const T, held: ?*const [pairs(T)]usize) ?Past
// the disk) is held to them where its fields end, beside its lengths
// (`pastHeld`), every declaration of every type at once: an index that names
// none is REFUSED, its field named (the dump is not the session: the view,
-// the pane it names is not there); a place past its thing's last is that
-// LAST (the session is there, its view a line off). A field that names a
-// slot by its type (`Pane.Id`, `View.Id`) and says nothing is a compile
-// error (`checkSlots`); a bare integer that does is found by reading, as
-// the lengths' were, until it is typed as its slot.
+// the pane it names is not there), and so is an entry that is not where it
+// may be (no session's: a rect past its screen); a place past its thing's
+// last is that LAST (the session is there, its view a line off). A field
+// that names a slot by its type (`Pane.Id`, `View.Id`) and says nothing is
+// a compile error (`checkSlots`); a bare integer that does is found by
+// reading, as the lengths' were, until it is typed as its slot.
fn declared(comptime T: type, comptime kind: []const u8) usize {
return if (@hasDecl(T, "replica") and @hasField(@TypeOf(T.replica), kind)) @field(T.replica, kind).len else 0;
}
-/// An index read back that names none of what it says it indexes.
-const Unnamed = struct { holder: []const u8, name: []const u8, says: usize, of: []const u8 };
+/// An index read back that names none of what it says it indexes, or
+/// (`within`) the entry `says` of a field that is not where it may be.
+const Unnamed = struct { holder: []const u8, name: []const u8, says: usize, of: []const u8, within: bool = false };
/// What an index field says, as a number: an integer, an optional one's (null
/// names nothing), a slot's enum's (`Pane.Id`).
@@ -395,6 +399,11 @@ fn heldIndexes(comptime T: type, v: *T) ?Unnamed {
if (comptime d.len == 2) if (firstUnnamed(T, v, d[0], T, v, d[1])) |i|
return .{ .holder = @typeName(T), .name = d[0], .says = i, .of = @typeName(T) ++ "." ++ d[1] };
}
+ inline for (0..comptime declared(T, "within")) |k| {
+ const d = T.replica.within[k];
+ for (0..heldOf(T, v, d[0])) |i| if (!@field(T, d[1])(v, i))
+ return .{ .holder = @typeName(T), .name = d[0], .says = i, .of = @typeName(T) ++ "." ++ d[1], .within = true };
+ }
inline for (comptime heldIn(T)) |U| if (visit(T, v, U, T, v, 0)) |bad| return bad;
return null;
}
@@ -461,7 +470,10 @@ fn holdTo(l: anytype, comptime T: type, out: *T, held: *const [pairs(T)]usize, d
}
if (comptime @hasDecl(T, "replica")) if (comptime @hasField(@TypeOf(T.replica), "left_out")) if (l.dropped != dropped) @field(T, T.replica.left_out)(out);
if (heldIndexes(T, out)) |bad| {
- l.note("{s}.{s} says {d}, which names none of {s}: refused", .{ bad.holder, bad.name, bad.says, bad.of });
+ if (bad.within)
+ l.note("{s}.{s}[{d}] is not within {s}: refused", .{ bad.holder, bad.name, bad.says, bad.of })
+ else
+ l.note("{s}.{s} says {d}, which names none of {s}: refused", .{ bad.holder, bad.name, bad.says, bad.of });
return error.BadDump;
}
}
@@ -499,10 +511,11 @@ fn checkAnnotations(comptime T: type) void {
continue;
}
inline for (@field(T.replica, kind)) |entry| {
- const pair = comptime std.mem.eql(u8, kind, "len") or std.mem.eql(u8, kind, "alloc") or std.mem.eql(u8, kind, "index") or std.mem.eql(u8, kind, "place");
+ const held = comptime std.mem.eql(u8, kind, "index") or std.mem.eql(u8, kind, "place") or std.mem.eql(u8, kind, "within");
+ const pair = comptime held or std.mem.eql(u8, kind, "len") or std.mem.eql(u8, kind, "alloc");
const name = if (pair) entry[0] else entry;
if (!@hasField(T, name)) @compileError("walk: " ++ @typeName(T) ++ " annotates no field " ++ name);
- if (comptime std.mem.eql(u8, kind, "index") or std.mem.eql(u8, kind, "place")) {
+ if (held) {
const H = if (entry.len >= 3) entry[1] else T;
const what = if (entry.len >= 3) entry[2] else entry[1];
if (entry.len == 4) if (!@hasField(T, entry[3])) @compileError("walk: " ++ @typeName(T) ++ " counts its span by no field " ++ entry[3]);
@@ -3146,7 +3159,7 @@ test "a length past what its buffer holds is refused where it is read back (a ta
try std.testing.expectError(error.BadDump, get.get(Room, (try Get.member(root, "room")).?));
}
-test "an index read back that names none of its things is refused, its field named, in a tape, a dump and an image; a place past its thing's last is that last" {
+test "an index read back that names none of its things is refused, its field named, in a tape, a dump and an image, and so is an entry not where it may be; a place past its thing's last is that last" {
const S = struct {
const Self = @This();
const Inner = struct {
@@ -3161,10 +3174,14 @@ test "an index read back that names none of its things is refused, its field nam
slot: ?u16 = null,
scroll: u32 = 0,
inner: [2]?*Inner = @splat(null),
- pub const replica = .{ .index = .{ .{ "live", "there" }, .{ "slot", "things" } }, .place = .{.{ "scroll", "last" }} };
+ edges: [2]u8 = @splat(0),
+ pub const replica = .{ .index = .{ .{ "live", "there" }, .{ "slot", "things" } }, .place = .{.{ "scroll", "last" }}, .within = .{.{ "edges", "inside" }} };
pub fn there(s: *const Self, i: usize) bool {
return i < s.things.len and s.things[i] != null;
}
+ pub fn inside(s: *const Self, i: usize) bool {
+ return s.edges[i] < 8;
+ }
pub fn last(_: *const Self) usize {
return 9;
}
@@ -3200,7 +3217,13 @@ test "an index read back that names none of its things is refused, its field nam
v.inner[1] = &bad_list;
break :blk v;
} },
+ .{ "S.edges[1] is not within", blk: {
+ var v = good;
+ v.edges = .{ 7, 8 };
+ break :blk v;
+ } },
};
+ const n_bad = bad.len;
var notes: std.ArrayList(u8) = .empty;
// A dump.
@@ -3239,14 +3262,14 @@ test "an index read back that names none of its things is refused, its field nam
pub fn run(ctx: @This(), cursor: *Mem.Cursor(.read_write)) !void {
const map = try Mem.HashMap(.read_write).init(cursor.*);
try ctx.put.member(map, "good", S, ctx.good);
- inline for (0..4) |i| try ctx.put.member(map, std.fmt.comptimePrint("bad{d}", .{i}), S, &ctx.bad[i][1]);
+ inline for (0..n_bad) |i| try ctx.put.member(map, std.fmt.comptimePrint("bad{d}", .{i}), S, &ctx.bad[i][1]);
}
}{ .put = &put, .good = &good, .bad = &bad });
var get: Get = .init(a);
defer get.deinit();
const root = db.rootCursor().readOnly();
try std.testing.expectEqual(@as(u32, 9), (try get.get(S, (try Get.member(root, "good")).?)).scroll);
- inline for (0..4) |i| {
+ inline for (0..n_bad) |i| {
get.notes.clearRetainingCapacity();
try std.testing.expectError(error.BadDump, get.get(S, (try Get.member(root, std.fmt.comptimePrint("bad{d}", .{i}))).?));
try std.testing.expect(std.mem.indexOf(u8, get.notes.items, bad[i][0]) != null);