Skip to content

Commit

Permalink
pgzx.node: add List type to iterate over List of Node(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
urso committed Aug 12, 2024
1 parent 0c19bbd commit 7f63637
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/pgzx/node.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const pg = @import("pgzx_pgsys");

const gen = @import("gen_node_tags");
const generated = @import("gen_node_tags");

pub const Tag = gen.Tag;
const collections = @import("collections.zig");

pub const Tag = generated.Tag;

pub const List = collections.list.PointerListOf(pg.Node);

pub inline fn make(comptime T: type) *T {
const node: *pg.Node = @ptrCast(@alignCast(pg.palloc0fast(@sizeOf(T))));
Expand All @@ -18,7 +22,7 @@ pub inline fn create(initFrom: anytype) *@TypeOf(initFrom) {
}

fn mustFindTag(comptime T: type) Tag {
return gen.findTag(T) orelse @compileError("No tag found for type");
return generated.findTag(T) orelse @compileError("No tag found for type");
}

pub inline fn tag(node: anytype) Tag {
Expand All @@ -38,7 +42,7 @@ pub inline fn castNode(comptime T: type, node: anytype) *T {
}

pub inline fn safeCastNode(comptime T: type, node: anytype) ?*T {
if (tag(node) != gen.findTag(T)) {
if (tag(node) != generated.findTag(T)) {
return null;
}
return castNode(T, node);
Expand Down

0 comments on commit 7f63637

Please sign in to comment.