Skip to content

Commit ac878b8

Browse files
authored
node: add initNode and export asNodePtr (#93)
1 parent c8689af commit ac878b8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/pgzx/node.zig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ pub inline fn create(initFrom: anytype) *@TypeOf(initFrom) {
2121
return node;
2222
}
2323

24+
pub inline fn initNode(initFrom: anytype) @TypeOf(initFrom) {
25+
var node = initFrom;
26+
setTag(&node, mustFindTag(@TypeOf(initFrom)));
27+
return node;
28+
}
29+
2430
fn mustFindTag(comptime T: type) Tag {
2531
return generated.findTag(T) orelse @compileError("No tag found for type");
2632
}
@@ -57,7 +63,7 @@ pub inline fn copyTypedNode(node: anytype) @TypeOf(node) {
5763
return @ptrCast(@alignCast(copy(node)));
5864
}
5965

60-
inline fn asNodePtr(node: anytype) *pg.Node {
66+
pub inline fn asNodePtr(node: anytype) *pg.Node {
6167
checkIsPotentialNodePtr(node);
6268
return @ptrCast(@alignCast(node));
6369
}

0 commit comments

Comments
 (0)