authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-23 20:14:38-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-23 20:14:38-04:00
logf771545a7ecfa77ad18745b11d80d0f5238ecb65
tree921c2313fa60e27e6bc2fdc4a98cad82714d0aa2
parentc78a2e2e8dc50a6e57ad4d390184e564dbe7be67

revert std.zig.ast iterator changes back to master branch API


1 files changed, 105 insertions(+), 381 deletions(-)

lib/std/zig/ast.zig+105-381
......@@ -399,22 +399,6 @@ pub const Error = union(enum) {
399399pub const Node = struct {
400400 id: Id,
401401
402 /// All the child Node types use this same Iterator state for their iteration.
403 pub const Iterator = struct {
404 parent_node: *const Node,
405 index: usize,
406
407 pub fn next(it: *Iterator) ?*Node {
408 inline for (@typeInfo(Id).Enum.fields) |f| {
409 if (it.parent_node.id == @field(Id, f.name)) {
410 const T = @field(Node, f.name);
411 return @fieldParentPtr(T, "base", it.parent_node).iterateNext(it);
412 }
413 }
414 unreachable;
415 }
416 };
417
418402 pub const Id = enum {
419403 // Top level
420404 Root,
......@@ -497,11 +481,11 @@ pub const Node = struct {
497481 return null;
498482 }
499483
500 pub fn iterate(base: *Node) Iterator {
484 pub fn iterate(base: *Node, index: usize) ?*Node {
501485 inline for (@typeInfo(Id).Enum.fields) |f| {
502486 if (base.id == @field(Id, f.name)) {
503487 const T = @field(Node, f.name);
504 return @fieldParentPtr(T, "base", base).iterate();
488 return @fieldParentPtr(T, "base", base).iterate(index);
505489 }
506490 }
507491 unreachable;
......@@ -647,13 +631,8 @@ pub const Node = struct {
647631 allocator.free(bytes);
648632 }
649633
650 pub fn iterate(self: *const Root) Node.Iterator {
651 return .{ .parent_node = &self.base, .index = 0 };
652 }
653
654 pub fn iterateNext(self: *const Root, it: *Node.Iterator) ?*Node {
655 var i = it.index;
656 it.index += 1;
634 pub fn iterate(self: *const Root, index: usize) ?*Node {
635 var i = index;
657636
658637 if (i < self.decls_len) return self.declsConst()[i];
659638 return null;
......@@ -701,13 +680,8 @@ pub const Node = struct {
701680 init_node: ?*Node,
702681 semicolon_token: TokenIndex,
703682
704 pub fn iterate(self: *const VarDecl) Node.Iterator {
705 return .{ .parent_node = &self.base, .index = 0 };
706 }
707
708 pub fn iterateNext(self: *const VarDecl, it: *Node.Iterator) ?*Node {
709 var i = it.index;
710 it.index += 1;
683 pub fn iterate(self: *const VarDecl, index: usize) ?*Node {
684 var i = index;
711685
712686 if (self.type_node) |type_node| {
713687 if (i < 1) return type_node;
......@@ -755,13 +729,8 @@ pub const Node = struct {
755729 expr: *Node,
756730 semicolon_token: TokenIndex,
757731
758 pub fn iterate(self: *const Use) Node.Iterator {
759 return .{ .parent_node = &self.base, .index = 0 };
760 }
761
762 pub fn iterateNext(self: *const Use, it: *Node.Iterator) ?*Node {
763 var i = it.index;
764 it.index += 1;
732 pub fn iterate(self: *const Use, index: usize) ?*Node {
733 var i = index;
765734
766735 if (i < 1) return self.expr;
767736 i -= 1;
......@@ -796,13 +765,8 @@ pub const Node = struct {
796765 allocator.free(bytes);
797766 }
798767
799 pub fn iterate(self: *const ErrorSetDecl) Node.Iterator {
800 return .{ .parent_node = &self.base, .index = 0 };
801 }
802
803 pub fn iterateNext(self: *const ErrorSetDecl, it: *Node.Iterator) ?*Node {
804 var i = it.index;
805 it.index += 1;
768 pub fn iterate(self: *const ErrorSetDecl, index: usize) ?*Node {
769 var i = index;
806770
807771 if (i < self.decls_len) return self.declsConst()[i];
808772 i -= self.decls_len;
......@@ -860,13 +824,8 @@ pub const Node = struct {
860824 allocator.free(bytes);
861825 }
862826
863 pub fn iterate(self: *const ContainerDecl) Node.Iterator {
864 return .{ .parent_node = &self.base, .index = 0 };
865 }
866
867 pub fn iterateNext(self: *const ContainerDecl, it: *Node.Iterator) ?*Node {
868 var i = it.index;
869 it.index += 1;
827 pub fn iterate(self: *const ContainerDecl, index: usize) ?*Node {
828 var i = index;
870829
871830 switch (self.init_arg_expr) {
872831 .Type => |t| {
......@@ -917,13 +876,8 @@ pub const Node = struct {
917876 value_expr: ?*Node,
918877 align_expr: ?*Node,
919878
920 pub fn iterate(self: *const ContainerField) Node.Iterator {
921 return .{ .parent_node = &self.base, .index = 0 };
922 }
923
924 pub fn iterateNext(self: *const ContainerField, it: *Node.Iterator) ?*Node {
925 var i = it.index;
926 it.index += 1;
879 pub fn iterate(self: *const ContainerField, index: usize) ?*Node {
880 var i = index;
927881
928882 if (self.type_expr) |type_expr| {
929883 if (i < 1) return type_expr;
......@@ -969,13 +923,8 @@ pub const Node = struct {
969923 doc_comments: ?*DocComment,
970924 name_token: TokenIndex,
971925
972 pub fn iterate(self: *const ErrorTag) Node.Iterator {
973 return .{ .parent_node = &self.base, .index = 0 };
974 }
975
976 pub fn iterateNext(self: *const ErrorTag, it: *Node.Iterator) ?*Node {
977 var i = it.index;
978 it.index += 1;
926 pub fn iterate(self: *const ErrorTag, index: usize) ?*Node {
927 var i = index;
979928
980929 if (self.doc_comments) |comments| {
981930 if (i < 1) return &comments.base;
......@@ -998,11 +947,7 @@ pub const Node = struct {
998947 base: Node = Node{ .id = .Identifier },
999948 token: TokenIndex,
1000949
1001 pub fn iterate(self: *const Identifier) Node.Iterator {
1002 return .{ .parent_node = &self.base, .index = 0 };
1003 }
1004
1005 pub fn iterateNext(self: *const Identifier, it: *Node.Iterator) ?*Node {
950 pub fn iterate(self: *const Identifier, index: usize) ?*Node {
1006951 return null;
1007952 }
1008953
......@@ -1053,13 +998,8 @@ pub const Node = struct {
1053998 type_expr: *Node,
1054999 };
10551000
1056 pub fn iterate(self: *const ParamDecl) Node.Iterator {
1057 return .{ .parent_node = &self.base, .index = 0 };
1058 }
1059
1060 pub fn iterateNext(self: *const ParamDecl, it: *Node.Iterator) ?*Node {
1061 var i = it.index;
1062 it.index += 1;
1001 pub fn iterate(self: *const ParamDecl, index: usize) ?*Node {
1002 var i = index;
10631003
10641004 if (i < 1) {
10651005 switch (self.param_type) {
......@@ -1101,30 +1041,26 @@ pub const Node = struct {
11011041 allocator.free(bytes);
11021042 }
11031043
1104 pub fn iterate(self: *const FnProto) Node.Iterator {
1105 return .{ .parent_node = &self.base, .index = 0 };
1106 }
1107
1108 pub fn iterateNext(self: *const FnProto, it: *Node.Iterator) ?*Node {
1109 var i = it.index;
1110 it.index += 1;
1044 pub fn iterate(self: *const FnProto, index: usize) ?*Node {
1045 var i = index;
11111046
11121047 if (self.lib_name) |lib_name| {
11131048 if (i < 1) return lib_name;
11141049 i -= 1;
11151050 }
11161051
1117 if (i < self.params_len) {
1052 const params_len = switch (self.paramsConst()[self.params_len - 1].param_type) {
1053 .var_type, .type_expr => self.params_len,
1054 .var_args => self.params_len - 1,
1055 };
1056 if (i < params_len) {
11181057 switch (self.paramsConst()[i].param_type) {
11191058 .var_type => |n| return n,
1120 .var_args => {
1121 i += 1;
1122 it.index += 1;
1123 },
1059 .var_args => unreachable,
11241060 .type_expr => |n| return n,
11251061 }
11261062 }
1127 i -= self.params_len;
1063 i -= params_len;
11281064
11291065 if (self.align_expr) |align_expr| {
11301066 if (i < 1) return align_expr;
......@@ -1192,13 +1128,8 @@ pub const Node = struct {
11921128 return_type: *Node,
11931129 };
11941130
1195 pub fn iterate(self: *const AnyFrameType) Node.Iterator {
1196 return .{ .parent_node = &self.base, .index = 0 };
1197 }
1198
1199 pub fn iterateNext(self: *const AnyFrameType, it: *Node.Iterator) ?*Node {
1200 var i = it.index;
1201 it.index += 1;
1131 pub fn iterate(self: *const AnyFrameType, index: usize) ?*Node {
1132 var i = index;
12021133
12031134 if (self.result) |result| {
12041135 if (i < 1) return result.return_type;
......@@ -1237,13 +1168,8 @@ pub const Node = struct {
12371168 allocator.free(bytes);
12381169 }
12391170
1240 pub fn iterate(self: *const Block) Node.Iterator {
1241 return .{ .parent_node = &self.base, .index = 0 };
1242 }
1243
1244 pub fn iterateNext(self: *const Block, it: *Node.Iterator) ?*Node {
1245 var i = it.index;
1246 it.index += 1;
1171 pub fn iterate(self: *const Block, index: usize) ?*Node {
1172 var i = index;
12471173
12481174 if (i < self.statements_len) return self.statementsConst()[i];
12491175 i -= self.statements_len;
......@@ -1284,13 +1210,8 @@ pub const Node = struct {
12841210 payload: ?*Node,
12851211 expr: *Node,
12861212
1287 pub fn iterate(self: *const Defer) Node.Iterator {
1288 return .{ .parent_node = &self.base, .index = 0 };
1289 }
1290
1291 pub fn iterateNext(self: *const Defer, it: *Node.Iterator) ?*Node {
1292 var i = it.index;
1293 it.index += 1;
1213 pub fn iterate(self: *const Defer, index: usize) ?*Node {
1214 var i = index;
12941215
12951216 if (i < 1) return self.expr;
12961217 i -= 1;
......@@ -1313,13 +1234,8 @@ pub const Node = struct {
13131234 comptime_token: TokenIndex,
13141235 expr: *Node,
13151236
1316 pub fn iterate(self: *const Comptime) Node.Iterator {
1317 return .{ .parent_node = &self.base, .index = 0 };
1318 }
1319
1320 pub fn iterateNext(self: *const Comptime, it: *Node.Iterator) ?*Node {
1321 var i = it.index;
1322 it.index += 1;
1237 pub fn iterate(self: *const Comptime, index: usize) ?*Node {
1238 var i = index;
13231239
13241240 if (i < 1) return self.expr;
13251241 i -= 1;
......@@ -1341,13 +1257,8 @@ pub const Node = struct {
13411257 nosuspend_token: TokenIndex,
13421258 expr: *Node,
13431259
1344 pub fn iterate(self: *const Nosuspend) Node.Iterator {
1345 return .{ .parent_node = &self.base, .index = 0 };
1346 }
1347
1348 pub fn iterateNext(self: *const Nosuspend, it: *Node.Iterator) ?*Node {
1349 var i = it.index;
1350 it.index += 1;
1260 pub fn iterate(self: *const Nosuspend, index: usize) ?*Node {
1261 var i = index;
13511262
13521263 if (i < 1) return self.expr;
13531264 i -= 1;
......@@ -1370,13 +1281,8 @@ pub const Node = struct {
13701281 error_symbol: *Node,
13711282 rpipe: TokenIndex,
13721283
1373 pub fn iterate(self: *const Payload) Node.Iterator {
1374 return .{ .parent_node = &self.base, .index = 0 };
1375 }
1376
1377 pub fn iterateNext(self: *const Payload, it: *Node.Iterator) ?*Node {
1378 var i = it.index;
1379 it.index += 1;
1284 pub fn iterate(self: *const Payload, index: usize) ?*Node {
1285 var i = index;
13801286
13811287 if (i < 1) return self.error_symbol;
13821288 i -= 1;
......@@ -1400,13 +1306,8 @@ pub const Node = struct {
14001306 value_symbol: *Node,
14011307 rpipe: TokenIndex,
14021308
1403 pub fn iterate(self: *const PointerPayload) Node.Iterator {
1404 return .{ .parent_node = &self.base, .index = 0 };
1405 }
1406
1407 pub fn iterateNext(self: *const PointerPayload, it: *Node.Iterator) ?*Node {
1408 var i = it.index;
1409 it.index += 1;
1309 pub fn iterate(self: *const PointerPayload, index: usize) ?*Node {
1310 var i = index;
14101311
14111312 if (i < 1) return self.value_symbol;
14121313 i -= 1;
......@@ -1431,13 +1332,8 @@ pub const Node = struct {
14311332 index_symbol: ?*Node,
14321333 rpipe: TokenIndex,
14331334
1434 pub fn iterate(self: *const PointerIndexPayload) Node.Iterator {
1435 return .{ .parent_node = &self.base, .index = 0 };
1436 }
1437
1438 pub fn iterateNext(self: *const PointerIndexPayload, it: *Node.Iterator) ?*Node {
1439 var i = it.index;
1440 it.index += 1;
1335 pub fn iterate(self: *const PointerIndexPayload, index: usize) ?*Node {
1336 var i = index;
14411337
14421338 if (i < 1) return self.value_symbol;
14431339 i -= 1;
......@@ -1465,13 +1361,8 @@ pub const Node = struct {
14651361 payload: ?*Node,
14661362 body: *Node,
14671363
1468 pub fn iterate(self: *const Else) Node.Iterator {
1469 return .{ .parent_node = &self.base, .index = 0 };
1470 }
1471
1472 pub fn iterateNext(self: *const Else, it: *Node.Iterator) ?*Node {
1473 var i = it.index;
1474 it.index += 1;
1364 pub fn iterate(self: *const Else, index: usize) ?*Node {
1365 var i = index;
14751366
14761367 if (self.payload) |payload| {
14771368 if (i < 1) return payload;
......@@ -1513,13 +1404,8 @@ pub const Node = struct {
15131404 allocator.free(bytes);
15141405 }
15151406
1516 pub fn iterate(self: *const Switch) Node.Iterator {
1517 return .{ .parent_node = &self.base, .index = 0 };
1518 }
1519
1520 pub fn iterateNext(self: *const Switch, it: *Node.Iterator) ?*Node {
1521 var i = it.index;
1522 it.index += 1;
1407 pub fn iterate(self: *const Switch, index: usize) ?*Node {
1408 var i = index;
15231409
15241410 if (i < 1) return self.expr;
15251411 i -= 1;
......@@ -1572,13 +1458,8 @@ pub const Node = struct {
15721458 allocator.free(bytes);
15731459 }
15741460
1575 pub fn iterate(self: *const SwitchCase) Node.Iterator {
1576 return .{ .parent_node = &self.base, .index = 0 };
1577 }
1578
1579 pub fn iterateNext(self: *const SwitchCase, it: *Node.Iterator) ?*Node {
1580 var i = it.index;
1581 it.index += 1;
1461 pub fn iterate(self: *const SwitchCase, index: usize) ?*Node {
1462 var i = index;
15821463
15831464 if (i < self.items_len) return self.itemsConst()[i];
15841465 i -= self.items_len;
......@@ -1621,11 +1502,7 @@ pub const Node = struct {
16211502 base: Node = Node{ .id = .SwitchElse },
16221503 token: TokenIndex,
16231504
1624 pub fn iterate(self: *const SwitchElse) Node.Iterator {
1625 return .{ .parent_node = &self.base, .index = 0 };
1626 }
1627
1628 pub fn iterateNext(self: *const SwitchElse, it: *Node.Iterator) ?*Node {
1505 pub fn iterate(self: *const SwitchElse, index: usize) ?*Node {
16291506 return null;
16301507 }
16311508
......@@ -1649,13 +1526,8 @@ pub const Node = struct {
16491526 body: *Node,
16501527 @"else": ?*Else,
16511528
1652 pub fn iterate(self: *const While) Node.Iterator {
1653 return .{ .parent_node = &self.base, .index = 0 };
1654 }
1655
1656 pub fn iterateNext(self: *const While, it: *Node.Iterator) ?*Node {
1657 var i = it.index;
1658 it.index += 1;
1529 pub fn iterate(self: *const While, index: usize) ?*Node {
1530 var i = index;
16591531
16601532 if (i < 1) return self.condition;
16611533 i -= 1;
......@@ -1712,13 +1584,8 @@ pub const Node = struct {
17121584 body: *Node,
17131585 @"else": ?*Else,
17141586
1715 pub fn iterate(self: *const For) Node.Iterator {
1716 return .{ .parent_node = &self.base, .index = 0 };
1717 }
1718
1719 pub fn iterateNext(self: *const For, it: *Node.Iterator) ?*Node {
1720 var i = it.index;
1721 it.index += 1;
1587 pub fn iterate(self: *const For, index: usize) ?*Node {
1588 var i = index;
17221589
17231590 if (i < 1) return self.array_expr;
17241591 i -= 1;
......@@ -1766,13 +1633,8 @@ pub const Node = struct {
17661633 body: *Node,
17671634 @"else": ?*Else,
17681635
1769 pub fn iterate(self: *const If) Node.Iterator {
1770 return .{ .parent_node = &self.base, .index = 0 };
1771 }
1772
1773 pub fn iterateNext(self: *const If, it: *Node.Iterator) ?*Node {
1774 var i = it.index;
1775 it.index += 1;
1636 pub fn iterate(self: *const If, index: usize) ?*Node {
1637 var i = index;
17761638
17771639 if (i < 1) return self.condition;
17781640 i -= 1;
......@@ -1859,13 +1721,8 @@ pub const Node = struct {
18591721 UnwrapOptional,
18601722 };
18611723
1862 pub fn iterate(self: *const InfixOp) Node.Iterator {
1863 return .{ .parent_node = &self.base, .index = 0 };
1864 }
1865
1866 pub fn iterateNext(self: *const InfixOp, it: *Node.Iterator) ?*Node {
1867 var i = it.index;
1868 it.index += 1;
1724 pub fn iterate(self: *const InfixOp, index: usize) ?*Node {
1725 var i = index;
18691726
18701727 if (i < 1) return self.lhs;
18711728 i -= 1;
......@@ -1982,13 +1839,8 @@ pub const Node = struct {
19821839 };
19831840 };
19841841
1985 pub fn iterate(self: *const PrefixOp) Node.Iterator {
1986 return .{ .parent_node = &self.base, .index = 0 };
1987 }
1988
1989 pub fn iterateNext(self: *const PrefixOp, it: *Node.Iterator) ?*Node {
1990 var i = it.index;
1991 it.index += 1;
1842 pub fn iterate(self: *const PrefixOp, index: usize) ?*Node {
1843 var i = index;
19921844
19931845 switch (self.op) {
19941846 .PtrType, .SliceType => |addr_of_info| {
......@@ -2045,13 +1897,8 @@ pub const Node = struct {
20451897 name_token: TokenIndex,
20461898 expr: *Node,
20471899
2048 pub fn iterate(self: *const FieldInitializer) Node.Iterator {
2049 return .{ .parent_node = &self.base, .index = 0 };
2050 }
2051
2052 pub fn iterateNext(self: *const FieldInitializer, it: *Node.Iterator) ?*Node {
2053 var i = it.index;
2054 it.index += 1;
1900 pub fn iterate(self: *const FieldInitializer, index: usize) ?*Node {
1901 var i = index;
20551902
20561903 if (i < 1) return self.expr;
20571904 i -= 1;
......@@ -2086,13 +1933,8 @@ pub const Node = struct {
20861933 allocator.free(bytes);
20871934 }
20881935
2089 pub fn iterate(self: *const ArrayInitializer) Node.Iterator {
2090 return .{ .parent_node = &self.base, .index = 0 };
2091 }
2092
2093 pub fn iterateNext(self: *const ArrayInitializer, it: *Node.Iterator) ?*Node {
2094 var i = it.index;
2095 it.index += 1;
1936 pub fn iterate(self: *const ArrayInitializer, index: usize) ?*Node {
1937 var i = index;
20961938
20971939 if (i < 1) return self.lhs;
20981940 i -= 1;
......@@ -2144,13 +1986,8 @@ pub const Node = struct {
21441986 allocator.free(bytes);
21451987 }
21461988
2147 pub fn iterate(self: *const ArrayInitializerDot) Node.Iterator {
2148 return .{ .parent_node = &self.base, .index = 0 };
2149 }
2150
2151 pub fn iterateNext(self: *const ArrayInitializerDot, it: *Node.Iterator) ?*Node {
2152 var i = it.index;
2153 it.index += 1;
1989 pub fn iterate(self: *const ArrayInitializerDot, index: usize) ?*Node {
1990 var i = index;
21541991
21551992 if (i < self.list_len) return self.listConst()[i];
21561993 i -= self.list_len;
......@@ -2199,13 +2036,8 @@ pub const Node = struct {
21992036 allocator.free(bytes);
22002037 }
22012038
2202 pub fn iterate(self: *const StructInitializer) Node.Iterator {
2203 return .{ .parent_node = &self.base, .index = 0 };
2204 }
2205
2206 pub fn iterateNext(self: *const StructInitializer, it: *Node.Iterator) ?*Node {
2207 var i = it.index;
2208 it.index += 1;
2039 pub fn iterate(self: *const StructInitializer, index: usize) ?*Node {
2040 var i = index;
22092041
22102042 if (i < 1) return self.lhs;
22112043 i -= 1;
......@@ -2257,13 +2089,8 @@ pub const Node = struct {
22572089 allocator.free(bytes);
22582090 }
22592091
2260 pub fn iterate(self: *const StructInitializerDot) Node.Iterator {
2261 return .{ .parent_node = &self.base, .index = 0 };
2262 }
2263
2264 pub fn iterateNext(self: *const StructInitializerDot, it: *Node.Iterator) ?*Node {
2265 var i = it.index;
2266 it.index += 1;
2092 pub fn iterate(self: *const StructInitializerDot, index: usize) ?*Node {
2093 var i = index;
22672094
22682095 if (i < self.list_len) return self.listConst()[i];
22692096 i -= self.list_len;
......@@ -2313,13 +2140,8 @@ pub const Node = struct {
23132140 allocator.free(bytes);
23142141 }
23152142
2316 pub fn iterate(self: *const Call) Node.Iterator {
2317 return .{ .parent_node = &self.base, .index = 0};
2318 }
2319
2320 pub fn iterateNext(self: *const Call, it: *Node.Iterator) ?*Node {
2321 var i = it.index;
2322 it.index += 1;
2143 pub fn iterate(self: *const Call, index: usize) ?*Node {
2144 var i = index;
23232145
23242146 if (i < 1) return self.lhs;
23252147 i -= 1;
......@@ -2373,13 +2195,8 @@ pub const Node = struct {
23732195 };
23742196 };
23752197
2376 pub fn iterate(self: *const SuffixOp) Node.Iterator {
2377 return .{ .parent_node = &self.base, .index = 0};
2378 }
2379
2380 pub fn iterateNext(self: *const SuffixOp, it: *Node.Iterator) ?*Node {
2381 var i = it.index;
2382 it.index += 1;
2198 pub fn iterate(self: *const SuffixOp, index: usize) ?*Node {
2199 var i = index;
23832200
23842201 if (i == 0) return self.lhs;
23852202 i -= 1;
......@@ -2425,13 +2242,8 @@ pub const Node = struct {
24252242 expr: *Node,
24262243 rparen: TokenIndex,
24272244
2428 pub fn iterate(self: *const GroupedExpression) Node.Iterator {
2429 return .{ .parent_node = &self.base, .index = 0 };
2430 }
2431
2432 pub fn iterateNext(self: *const GroupedExpression, it: *Node.Iterator) ?*Node {
2433 var i = it.index;
2434 it.index += 1;
2245 pub fn iterate(self: *const GroupedExpression, index: usize) ?*Node {
2246 var i = index;
24352247
24362248 if (i < 1) return self.expr;
24372249 i -= 1;
......@@ -2460,13 +2272,8 @@ pub const Node = struct {
24602272 Return,
24612273 };
24622274
2463 pub fn iterate(self: *const ControlFlowExpression) Node.Iterator {
2464 return .{ .parent_node = &self.base, .index = 0 };
2465 }
2466
2467 pub fn iterateNext(self: *const ControlFlowExpression, it: *Node.Iterator) ?*Node {
2468 var i = it.index;
2469 it.index += 1;
2275 pub fn iterate(self: *const ControlFlowExpression, index: usize) ?*Node {
2276 var i = index;
24702277
24712278 switch (self.kind) {
24722279 .Break, .Continue => |maybe_label| {
......@@ -2513,13 +2320,8 @@ pub const Node = struct {
25132320 suspend_token: TokenIndex,
25142321 body: ?*Node,
25152322
2516 pub fn iterate(self: *const Suspend) Node.Iterator {
2517 return .{ .parent_node = &self.base, .index = 0 };
2518 }
2519
2520 pub fn iterateNext(self: *const Suspend, it: *Node.Iterator) ?*Node {
2521 var i = it.index;
2522 it.index += 1;
2323 pub fn iterate(self: *const Suspend, index: usize) ?*Node {
2324 var i = index;
25232325
25242326 if (self.body) |body| {
25252327 if (i < 1) return body;
......@@ -2546,11 +2348,7 @@ pub const Node = struct {
25462348 base: Node = Node{ .id = .IntegerLiteral },
25472349 token: TokenIndex,
25482350
2549 pub fn iterate(self: *const IntegerLiteral) Node.Iterator {
2550 return .{ .parent_node = &self.base, .index = 0 };
2551 }
2552
2553 pub fn iterateNext(self: *const IntegerLiteral, it: *Node.Iterator) ?*Node {
2351 pub fn iterate(self: *const IntegerLiteral, index: usize) ?*Node {
25542352 return null;
25552353 }
25562354
......@@ -2568,11 +2366,7 @@ pub const Node = struct {
25682366 dot: TokenIndex,
25692367 name: TokenIndex,
25702368
2571 pub fn iterate(self: *const EnumLiteral) Node.Iterator {
2572 return .{ .parent_node = &self.base, .index = 0 };
2573 }
2574
2575 pub fn iterateNext(self: *const EnumLiteral, it: *Node.Iterator) ?*Node {
2369 pub fn iterate(self: *const EnumLiteral, index: usize) ?*Node {
25762370 return null;
25772371 }
25782372
......@@ -2589,11 +2383,7 @@ pub const Node = struct {
25892383 base: Node = Node{ .id = .FloatLiteral },
25902384 token: TokenIndex,
25912385
2592 pub fn iterate(self: *const FloatLiteral) Node.Iterator {
2593 return .{ .parent_node = &self.base, .index = 0 };
2594 }
2595
2596 pub fn iterateNext(self: *const FloatLiteral, it: *Node.Iterator) ?*Node {
2386 pub fn iterate(self: *const FloatLiteral, index: usize) ?*Node {
25972387 return null;
25982388 }
25992389
......@@ -2624,13 +2414,8 @@ pub const Node = struct {
26242414 allocator.free(bytes);
26252415 }
26262416
2627 pub fn iterate(self: *const BuiltinCall) Node.Iterator {
2628 return .{ .parent_node = &self.base, .index = 0 };
2629 }
2630
2631 pub fn iterateNext(self: *const BuiltinCall, it: *Node.Iterator) ?*Node {
2632 var i = it.index;
2633 it.index += 1;
2417 pub fn iterate(self: *const BuiltinCall, index: usize) ?*Node {
2418 var i = index;
26342419
26352420 if (i < self.params_len) return self.paramsConst()[i];
26362421 i -= self.params_len;
......@@ -2665,11 +2450,7 @@ pub const Node = struct {
26652450 base: Node = Node{ .id = .StringLiteral },
26662451 token: TokenIndex,
26672452
2668 pub fn iterate(self: *const StringLiteral) Node.Iterator {
2669 return .{ .parent_node = &self.base, .index = 0 };
2670 }
2671
2672 pub fn iterateNext(self: *const StringLiteral, it: *Node.Iterator) ?*Node {
2453 pub fn iterate(self: *const StringLiteral, index: usize) ?*Node {
26732454 return null;
26742455 }
26752456
......@@ -2698,11 +2479,7 @@ pub const Node = struct {
26982479 allocator.free(bytes);
26992480 }
27002481
2701 pub fn iterate(self: *const MultilineStringLiteral) Node.Iterator {
2702 return .{ .parent_node = &self.base, .index = 0 };
2703 }
2704
2705 pub fn iterateNext(self: *const MultilineStringLiteral, it: *Node.Iterator) ?*Node {
2482 pub fn iterate(self: *const MultilineStringLiteral, index: usize) ?*Node {
27062483 return null;
27072484 }
27082485
......@@ -2733,11 +2510,7 @@ pub const Node = struct {
27332510 base: Node = Node{ .id = .CharLiteral },
27342511 token: TokenIndex,
27352512
2736 pub fn iterate(self: *const CharLiteral) Node.Iterator {
2737 return .{ .parent_node = &self.base, .index = 0 };
2738 }
2739
2740 pub fn iterateNext(self: *const CharLiteral, it: *Node.Iterator) ?*Node {
2513 pub fn iterate(self: *const CharLiteral, index: usize) ?*Node {
27412514 return null;
27422515 }
27432516
......@@ -2754,11 +2527,7 @@ pub const Node = struct {
27542527 base: Node = Node{ .id = .BoolLiteral },
27552528 token: TokenIndex,
27562529
2757 pub fn iterate(self: *const BoolLiteral) Node.Iterator {
2758 return .{ .parent_node = &self.base, .index = 0 };
2759 }
2760
2761 pub fn iterateNext(self: *const BoolLiteral, it: *Node.Iterator) ?*Node {
2530 pub fn iterate(self: *const BoolLiteral, index: usize) ?*Node {
27622531 return null;
27632532 }
27642533
......@@ -2775,11 +2544,7 @@ pub const Node = struct {
27752544 base: Node = Node{ .id = .NullLiteral },
27762545 token: TokenIndex,
27772546
2778 pub fn iterate(self: *const NullLiteral) Node.Iterator {
2779 return .{ .parent_node = &self.base, .index = 0 };
2780 }
2781
2782 pub fn iterateNext(self: *const NullLiteral, it: *Node.Iterator) ?*Node {
2547 pub fn iterate(self: *const NullLiteral, index: usize) ?*Node {
27832548 return null;
27842549 }
27852550
......@@ -2796,11 +2561,7 @@ pub const Node = struct {
27962561 base: Node = Node{ .id = .UndefinedLiteral },
27972562 token: TokenIndex,
27982563
2799 pub fn iterate(self: *const UndefinedLiteral) Node.Iterator {
2800 return .{ .parent_node = &self.base, .index = 0 };
2801 }
2802
2803 pub fn iterateNext(self: *const UndefinedLiteral, it: *Node.Iterator) ?*Node {
2564 pub fn iterate(self: *const UndefinedLiteral, index: usize) ?*Node {
28042565 return null;
28052566 }
28062567
......@@ -2836,13 +2597,8 @@ pub const Node = struct {
28362597 Return: *Node,
28372598 };
28382599
2839 pub fn iterate(self: *const Output) Node.Iterator {
2840 return .{ .parent_node = &self.base, .index = 0 };
2841 }
2842
2843 pub fn iterateNext(self: *const Output, it: *Node.Iterator) ?*Node {
2844 var i = it.index;
2845 it.index += 1;
2600 pub fn iterate(self: *const Output, index: usize) ?*Node {
2601 var i = index;
28462602
28472603 if (i < 1) return self.symbolic_name;
28482604 i -= 1;
......@@ -2880,13 +2636,8 @@ pub const Node = struct {
28802636 expr: *Node,
28812637 rparen: TokenIndex,
28822638
2883 pub fn iterate(self: *const Input) Node.Iterator {
2884 return .{ .parent_node = &self.base, .index = 0 };
2885 }
2886
2887 pub fn iterateNext(self: *const Input, it: *Node.Iterator) ?*Node {
2888 var i = it.index;
2889 it.index += 1;
2639 pub fn iterate(self: *const Input, index: usize) ?*Node {
2640 var i = index;
28902641
28912642 if (i < 1) return self.symbolic_name;
28922643 i -= 1;
......@@ -2910,13 +2661,8 @@ pub const Node = struct {
29102661 };
29112662
29122663
2913 pub fn iterate(self: *const Asm) Node.Iterator {
2914 return .{ .parent_node = &self.base, .index = 0};
2915 }
2916
2917 pub fn iterateNext(self: *const Asm, it: *Node.Iterator) ?*Node {
2918 var i = it.index;
2919 it.index += 1;
2664 pub fn iterate(self: *const Asm, index: usize) ?*Node {
2665 var i = index;
29202666
29212667 if (i < self.outputs.len * 3) switch (i % 3) {
29222668 0 => return self.outputs[i / 3].symbolic_name,
......@@ -2953,11 +2699,7 @@ pub const Node = struct {
29532699 base: Node = Node{ .id = .Unreachable },
29542700 token: TokenIndex,
29552701
2956 pub fn iterate(self: *const Unreachable) Node.Iterator {
2957 return .{ .parent_node = &self.base, .index = 0 };
2958 }
2959
2960 pub fn iterateNext(self: *const Unreachable, it: *Node.Iterator) ?*Node {
2702 pub fn iterate(self: *const Unreachable, index: usize) ?*Node {
29612703 return null;
29622704 }
29632705
......@@ -2974,11 +2716,7 @@ pub const Node = struct {
29742716 base: Node = Node{ .id = .ErrorType },
29752717 token: TokenIndex,
29762718
2977 pub fn iterate(self: *const ErrorType) Node.Iterator {
2978 return .{ .parent_node = &self.base, .index = 0 };
2979 }
2980
2981 pub fn iterateNext(self: *const ErrorType, it: *Node.Iterator) ?*Node {
2719 pub fn iterate(self: *const ErrorType, index: usize) ?*Node {
29822720 return null;
29832721 }
29842722
......@@ -2995,11 +2733,7 @@ pub const Node = struct {
29952733 base: Node = Node{ .id = .VarType },
29962734 token: TokenIndex,
29972735
2998 pub fn iterate(self: *const VarType) Node.Iterator {
2999 return .{ .parent_node = &self.base, .index = 0 };
3000 }
3001
3002 pub fn iterateNext(self: *const VarType, it: *Node.Iterator) ?*Node {
2736 pub fn iterate(self: *const VarType, index: usize) ?*Node {
30032737 return null;
30042738 }
30052739
......@@ -3019,11 +2753,7 @@ pub const Node = struct {
30192753 /// at the first other token.
30202754 first_line: TokenIndex,
30212755
3022 pub fn iterate(self: *const DocComment) Node.Iterator {
3023 return .{ .parent_node = &self.base, .index = 0 };
3024 }
3025
3026 pub fn iterateNext(self: *const DocComment, it: *Node.Iterator) ?*Node {
2756 pub fn iterate(self: *const DocComment, index: usize) ?*Node {
30272757 return null;
30282758 }
30292759
......@@ -3045,13 +2775,8 @@ pub const Node = struct {
30452775 name: *Node,
30462776 body_node: *Node,
30472777
3048 pub fn iterate(self: *const TestDecl) Node.Iterator {
3049 return .{ .parent_node = &self.base, .index = 0 };
3050 }
3051
3052 pub fn iterateNext(self: *const TestDecl, it: *Node.Iterator) ?*Node {
3053 var i = it.index;
3054 it.index += 1;
2778 pub fn iterate(self: *const TestDecl, index: usize) ?*Node {
2779 var i = index;
30552780
30562781 if (i < 1) return self.body_node;
30572782 i -= 1;
......@@ -3076,6 +2801,5 @@ test "iterate" {
30762801 .eof_token = 0,
30772802 };
30782803 var base = &root.base;
3079 var it = base.iterate();
3080 testing.expect(it.next() == null);
2804 testing.expect(base.iterate(0) == null);
30812805}