authorgravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2023-01-09 14:59:19+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-01-09 16:59:19+02:00
log1f8f79cd53d2fbe96af7e7583fd3905c434f5543
tree122be3aedbd43b09cf69284a893ff9cd85638e98
parentfcee1bf9930ad48300863d1b85b1f0a7ee924fbc
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std: add helper functions to std.zig.Ast for extracting data out of nodes


5 files changed, 475 insertions(+), 789 deletions(-)

lib/std/zig/Ast.zig+205-72
......@@ -1243,7 +1243,7 @@ pub fn globalVarDecl(tree: Ast, node: Node.Index) full.VarDecl {
12431243 assert(tree.nodes.items(.tag)[node] == .global_var_decl);
12441244 const data = tree.nodes.items(.data)[node];
12451245 const extra = tree.extraData(data.lhs, Node.GlobalVarDecl);
1246 return tree.fullVarDecl(.{
1246 return tree.fullVarDeclComponents(.{
12471247 .type_node = extra.type_node,
12481248 .align_node = extra.align_node,
12491249 .addrspace_node = extra.addrspace_node,
......@@ -1257,7 +1257,7 @@ pub fn localVarDecl(tree: Ast, node: Node.Index) full.VarDecl {
12571257 assert(tree.nodes.items(.tag)[node] == .local_var_decl);
12581258 const data = tree.nodes.items(.data)[node];
12591259 const extra = tree.extraData(data.lhs, Node.LocalVarDecl);
1260 return tree.fullVarDecl(.{
1260 return tree.fullVarDeclComponents(.{
12611261 .type_node = extra.type_node,
12621262 .align_node = extra.align_node,
12631263 .addrspace_node = 0,
......@@ -1270,7 +1270,7 @@ pub fn localVarDecl(tree: Ast, node: Node.Index) full.VarDecl {
12701270pub fn simpleVarDecl(tree: Ast, node: Node.Index) full.VarDecl {
12711271 assert(tree.nodes.items(.tag)[node] == .simple_var_decl);
12721272 const data = tree.nodes.items(.data)[node];
1273 return tree.fullVarDecl(.{
1273 return tree.fullVarDeclComponents(.{
12741274 .type_node = data.lhs,
12751275 .align_node = 0,
12761276 .addrspace_node = 0,
......@@ -1283,7 +1283,7 @@ pub fn simpleVarDecl(tree: Ast, node: Node.Index) full.VarDecl {
12831283pub fn alignedVarDecl(tree: Ast, node: Node.Index) full.VarDecl {
12841284 assert(tree.nodes.items(.tag)[node] == .aligned_var_decl);
12851285 const data = tree.nodes.items(.data)[node];
1286 return tree.fullVarDecl(.{
1286 return tree.fullVarDeclComponents(.{
12871287 .type_node = 0,
12881288 .align_node = data.lhs,
12891289 .addrspace_node = 0,
......@@ -1296,7 +1296,7 @@ pub fn alignedVarDecl(tree: Ast, node: Node.Index) full.VarDecl {
12961296pub fn ifSimple(tree: Ast, node: Node.Index) full.If {
12971297 assert(tree.nodes.items(.tag)[node] == .if_simple);
12981298 const data = tree.nodes.items(.data)[node];
1299 return tree.fullIf(.{
1299 return tree.fullIfComponents(.{
13001300 .cond_expr = data.lhs,
13011301 .then_expr = data.rhs,
13021302 .else_expr = 0,
......@@ -1308,7 +1308,7 @@ pub fn ifFull(tree: Ast, node: Node.Index) full.If {
13081308 assert(tree.nodes.items(.tag)[node] == .@"if");
13091309 const data = tree.nodes.items(.data)[node];
13101310 const extra = tree.extraData(data.rhs, Node.If);
1311 return tree.fullIf(.{
1311 return tree.fullIfComponents(.{
13121312 .cond_expr = data.lhs,
13131313 .then_expr = extra.then_expr,
13141314 .else_expr = extra.else_expr,
......@@ -1321,7 +1321,7 @@ pub fn containerField(tree: Ast, node: Node.Index) full.ContainerField {
13211321 const data = tree.nodes.items(.data)[node];
13221322 const extra = tree.extraData(data.rhs, Node.ContainerField);
13231323 const main_token = tree.nodes.items(.main_token)[node];
1324 return tree.fullContainerField(.{
1324 return tree.fullContainerFieldComponents(.{
13251325 .main_token = main_token,
13261326 .type_expr = data.lhs,
13271327 .value_expr = extra.value_expr,
......@@ -1334,7 +1334,7 @@ pub fn containerFieldInit(tree: Ast, node: Node.Index) full.ContainerField {
13341334 assert(tree.nodes.items(.tag)[node] == .container_field_init);
13351335 const data = tree.nodes.items(.data)[node];
13361336 const main_token = tree.nodes.items(.main_token)[node];
1337 return tree.fullContainerField(.{
1337 return tree.fullContainerFieldComponents(.{
13381338 .main_token = main_token,
13391339 .type_expr = data.lhs,
13401340 .value_expr = data.rhs,
......@@ -1347,7 +1347,7 @@ pub fn containerFieldAlign(tree: Ast, node: Node.Index) full.ContainerField {
13471347 assert(tree.nodes.items(.tag)[node] == .container_field_align);
13481348 const data = tree.nodes.items(.data)[node];
13491349 const main_token = tree.nodes.items(.main_token)[node];
1350 return tree.fullContainerField(.{
1350 return tree.fullContainerFieldComponents(.{
13511351 .main_token = main_token,
13521352 .type_expr = data.lhs,
13531353 .value_expr = 0,
......@@ -1361,7 +1361,7 @@ pub fn fnProtoSimple(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.F
13611361 const data = tree.nodes.items(.data)[node];
13621362 buffer[0] = data.lhs;
13631363 const params = if (data.lhs == 0) buffer[0..0] else buffer[0..1];
1364 return tree.fullFnProto(.{
1364 return tree.fullFnProtoComponents(.{
13651365 .proto_node = node,
13661366 .fn_token = tree.nodes.items(.main_token)[node],
13671367 .return_type = data.rhs,
......@@ -1378,7 +1378,7 @@ pub fn fnProtoMulti(tree: Ast, node: Node.Index) full.FnProto {
13781378 const data = tree.nodes.items(.data)[node];
13791379 const params_range = tree.extraData(data.lhs, Node.SubRange);
13801380 const params = tree.extra_data[params_range.start..params_range.end];
1381 return tree.fullFnProto(.{
1381 return tree.fullFnProtoComponents(.{
13821382 .proto_node = node,
13831383 .fn_token = tree.nodes.items(.main_token)[node],
13841384 .return_type = data.rhs,
......@@ -1396,7 +1396,7 @@ pub fn fnProtoOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.FnPr
13961396 const extra = tree.extraData(data.lhs, Node.FnProtoOne);
13971397 buffer[0] = extra.param;
13981398 const params = if (extra.param == 0) buffer[0..0] else buffer[0..1];
1399 return tree.fullFnProto(.{
1399 return tree.fullFnProtoComponents(.{
14001400 .proto_node = node,
14011401 .fn_token = tree.nodes.items(.main_token)[node],
14021402 .return_type = data.rhs,
......@@ -1413,7 +1413,7 @@ pub fn fnProto(tree: Ast, node: Node.Index) full.FnProto {
14131413 const data = tree.nodes.items(.data)[node];
14141414 const extra = tree.extraData(data.lhs, Node.FnProto);
14151415 const params = tree.extra_data[extra.params_start..extra.params_end];
1416 return tree.fullFnProto(.{
1416 return tree.fullFnProtoComponents(.{
14171417 .proto_node = node,
14181418 .fn_token = tree.nodes.items(.main_token)[node],
14191419 .return_type = data.rhs,
......@@ -1431,11 +1431,13 @@ pub fn structInitOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.S
14311431 const data = tree.nodes.items(.data)[node];
14321432 buffer[0] = data.rhs;
14331433 const fields = if (data.rhs == 0) buffer[0..0] else buffer[0..1];
1434 return tree.fullStructInit(.{
1435 .lbrace = tree.nodes.items(.main_token)[node],
1436 .fields = fields,
1437 .type_expr = data.lhs,
1438 });
1434 return .{
1435 .ast = .{
1436 .lbrace = tree.nodes.items(.main_token)[node],
1437 .fields = fields,
1438 .type_expr = data.lhs,
1439 },
1440 };
14391441}
14401442
14411443pub fn structInitDotTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full.StructInit {
......@@ -1449,22 +1451,26 @@ pub fn structInitDotTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) ful
14491451 buffer[0..1]
14501452 else
14511453 buffer[0..0];
1452 return tree.fullStructInit(.{
1453 .lbrace = tree.nodes.items(.main_token)[node],
1454 .fields = fields,
1455 .type_expr = 0,
1456 });
1454 return .{
1455 .ast = .{
1456 .lbrace = tree.nodes.items(.main_token)[node],
1457 .fields = fields,
1458 .type_expr = 0,
1459 },
1460 };
14571461}
14581462
14591463pub fn structInitDot(tree: Ast, node: Node.Index) full.StructInit {
14601464 assert(tree.nodes.items(.tag)[node] == .struct_init_dot or
14611465 tree.nodes.items(.tag)[node] == .struct_init_dot_comma);
14621466 const data = tree.nodes.items(.data)[node];
1463 return tree.fullStructInit(.{
1464 .lbrace = tree.nodes.items(.main_token)[node],
1465 .fields = tree.extra_data[data.lhs..data.rhs],
1466 .type_expr = 0,
1467 });
1467 return .{
1468 .ast = .{
1469 .lbrace = tree.nodes.items(.main_token)[node],
1470 .fields = tree.extra_data[data.lhs..data.rhs],
1471 .type_expr = 0,
1472 },
1473 };
14681474}
14691475
14701476pub fn structInit(tree: Ast, node: Node.Index) full.StructInit {
......@@ -1472,11 +1478,13 @@ pub fn structInit(tree: Ast, node: Node.Index) full.StructInit {
14721478 tree.nodes.items(.tag)[node] == .struct_init_comma);
14731479 const data = tree.nodes.items(.data)[node];
14741480 const fields_range = tree.extraData(data.rhs, Node.SubRange);
1475 return tree.fullStructInit(.{
1476 .lbrace = tree.nodes.items(.main_token)[node],
1477 .fields = tree.extra_data[fields_range.start..fields_range.end],
1478 .type_expr = data.lhs,
1479 });
1481 return .{
1482 .ast = .{
1483 .lbrace = tree.nodes.items(.main_token)[node],
1484 .fields = tree.extra_data[fields_range.start..fields_range.end],
1485 .type_expr = data.lhs,
1486 },
1487 };
14801488}
14811489
14821490pub fn arrayInitOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.ArrayInit {
......@@ -1572,7 +1580,7 @@ pub fn arrayTypeSentinel(tree: Ast, node: Node.Index) full.ArrayType {
15721580pub fn ptrTypeAligned(tree: Ast, node: Node.Index) full.PtrType {
15731581 assert(tree.nodes.items(.tag)[node] == .ptr_type_aligned);
15741582 const data = tree.nodes.items(.data)[node];
1575 return tree.fullPtrType(.{
1583 return tree.fullPtrTypeComponents(.{
15761584 .main_token = tree.nodes.items(.main_token)[node],
15771585 .align_node = data.lhs,
15781586 .addrspace_node = 0,
......@@ -1586,7 +1594,7 @@ pub fn ptrTypeAligned(tree: Ast, node: Node.Index) full.PtrType {
15861594pub fn ptrTypeSentinel(tree: Ast, node: Node.Index) full.PtrType {
15871595 assert(tree.nodes.items(.tag)[node] == .ptr_type_sentinel);
15881596 const data = tree.nodes.items(.data)[node];
1589 return tree.fullPtrType(.{
1597 return tree.fullPtrTypeComponents(.{
15901598 .main_token = tree.nodes.items(.main_token)[node],
15911599 .align_node = 0,
15921600 .addrspace_node = 0,
......@@ -1601,7 +1609,7 @@ pub fn ptrType(tree: Ast, node: Node.Index) full.PtrType {
16011609 assert(tree.nodes.items(.tag)[node] == .ptr_type);
16021610 const data = tree.nodes.items(.data)[node];
16031611 const extra = tree.extraData(data.lhs, Node.PtrType);
1604 return tree.fullPtrType(.{
1612 return tree.fullPtrTypeComponents(.{
16051613 .main_token = tree.nodes.items(.main_token)[node],
16061614 .align_node = extra.align_node,
16071615 .addrspace_node = extra.addrspace_node,
......@@ -1616,7 +1624,7 @@ pub fn ptrTypeBitRange(tree: Ast, node: Node.Index) full.PtrType {
16161624 assert(tree.nodes.items(.tag)[node] == .ptr_type_bit_range);
16171625 const data = tree.nodes.items(.data)[node];
16181626 const extra = tree.extraData(data.lhs, Node.PtrTypeBitRange);
1619 return tree.fullPtrType(.{
1627 return tree.fullPtrTypeComponents(.{
16201628 .main_token = tree.nodes.items(.main_token)[node],
16211629 .align_node = extra.align_node,
16221630 .addrspace_node = extra.addrspace_node,
......@@ -1682,7 +1690,7 @@ pub fn containerDeclTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) ful
16821690 buffer[0..1]
16831691 else
16841692 buffer[0..0];
1685 return tree.fullContainerDecl(.{
1693 return tree.fullContainerDeclComponents(.{
16861694 .main_token = tree.nodes.items(.main_token)[node],
16871695 .enum_token = null,
16881696 .members = members,
......@@ -1694,7 +1702,7 @@ pub fn containerDecl(tree: Ast, node: Node.Index) full.ContainerDecl {
16941702 assert(tree.nodes.items(.tag)[node] == .container_decl or
16951703 tree.nodes.items(.tag)[node] == .container_decl_trailing);
16961704 const data = tree.nodes.items(.data)[node];
1697 return tree.fullContainerDecl(.{
1705 return tree.fullContainerDeclComponents(.{
16981706 .main_token = tree.nodes.items(.main_token)[node],
16991707 .enum_token = null,
17001708 .members = tree.extra_data[data.lhs..data.rhs],
......@@ -1707,7 +1715,7 @@ pub fn containerDeclArg(tree: Ast, node: Node.Index) full.ContainerDecl {
17071715 tree.nodes.items(.tag)[node] == .container_decl_arg_trailing);
17081716 const data = tree.nodes.items(.data)[node];
17091717 const members_range = tree.extraData(data.rhs, Node.SubRange);
1710 return tree.fullContainerDecl(.{
1718 return tree.fullContainerDeclComponents(.{
17111719 .main_token = tree.nodes.items(.main_token)[node],
17121720 .enum_token = null,
17131721 .members = tree.extra_data[members_range.start..members_range.end],
......@@ -1739,7 +1747,7 @@ pub fn taggedUnionTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full.
17391747 else
17401748 buffer[0..0];
17411749 const main_token = tree.nodes.items(.main_token)[node];
1742 return tree.fullContainerDecl(.{
1750 return tree.fullContainerDeclComponents(.{
17431751 .main_token = main_token,
17441752 .enum_token = main_token + 2, // union lparen enum
17451753 .members = members,
......@@ -1752,7 +1760,7 @@ pub fn taggedUnion(tree: Ast, node: Node.Index) full.ContainerDecl {
17521760 tree.nodes.items(.tag)[node] == .tagged_union_trailing);
17531761 const data = tree.nodes.items(.data)[node];
17541762 const main_token = tree.nodes.items(.main_token)[node];
1755 return tree.fullContainerDecl(.{
1763 return tree.fullContainerDeclComponents(.{
17561764 .main_token = main_token,
17571765 .enum_token = main_token + 2, // union lparen enum
17581766 .members = tree.extra_data[data.lhs..data.rhs],
......@@ -1766,7 +1774,7 @@ pub fn taggedUnionEnumTag(tree: Ast, node: Node.Index) full.ContainerDecl {
17661774 const data = tree.nodes.items(.data)[node];
17671775 const members_range = tree.extraData(data.rhs, Node.SubRange);
17681776 const main_token = tree.nodes.items(.main_token)[node];
1769 return tree.fullContainerDecl(.{
1777 return tree.fullContainerDeclComponents(.{
17701778 .main_token = main_token,
17711779 .enum_token = main_token + 2, // union lparen enum
17721780 .members = tree.extra_data[members_range.start..members_range.end],
......@@ -1777,7 +1785,7 @@ pub fn taggedUnionEnumTag(tree: Ast, node: Node.Index) full.ContainerDecl {
17771785pub fn switchCaseOne(tree: Ast, node: Node.Index) full.SwitchCase {
17781786 const data = &tree.nodes.items(.data)[node];
17791787 const values: *[1]Node.Index = &data.lhs;
1780 return tree.fullSwitchCase(.{
1788 return tree.fullSwitchCaseComponents(.{
17811789 .values = if (data.lhs == 0) values[0..0] else values[0..1],
17821790 .arrow_token = tree.nodes.items(.main_token)[node],
17831791 .target_expr = data.rhs,
......@@ -1787,7 +1795,7 @@ pub fn switchCaseOne(tree: Ast, node: Node.Index) full.SwitchCase {
17871795pub fn switchCase(tree: Ast, node: Node.Index) full.SwitchCase {
17881796 const data = tree.nodes.items(.data)[node];
17891797 const extra = tree.extraData(data.lhs, Node.SubRange);
1790 return tree.fullSwitchCase(.{
1798 return tree.fullSwitchCaseComponents(.{
17911799 .values = tree.extra_data[extra.start..extra.end],
17921800 .arrow_token = tree.nodes.items(.main_token)[node],
17931801 .target_expr = data.rhs,
......@@ -1796,7 +1804,7 @@ pub fn switchCase(tree: Ast, node: Node.Index) full.SwitchCase {
17961804
17971805pub fn asmSimple(tree: Ast, node: Node.Index) full.Asm {
17981806 const data = tree.nodes.items(.data)[node];
1799 return tree.fullAsm(.{
1807 return tree.fullAsmComponents(.{
18001808 .asm_token = tree.nodes.items(.main_token)[node],
18011809 .template = data.lhs,
18021810 .items = &.{},
......@@ -1807,7 +1815,7 @@ pub fn asmSimple(tree: Ast, node: Node.Index) full.Asm {
18071815pub fn asmFull(tree: Ast, node: Node.Index) full.Asm {
18081816 const data = tree.nodes.items(.data)[node];
18091817 const extra = tree.extraData(data.rhs, Node.Asm);
1810 return tree.fullAsm(.{
1818 return tree.fullAsmComponents(.{
18111819 .asm_token = tree.nodes.items(.main_token)[node],
18121820 .template = data.lhs,
18131821 .items = tree.extra_data[extra.items_start..extra.items_end],
......@@ -1817,7 +1825,7 @@ pub fn asmFull(tree: Ast, node: Node.Index) full.Asm {
18171825
18181826pub fn whileSimple(tree: Ast, node: Node.Index) full.While {
18191827 const data = tree.nodes.items(.data)[node];
1820 return tree.fullWhile(.{
1828 return tree.fullWhileComponents(.{
18211829 .while_token = tree.nodes.items(.main_token)[node],
18221830 .cond_expr = data.lhs,
18231831 .cont_expr = 0,
......@@ -1829,7 +1837,7 @@ pub fn whileSimple(tree: Ast, node: Node.Index) full.While {
18291837pub fn whileCont(tree: Ast, node: Node.Index) full.While {
18301838 const data = tree.nodes.items(.data)[node];
18311839 const extra = tree.extraData(data.rhs, Node.WhileCont);
1832 return tree.fullWhile(.{
1840 return tree.fullWhileComponents(.{
18331841 .while_token = tree.nodes.items(.main_token)[node],
18341842 .cond_expr = data.lhs,
18351843 .cont_expr = extra.cont_expr,
......@@ -1841,7 +1849,7 @@ pub fn whileCont(tree: Ast, node: Node.Index) full.While {
18411849pub fn whileFull(tree: Ast, node: Node.Index) full.While {
18421850 const data = tree.nodes.items(.data)[node];
18431851 const extra = tree.extraData(data.rhs, Node.While);
1844 return tree.fullWhile(.{
1852 return tree.fullWhileComponents(.{
18451853 .while_token = tree.nodes.items(.main_token)[node],
18461854 .cond_expr = data.lhs,
18471855 .cont_expr = extra.cont_expr,
......@@ -1852,7 +1860,7 @@ pub fn whileFull(tree: Ast, node: Node.Index) full.While {
18521860
18531861pub fn forSimple(tree: Ast, node: Node.Index) full.While {
18541862 const data = tree.nodes.items(.data)[node];
1855 return tree.fullWhile(.{
1863 return tree.fullWhileComponents(.{
18561864 .while_token = tree.nodes.items(.main_token)[node],
18571865 .cond_expr = data.lhs,
18581866 .cont_expr = 0,
......@@ -1864,7 +1872,7 @@ pub fn forSimple(tree: Ast, node: Node.Index) full.While {
18641872pub fn forFull(tree: Ast, node: Node.Index) full.While {
18651873 const data = tree.nodes.items(.data)[node];
18661874 const extra = tree.extraData(data.rhs, Node.If);
1867 return tree.fullWhile(.{
1875 return tree.fullWhileComponents(.{
18681876 .while_token = tree.nodes.items(.main_token)[node],
18691877 .cond_expr = data.lhs,
18701878 .cont_expr = 0,
......@@ -1877,7 +1885,7 @@ pub fn callOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.Call {
18771885 const data = tree.nodes.items(.data)[node];
18781886 buffer.* = .{data.rhs};
18791887 const params = if (data.rhs != 0) buffer[0..1] else buffer[0..0];
1880 return tree.fullCall(.{
1888 return tree.fullCallComponents(.{
18811889 .lparen = tree.nodes.items(.main_token)[node],
18821890 .fn_expr = data.lhs,
18831891 .params = params,
......@@ -1887,14 +1895,14 @@ pub fn callOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.Call {
18871895pub fn callFull(tree: Ast, node: Node.Index) full.Call {
18881896 const data = tree.nodes.items(.data)[node];
18891897 const extra = tree.extraData(data.rhs, Node.SubRange);
1890 return tree.fullCall(.{
1898 return tree.fullCallComponents(.{
18911899 .lparen = tree.nodes.items(.main_token)[node],
18921900 .fn_expr = data.lhs,
18931901 .params = tree.extra_data[extra.start..extra.end],
18941902 });
18951903}
18961904
1897fn fullVarDecl(tree: Ast, info: full.VarDecl.Components) full.VarDecl {
1905fn fullVarDeclComponents(tree: Ast, info: full.VarDecl.Components) full.VarDecl {
18981906 const token_tags = tree.tokens.items(.tag);
18991907 var result: full.VarDecl = .{
19001908 .ast = info,
......@@ -1919,7 +1927,7 @@ fn fullVarDecl(tree: Ast, info: full.VarDecl.Components) full.VarDecl {
19191927 return result;
19201928}
19211929
1922fn fullIf(tree: Ast, info: full.If.Components) full.If {
1930fn fullIfComponents(tree: Ast, info: full.If.Components) full.If {
19231931 const token_tags = tree.tokens.items(.tag);
19241932 var result: full.If = .{
19251933 .ast = info,
......@@ -1944,7 +1952,7 @@ fn fullIf(tree: Ast, info: full.If.Components) full.If {
19441952 return result;
19451953}
19461954
1947fn fullContainerField(tree: Ast, info: full.ContainerField.Components) full.ContainerField {
1955fn fullContainerFieldComponents(tree: Ast, info: full.ContainerField.Components) full.ContainerField {
19481956 const token_tags = tree.tokens.items(.tag);
19491957 var result: full.ContainerField = .{
19501958 .ast = info,
......@@ -1962,7 +1970,7 @@ fn fullContainerField(tree: Ast, info: full.ContainerField.Components) full.Cont
19621970 return result;
19631971}
19641972
1965fn fullFnProto(tree: Ast, info: full.FnProto.Components) full.FnProto {
1973fn fullFnProtoComponents(tree: Ast, info: full.FnProto.Components) full.FnProto {
19661974 const token_tags = tree.tokens.items(.tag);
19671975 var result: full.FnProto = .{
19681976 .ast = info,
......@@ -1998,15 +2006,7 @@ fn fullFnProto(tree: Ast, info: full.FnProto.Components) full.FnProto {
19982006 return result;
19992007}
20002008
2001fn fullStructInit(tree: Ast, info: full.StructInit.Components) full.StructInit {
2002 _ = tree;
2003 var result: full.StructInit = .{
2004 .ast = info,
2005 };
2006 return result;
2007}
2008
2009fn fullPtrType(tree: Ast, info: full.PtrType.Components) full.PtrType {
2009fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType {
20102010 const token_tags = tree.tokens.items(.tag);
20112011 const Size = std.builtin.Type.Pointer.Size;
20122012 const size: Size = switch (token_tags[info.main_token]) {
......@@ -2053,7 +2053,7 @@ fn fullPtrType(tree: Ast, info: full.PtrType.Components) full.PtrType {
20532053 return result;
20542054}
20552055
2056fn fullContainerDecl(tree: Ast, info: full.ContainerDecl.Components) full.ContainerDecl {
2056fn fullContainerDeclComponents(tree: Ast, info: full.ContainerDecl.Components) full.ContainerDecl {
20572057 const token_tags = tree.tokens.items(.tag);
20582058 var result: full.ContainerDecl = .{
20592059 .ast = info,
......@@ -2069,7 +2069,7 @@ fn fullContainerDecl(tree: Ast, info: full.ContainerDecl.Components) full.Contai
20692069 return result;
20702070}
20712071
2072fn fullSwitchCase(tree: Ast, info: full.SwitchCase.Components, node: Node.Index) full.SwitchCase {
2072fn fullSwitchCaseComponents(tree: Ast, info: full.SwitchCase.Components, node: Node.Index) full.SwitchCase {
20732073 const token_tags = tree.tokens.items(.tag);
20742074 const node_tags = tree.nodes.items(.tag);
20752075 var result: full.SwitchCase = .{
......@@ -2087,7 +2087,7 @@ fn fullSwitchCase(tree: Ast, info: full.SwitchCase.Components, node: Node.Index)
20872087 return result;
20882088}
20892089
2090fn fullAsm(tree: Ast, info: full.Asm.Components) full.Asm {
2090fn fullAsmComponents(tree: Ast, info: full.Asm.Components) full.Asm {
20912091 const token_tags = tree.tokens.items(.tag);
20922092 const node_tags = tree.nodes.items(.tag);
20932093 var result: full.Asm = .{
......@@ -2150,7 +2150,7 @@ fn fullAsm(tree: Ast, info: full.Asm.Components) full.Asm {
21502150 return result;
21512151}
21522152
2153fn fullWhile(tree: Ast, info: full.While.Components) full.While {
2153fn fullWhileComponents(tree: Ast, info: full.While.Components) full.While {
21542154 const token_tags = tree.tokens.items(.tag);
21552155 var result: full.While = .{
21562156 .ast = info,
......@@ -2185,7 +2185,7 @@ fn fullWhile(tree: Ast, info: full.While.Components) full.While {
21852185 return result;
21862186}
21872187
2188fn fullCall(tree: Ast, info: full.Call.Components) full.Call {
2188fn fullCallComponents(tree: Ast, info: full.Call.Components) full.Call {
21892189 const token_tags = tree.tokens.items(.tag);
21902190 var result: full.Call = .{
21912191 .ast = info,
......@@ -2198,6 +2198,139 @@ fn fullCall(tree: Ast, info: full.Call.Components) full.Call {
21982198 return result;
21992199}
22002200
2201pub fn fullVarDecl(tree: Ast, node: Node.Index) ?full.VarDecl {
2202 return switch (tree.nodes.items(.tag)[node]) {
2203 .global_var_decl => tree.globalVarDecl(node),
2204 .local_var_decl => tree.localVarDecl(node),
2205 .aligned_var_decl => tree.alignedVarDecl(node),
2206 .simple_var_decl => tree.simpleVarDecl(node),
2207 else => null,
2208 };
2209}
2210
2211pub fn fullIf(tree: Ast, node: Node.Index) ?full.If {
2212 return switch (tree.nodes.items(.tag)[node]) {
2213 .if_simple => tree.ifSimple(node),
2214 .@"if" => tree.ifFull(node),
2215 else => null,
2216 };
2217}
2218
2219pub fn fullWhile(tree: Ast, node: Node.Index) ?full.While {
2220 return switch (tree.nodes.items(.tag)[node]) {
2221 .while_simple => tree.whileSimple(node),
2222 .while_cont => tree.whileCont(node),
2223 .@"while" => tree.whileFull(node),
2224 .for_simple => tree.forSimple(node),
2225 .@"for" => tree.forFull(node),
2226 else => null,
2227 };
2228}
2229
2230pub fn fullContainerField(tree: Ast, node: Node.Index) ?full.ContainerField {
2231 return switch (tree.nodes.items(.tag)[node]) {
2232 .container_field_init => tree.containerFieldInit(node),
2233 .container_field_align => tree.containerFieldAlign(node),
2234 .container_field => tree.containerField(node),
2235 else => null,
2236 };
2237}
2238
2239pub fn fullFnProto(tree: Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.FnProto {
2240 return switch (tree.nodes.items(.tag)[node]) {
2241 .fn_proto => tree.fnProto(node),
2242 .fn_proto_multi => tree.fnProtoMulti(node),
2243 .fn_proto_one => tree.fnProtoOne(buffer, node),
2244 .fn_proto_simple => tree.fnProtoSimple(buffer, node),
2245 .fn_decl => tree.fullFnProto(buffer, tree.nodes.items(.data)[node].lhs),
2246 else => null,
2247 };
2248}
2249
2250pub fn fullStructInit(tree: Ast, buffer: *[2]Ast.Node.Index, node: Node.Index) ?full.StructInit {
2251 return switch (tree.nodes.items(.tag)[node]) {
2252 .struct_init_one, .struct_init_one_comma => tree.structInitOne(buffer[0..1], node),
2253 .struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(buffer, node),
2254 .struct_init_dot, .struct_init_dot_comma => tree.structInitDot(node),
2255 .struct_init, .struct_init_comma => tree.structInit(node),
2256 else => null,
2257 };
2258}
2259
2260pub fn fullArrayInit(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) ?full.ArrayInit {
2261 return switch (tree.nodes.items(.tag)[node]) {
2262 .array_init_one, .array_init_one_comma => tree.arrayInitOne(buffer[0..1], node),
2263 .array_init_dot_two, .array_init_dot_two_comma => tree.arrayInitDotTwo(buffer, node),
2264 .array_init_dot, .array_init_dot_comma => tree.arrayInitDot(node),
2265 .array_init, .array_init_comma => tree.arrayInit(node),
2266 else => null,
2267 };
2268}
2269
2270pub fn fullArrayType(tree: Ast, node: Node.Index) ?full.ArrayType {
2271 return switch (tree.nodes.items(.tag)[node]) {
2272 .array_type => tree.arrayType(node),
2273 .array_type_sentinel => tree.arrayTypeSentinel(node),
2274 else => null,
2275 };
2276}
2277
2278pub fn fullPtrType(tree: Ast, node: Node.Index) ?full.PtrType {
2279 return switch (tree.nodes.items(.tag)[node]) {
2280 .ptr_type_aligned => tree.ptrTypeAligned(node),
2281 .ptr_type_sentinel => tree.ptrTypeSentinel(node),
2282 .ptr_type => tree.ptrType(node),
2283 .ptr_type_bit_range => tree.ptrTypeBitRange(node),
2284 else => null,
2285 };
2286}
2287
2288pub fn fullSlice(tree: Ast, node: Node.Index) ?full.Slice {
2289 return switch (tree.nodes.items(.tag)[node]) {
2290 .slice_open => tree.sliceOpen(node),
2291 .slice => tree.slice(node),
2292 .slice_sentinel => tree.sliceSentinel(node),
2293 else => null,
2294 };
2295}
2296
2297pub fn fullContainerDecl(tree: Ast, buffer: *[2]Ast.Node.Index, node: Node.Index) ?full.ContainerDecl {
2298 return switch (tree.nodes.items(.tag)[node]) {
2299 .root => tree.containerDeclRoot(),
2300 .container_decl, .container_decl_trailing => tree.containerDecl(node),
2301 .container_decl_arg, .container_decl_arg_trailing => tree.containerDeclArg(node),
2302 .container_decl_two, .container_decl_two_trailing => tree.containerDeclTwo(buffer, node),
2303 .tagged_union, .tagged_union_trailing => tree.taggedUnion(node),
2304 .tagged_union_enum_tag, .tagged_union_enum_tag_trailing => tree.taggedUnionEnumTag(node),
2305 .tagged_union_two, .tagged_union_two_trailing => tree.taggedUnionTwo(buffer, node),
2306 else => null,
2307 };
2308}
2309
2310pub fn fullSwitchCase(tree: Ast, node: Node.Index) ?full.SwitchCase {
2311 return switch (tree.nodes.items(.tag)[node]) {
2312 .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(node),
2313 .switch_case, .switch_case_inline => tree.switchCase(node),
2314 else => null,
2315 };
2316}
2317
2318pub fn fullAsm(tree: Ast, node: Node.Index) ?full.Asm {
2319 return switch (tree.nodes.items(.tag)[node]) {
2320 .asm_simple => tree.asmSimple(node),
2321 .@"asm" => tree.asmFull(node),
2322 else => null,
2323 };
2324}
2325
2326pub fn fullCall(tree: Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.Call {
2327 return switch (tree.nodes.items(.tag)[node]) {
2328 .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node),
2329 .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(buffer, node),
2330 else => null,
2331 };
2332}
2333
22012334/// Fully assembled AST node information.
22022335pub const full = struct {
22032336 pub const VarDecl = struct {
lib/std/zig/render.zig+84-96
......@@ -42,13 +42,8 @@ fn renderMembers(gpa: Allocator, ais: *Ais, tree: Ast, members: []const Ast.Node
4242 if (members.len == 0) return;
4343 var is_tuple = true;
4444 for (members) |member| {
45 const tuple_like = switch (tree.nodes.items(.tag)[member]) {
46 .container_field_init => tree.containerFieldInit(member).ast.tuple_like,
47 .container_field_align => tree.containerFieldAlign(member).ast.tuple_like,
48 .container_field => tree.containerField(member).ast.tuple_like,
49 else => continue,
50 };
51 if (!tuple_like) {
45 const container_field = tree.fullContainerField(member) orelse continue;
46 if (!container_field.ast.tuple_like) {
5247 is_tuple = false;
5348 break;
5449 }
......@@ -164,10 +159,11 @@ fn renderMember(
164159 return renderToken(ais, tree, tree.lastToken(expr) + 1, space); // ;
165160 },
166161
167 .global_var_decl => return renderVarDecl(gpa, ais, tree, tree.globalVarDecl(decl)),
168 .local_var_decl => return renderVarDecl(gpa, ais, tree, tree.localVarDecl(decl)),
169 .simple_var_decl => return renderVarDecl(gpa, ais, tree, tree.simpleVarDecl(decl)),
170 .aligned_var_decl => return renderVarDecl(gpa, ais, tree, tree.alignedVarDecl(decl)),
162 .global_var_decl,
163 .local_var_decl,
164 .simple_var_decl,
165 .aligned_var_decl,
166 => return renderVarDecl(gpa, ais, tree, tree.fullVarDecl(decl).?),
171167
172168 .test_decl => {
173169 const test_token = main_tokens[decl];
......@@ -181,9 +177,11 @@ fn renderMember(
181177 try renderExpression(gpa, ais, tree, datas[decl].rhs, space);
182178 },
183179
184 .container_field_init => return renderContainerField(gpa, ais, tree, tree.containerFieldInit(decl), is_tuple, space),
185 .container_field_align => return renderContainerField(gpa, ais, tree, tree.containerFieldAlign(decl), is_tuple, space),
186 .container_field => return renderContainerField(gpa, ais, tree, tree.containerField(decl), is_tuple, space),
180 .container_field_init,
181 .container_field_align,
182 .container_field,
183 => return renderContainerField(gpa, ais, tree, tree.fullContainerField(decl).?, is_tuple, space),
184
187185 .@"comptime" => return renderExpression(gpa, ais, tree, decl, space),
188186
189187 .root => unreachable,
......@@ -437,54 +435,54 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index,
437435 return renderExpression(gpa, ais, tree, datas[node].lhs, space);
438436 },
439437
440 .array_type => return renderArrayType(gpa, ais, tree, tree.arrayType(node), space),
441 .array_type_sentinel => return renderArrayType(gpa, ais, tree, tree.arrayTypeSentinel(node), space),
438 .array_type,
439 .array_type_sentinel,
440 => return renderArrayType(gpa, ais, tree, tree.fullArrayType(node).?, space),
442441
443 .ptr_type_aligned => return renderPtrType(gpa, ais, tree, tree.ptrTypeAligned(node), space),
444 .ptr_type_sentinel => return renderPtrType(gpa, ais, tree, tree.ptrTypeSentinel(node), space),
445 .ptr_type => return renderPtrType(gpa, ais, tree, tree.ptrType(node), space),
446 .ptr_type_bit_range => return renderPtrType(gpa, ais, tree, tree.ptrTypeBitRange(node), space),
442 .ptr_type_aligned,
443 .ptr_type_sentinel,
444 .ptr_type,
445 .ptr_type_bit_range,
446 => return renderPtrType(gpa, ais, tree, tree.fullPtrType(node).?, space),
447447
448 .array_init_one, .array_init_one_comma => {
449 var elements: [1]Ast.Node.Index = undefined;
450 return renderArrayInit(gpa, ais, tree, tree.arrayInitOne(&elements, node), space);
451 },
452 .array_init_dot_two, .array_init_dot_two_comma => {
453 var elements: [2]Ast.Node.Index = undefined;
454 return renderArrayInit(gpa, ais, tree, tree.arrayInitDotTwo(&elements, node), space);
455 },
448 .array_init_one,
449 .array_init_one_comma,
450 .array_init_dot_two,
451 .array_init_dot_two_comma,
456452 .array_init_dot,
457453 .array_init_dot_comma,
458 => return renderArrayInit(gpa, ais, tree, tree.arrayInitDot(node), space),
459454 .array_init,
460455 .array_init_comma,
461 => return renderArrayInit(gpa, ais, tree, tree.arrayInit(node), space),
462
463 .struct_init_one, .struct_init_one_comma => {
464 var fields: [1]Ast.Node.Index = undefined;
465 return renderStructInit(gpa, ais, tree, node, tree.structInitOne(&fields, node), space);
466 },
467 .struct_init_dot_two, .struct_init_dot_two_comma => {
468 var fields: [2]Ast.Node.Index = undefined;
469 return renderStructInit(gpa, ais, tree, node, tree.structInitDotTwo(&fields, node), space);
456 => {
457 var elements: [2]Ast.Node.Index = undefined;
458 return renderArrayInit(gpa, ais, tree, tree.fullArrayInit(&elements, node).?, space);
470459 },
460
461 .struct_init_one,
462 .struct_init_one_comma,
463 .struct_init_dot_two,
464 .struct_init_dot_two_comma,
471465 .struct_init_dot,
472466 .struct_init_dot_comma,
473 => return renderStructInit(gpa, ais, tree, node, tree.structInitDot(node), space),
474467 .struct_init,
475468 .struct_init_comma,
476 => return renderStructInit(gpa, ais, tree, node, tree.structInit(node), space),
477
478 .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => {
479 var params: [1]Ast.Node.Index = undefined;
480 return renderCall(gpa, ais, tree, tree.callOne(&params, node), space);
469 => {
470 var buf: [2]Ast.Node.Index = undefined;
471 return renderStructInit(gpa, ais, tree, node, tree.fullStructInit(&buf, node).?, space);
481472 },
482473
474 .call_one,
475 .call_one_comma,
476 .async_call_one,
477 .async_call_one_comma,
483478 .call,
484479 .call_comma,
485480 .async_call,
486481 .async_call_comma,
487 => return renderCall(gpa, ais, tree, tree.callFull(node), space),
482 => {
483 var buf: [1]Ast.Node.Index = undefined;
484 return renderCall(gpa, ais, tree, tree.fullCall(&buf, node).?, space);
485 },
488486
489487 .array_access => {
490488 const suffix = datas[node];
......@@ -500,9 +498,7 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index,
500498 return renderToken(ais, tree, rbracket, space); // ]
501499 },
502500
503 .slice_open => return renderSlice(gpa, ais, tree, node, tree.sliceOpen(node), space),
504 .slice => return renderSlice(gpa, ais, tree, node, tree.slice(node), space),
505 .slice_sentinel => return renderSlice(gpa, ais, tree, node, tree.sliceSentinel(node), space),
501 .slice_open, .slice, .slice_sentinel => return renderSlice(gpa, ais, tree, node, tree.fullSlice(node).?, space),
506502
507503 .deref => {
508504 try renderExpression(gpa, ais, tree, datas[node].lhs, .none);
......@@ -566,27 +562,20 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index,
566562
567563 .container_decl,
568564 .container_decl_trailing,
569 => return renderContainerDecl(gpa, ais, tree, node, tree.containerDecl(node), space),
570
571 .container_decl_two, .container_decl_two_trailing => {
572 var buffer: [2]Ast.Node.Index = undefined;
573 return renderContainerDecl(gpa, ais, tree, node, tree.containerDeclTwo(&buffer, node), space);
574 },
575565 .container_decl_arg,
576566 .container_decl_arg_trailing,
577 => return renderContainerDecl(gpa, ais, tree, node, tree.containerDeclArg(node), space),
578
567 .container_decl_two,
568 .container_decl_two_trailing,
579569 .tagged_union,
580570 .tagged_union_trailing,
581 => return renderContainerDecl(gpa, ais, tree, node, tree.taggedUnion(node), space),
582
583 .tagged_union_two, .tagged_union_two_trailing => {
584 var buffer: [2]Ast.Node.Index = undefined;
585 return renderContainerDecl(gpa, ais, tree, node, tree.taggedUnionTwo(&buffer, node), space);
586 },
587571 .tagged_union_enum_tag,
588572 .tagged_union_enum_tag_trailing,
589 => return renderContainerDecl(gpa, ais, tree, node, tree.taggedUnionEnumTag(node), space),
573 .tagged_union_two,
574 .tagged_union_two_trailing,
575 => {
576 var buf: [2]Ast.Node.Index = undefined;
577 return renderContainerDecl(gpa, ais, tree, node, tree.fullContainerDecl(&buf, node).?, space);
578 },
590579
591580 .error_set_decl => {
592581 const error_token = main_tokens[node];
......@@ -651,16 +640,14 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index,
651640 return renderBuiltinCall(gpa, ais, tree, main_tokens[node], params, space);
652641 },
653642
654 .fn_proto_simple => {
655 var params: [1]Ast.Node.Index = undefined;
656 return renderFnProto(gpa, ais, tree, tree.fnProtoSimple(&params, node), space);
657 },
658 .fn_proto_multi => return renderFnProto(gpa, ais, tree, tree.fnProtoMulti(node), space),
659 .fn_proto_one => {
660 var params: [1]Ast.Node.Index = undefined;
661 return renderFnProto(gpa, ais, tree, tree.fnProtoOne(&params, node), space);
643 .fn_proto_simple,
644 .fn_proto_multi,
645 .fn_proto_one,
646 .fn_proto,
647 => {
648 var buf: [1]Ast.Node.Index = undefined;
649 return renderFnProto(gpa, ais, tree, tree.fullFnProto(&buf, node).?, space);
662650 },
663 .fn_proto => return renderFnProto(gpa, ais, tree, tree.fnProto(node), space),
664651
665652 .anyframe_type => {
666653 const main_token = main_tokens[node];
......@@ -698,20 +685,26 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index,
698685 return renderToken(ais, tree, tree.lastToken(node), space); // rbrace
699686 },
700687
701 .switch_case_one, .switch_case_inline_one => return renderSwitchCase(gpa, ais, tree, tree.switchCaseOne(node), space),
702 .switch_case, .switch_case_inline => return renderSwitchCase(gpa, ais, tree, tree.switchCase(node), space),
688 .switch_case_one,
689 .switch_case_inline_one,
690 .switch_case,
691 .switch_case_inline,
692 => return renderSwitchCase(gpa, ais, tree, tree.fullSwitchCase(node).?, space),
703693
704 .while_simple => return renderWhile(gpa, ais, tree, tree.whileSimple(node), space),
705 .while_cont => return renderWhile(gpa, ais, tree, tree.whileCont(node), space),
706 .@"while" => return renderWhile(gpa, ais, tree, tree.whileFull(node), space),
707 .for_simple => return renderWhile(gpa, ais, tree, tree.forSimple(node), space),
708 .@"for" => return renderWhile(gpa, ais, tree, tree.forFull(node), space),
694 .while_simple,
695 .while_cont,
696 .@"while",
697 .for_simple,
698 .@"for",
699 => return renderWhile(gpa, ais, tree, tree.fullWhile(node).?, space),
709700
710 .if_simple => return renderIf(gpa, ais, tree, tree.ifSimple(node), space),
711 .@"if" => return renderIf(gpa, ais, tree, tree.ifFull(node), space),
701 .if_simple,
702 .@"if",
703 => return renderIf(gpa, ais, tree, tree.fullIf(node).?, space),
712704
713 .asm_simple => return renderAsm(gpa, ais, tree, tree.asmSimple(node), space),
714 .@"asm" => return renderAsm(gpa, ais, tree, tree.asmFull(node), space),
705 .asm_simple,
706 .@"asm",
707 => return renderAsm(gpa, ais, tree, tree.fullAsm(node).?, space),
715708
716709 .enum_literal => {
717710 try renderToken(ais, tree, main_tokens[node] - 1, .none); // .
......@@ -1632,10 +1625,11 @@ fn renderBlock(
16321625 for (statements) |stmt, i| {
16331626 if (i != 0) try renderExtraNewline(ais, tree, stmt);
16341627 switch (node_tags[stmt]) {
1635 .global_var_decl => try renderVarDecl(gpa, ais, tree, tree.globalVarDecl(stmt)),
1636 .local_var_decl => try renderVarDecl(gpa, ais, tree, tree.localVarDecl(stmt)),
1637 .simple_var_decl => try renderVarDecl(gpa, ais, tree, tree.simpleVarDecl(stmt)),
1638 .aligned_var_decl => try renderVarDecl(gpa, ais, tree, tree.alignedVarDecl(stmt)),
1628 .global_var_decl,
1629 .local_var_decl,
1630 .simple_var_decl,
1631 .aligned_var_decl,
1632 => try renderVarDecl(gpa, ais, tree, tree.fullVarDecl(stmt).?),
16391633 else => try renderExpression(gpa, ais, tree, stmt, .semicolon),
16401634 }
16411635 }
......@@ -1938,7 +1932,6 @@ fn renderContainerDecl(
19381932 space: Space,
19391933) Error!void {
19401934 const token_tags = tree.tokens.items(.tag);
1941 const node_tags = tree.nodes.items(.tag);
19421935
19431936 if (container_decl.layout_token) |layout_token| {
19441937 try renderToken(ais, tree, layout_token, .space);
......@@ -1946,13 +1939,8 @@ fn renderContainerDecl(
19461939
19471940 var is_tuple = token_tags[container_decl.ast.main_token] == .keyword_struct;
19481941 if (is_tuple) for (container_decl.ast.members) |member| {
1949 const tuple_like = switch (tree.nodes.items(.tag)[member]) {
1950 .container_field_init => tree.containerFieldInit(member).ast.tuple_like,
1951 .container_field_align => tree.containerFieldAlign(member).ast.tuple_like,
1952 .container_field => tree.containerField(member).ast.tuple_like,
1953 else => continue,
1954 };
1955 if (!tuple_like) {
1942 const container_field = tree.fullContainerField(member) orelse continue;
1943 if (!container_field.ast.tuple_like) {
19561944 is_tuple = false;
19571945 break;
19581946 }
......@@ -2018,7 +2006,7 @@ fn renderContainerDecl(
20182006
20192007 // 4. The container has non-field members.
20202008 for (container_decl.ast.members) |member| {
2021 if (!node_tags[member].isContainerField()) break :one_line;
2009 if (tree.fullContainerField(member) == null) break :one_line;
20222010 }
20232011
20242012 // Print all the declarations on the same line.
src/AstGen.zig+104-194
......@@ -771,8 +771,9 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
771771
772772 .identifier => return identifier(gz, scope, ri, node),
773773
774 .asm_simple => return asmExpr(gz, scope, ri, node, tree.asmSimple(node)),
775 .@"asm" => return asmExpr(gz, scope, ri, node, tree.asmFull(node)),
774 .asm_simple,
775 .@"asm",
776 => return asmExpr(gz, scope, ri, node, tree.fullAsm(node).?),
776777
777778 .string_literal => return stringLiteral(gz, ri, node),
778779 .multiline_string_literal => return multilineStringLiteral(gz, ri, node),
......@@ -797,12 +798,17 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
797798 return builtinCall(gz, scope, ri, node, params);
798799 },
799800
800 .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => {
801 var params: [1]Ast.Node.Index = undefined;
802 return callExpr(gz, scope, ri, node, tree.callOne(&params, node));
803 },
804 .call, .call_comma, .async_call, .async_call_comma => {
805 return callExpr(gz, scope, ri, node, tree.callFull(node));
801 .call_one,
802 .call_one_comma,
803 .async_call_one,
804 .async_call_one_comma,
805 .call,
806 .call_comma,
807 .async_call,
808 .async_call_comma,
809 => {
810 var buf: [1]Ast.Node.Index = undefined;
811 return callExpr(gz, scope, ri, node, tree.fullCall(&buf, node).?);
806812 },
807813
808814 .unreachable_literal => {
......@@ -819,15 +825,16 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
819825 .@"return" => return ret(gz, scope, node),
820826 .field_access => return fieldAccess(gz, scope, ri, node),
821827
822 .if_simple => return ifExpr(gz, scope, ri.br(), node, tree.ifSimple(node)),
823 .@"if" => return ifExpr(gz, scope, ri.br(), node, tree.ifFull(node)),
828 .if_simple,
829 .@"if",
830 => return ifExpr(gz, scope, ri.br(), node, tree.fullIf(node).?),
824831
825 .while_simple => return whileExpr(gz, scope, ri.br(), node, tree.whileSimple(node), false),
826 .while_cont => return whileExpr(gz, scope, ri.br(), node, tree.whileCont(node), false),
827 .@"while" => return whileExpr(gz, scope, ri.br(), node, tree.whileFull(node), false),
832 .while_simple,
833 .while_cont,
834 .@"while",
835 => return whileExpr(gz, scope, ri.br(), node, tree.fullWhile(node).?, false),
828836
829 .for_simple => return forExpr(gz, scope, ri.br(), node, tree.forSimple(node), false),
830 .@"for" => return forExpr(gz, scope, ri.br(), node, tree.forFull(node), false),
837 .for_simple, .@"for" => return forExpr(gz, scope, ri.br(), node, tree.fullWhile(node).?, false),
831838
832839 .slice_open => {
833840 const lhs = try expr(gz, scope, .{ .rl = .ref }, node_datas[node].lhs);
......@@ -1012,32 +1019,28 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
10121019 ),
10131020 },
10141021
1015 .ptr_type_aligned => return ptrType(gz, scope, ri, node, tree.ptrTypeAligned(node)),
1016 .ptr_type_sentinel => return ptrType(gz, scope, ri, node, tree.ptrTypeSentinel(node)),
1017 .ptr_type => return ptrType(gz, scope, ri, node, tree.ptrType(node)),
1018 .ptr_type_bit_range => return ptrType(gz, scope, ri, node, tree.ptrTypeBitRange(node)),
1022 .ptr_type_aligned,
1023 .ptr_type_sentinel,
1024 .ptr_type,
1025 .ptr_type_bit_range,
1026 => return ptrType(gz, scope, ri, node, tree.fullPtrType(node).?),
10191027
10201028 .container_decl,
10211029 .container_decl_trailing,
1022 => return containerDecl(gz, scope, ri, node, tree.containerDecl(node)),
1023 .container_decl_two, .container_decl_two_trailing => {
1024 var buffer: [2]Ast.Node.Index = undefined;
1025 return containerDecl(gz, scope, ri, node, tree.containerDeclTwo(&buffer, node));
1026 },
10271030 .container_decl_arg,
10281031 .container_decl_arg_trailing,
1029 => return containerDecl(gz, scope, ri, node, tree.containerDeclArg(node)),
1030
1032 .container_decl_two,
1033 .container_decl_two_trailing,
10311034 .tagged_union,
10321035 .tagged_union_trailing,
1033 => return containerDecl(gz, scope, ri, node, tree.taggedUnion(node)),
1034 .tagged_union_two, .tagged_union_two_trailing => {
1035 var buffer: [2]Ast.Node.Index = undefined;
1036 return containerDecl(gz, scope, ri, node, tree.taggedUnionTwo(&buffer, node));
1037 },
10381036 .tagged_union_enum_tag,
10391037 .tagged_union_enum_tag_trailing,
1040 => return containerDecl(gz, scope, ri, node, tree.taggedUnionEnumTag(node)),
1038 .tagged_union_two,
1039 .tagged_union_two_trailing,
1040 => {
1041 var buf: [2]Ast.Node.Index = undefined;
1042 return containerDecl(gz, scope, ri, node, tree.fullContainerDecl(&buf, node).?);
1043 },
10411044
10421045 .@"break" => return breakExpr(gz, scope, node),
10431046 .@"continue" => return continueExpr(gz, scope, node),
......@@ -1057,49 +1060,39 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
10571060
10581061 .@"try" => return tryExpr(gz, scope, ri, node, node_datas[node].lhs),
10591062
1060 .array_init_one, .array_init_one_comma => {
1061 var elements: [1]Ast.Node.Index = undefined;
1062 return arrayInitExpr(gz, scope, ri, node, tree.arrayInitOne(&elements, node));
1063 },
1064 .array_init_dot_two, .array_init_dot_two_comma => {
1065 var elements: [2]Ast.Node.Index = undefined;
1066 return arrayInitExpr(gz, scope, ri, node, tree.arrayInitDotTwo(&elements, node));
1067 },
1063 .array_init_one,
1064 .array_init_one_comma,
1065 .array_init_dot_two,
1066 .array_init_dot_two_comma,
10681067 .array_init_dot,
10691068 .array_init_dot_comma,
1070 => return arrayInitExpr(gz, scope, ri, node, tree.arrayInitDot(node)),
10711069 .array_init,
10721070 .array_init_comma,
1073 => return arrayInitExpr(gz, scope, ri, node, tree.arrayInit(node)),
1074
1075 .struct_init_one, .struct_init_one_comma => {
1076 var fields: [1]Ast.Node.Index = undefined;
1077 return structInitExpr(gz, scope, ri, node, tree.structInitOne(&fields, node));
1078 },
1079 .struct_init_dot_two, .struct_init_dot_two_comma => {
1080 var fields: [2]Ast.Node.Index = undefined;
1081 return structInitExpr(gz, scope, ri, node, tree.structInitDotTwo(&fields, node));
1071 => {
1072 var buf: [2]Ast.Node.Index = undefined;
1073 return arrayInitExpr(gz, scope, ri, node, tree.fullArrayInit(&buf, node).?);
10821074 },
1075
1076 .struct_init_one,
1077 .struct_init_one_comma,
1078 .struct_init_dot_two,
1079 .struct_init_dot_two_comma,
10831080 .struct_init_dot,
10841081 .struct_init_dot_comma,
1085 => return structInitExpr(gz, scope, ri, node, tree.structInitDot(node)),
10861082 .struct_init,
10871083 .struct_init_comma,
1088 => return structInitExpr(gz, scope, ri, node, tree.structInit(node)),
1089
1090 .fn_proto_simple => {
1091 var params: [1]Ast.Node.Index = undefined;
1092 return fnProtoExpr(gz, scope, ri, node, tree.fnProtoSimple(&params, node));
1093 },
1094 .fn_proto_multi => {
1095 return fnProtoExpr(gz, scope, ri, node, tree.fnProtoMulti(node));
1096 },
1097 .fn_proto_one => {
1098 var params: [1]Ast.Node.Index = undefined;
1099 return fnProtoExpr(gz, scope, ri, node, tree.fnProtoOne(&params, node));
1084 => {
1085 var buf: [2]Ast.Node.Index = undefined;
1086 return structInitExpr(gz, scope, ri, node, tree.fullStructInit(&buf, node).?);
11001087 },
1101 .fn_proto => {
1102 return fnProtoExpr(gz, scope, ri, node, tree.fnProto(node));
1088
1089 .fn_proto_simple,
1090 .fn_proto_multi,
1091 .fn_proto_one,
1092 .fn_proto,
1093 => {
1094 var buf: [1]Ast.Node.Index = undefined;
1095 return fnProtoExpr(gz, scope, ri, node, tree.fullFnProto(&buf, node).?);
11031096 },
11041097 }
11051098}
......@@ -1374,11 +1367,7 @@ fn arrayInitExpr(
13741367 };
13751368
13761369 infer: {
1377 const array_type: Ast.full.ArrayType = switch (node_tags[array_init.ast.type_expr]) {
1378 .array_type => tree.arrayType(array_init.ast.type_expr),
1379 .array_type_sentinel => tree.arrayTypeSentinel(array_init.ast.type_expr),
1380 else => break :infer,
1381 };
1370 const array_type: Ast.full.ArrayType = tree.fullArrayType(array_init.ast.type_expr) orelse break :infer;
13821371 // This intentionally does not support `@"_"` syntax.
13831372 if (node_tags[array_type.ast.elem_count] == .identifier and
13841373 mem.eql(u8, tree.tokenSlice(main_tokens[array_type.ast.elem_count]), "_"))
......@@ -1606,17 +1595,13 @@ fn structInitExpr(
16061595 } else array: {
16071596 const node_tags = tree.nodes.items(.tag);
16081597 const main_tokens = tree.nodes.items(.main_token);
1609 const array_type: Ast.full.ArrayType = switch (node_tags[struct_init.ast.type_expr]) {
1610 .array_type => tree.arrayType(struct_init.ast.type_expr),
1611 .array_type_sentinel => tree.arrayTypeSentinel(struct_init.ast.type_expr),
1612 else => {
1613 if (struct_init.ast.fields.len == 0) {
1614 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
1615 const result = try gz.addUnNode(.struct_init_empty, ty_inst, node);
1616 return rvalue(gz, ri, result, node);
1617 }
1618 break :array;
1619 },
1598 const array_type: Ast.full.ArrayType = tree.fullArrayType(struct_init.ast.type_expr) orelse {
1599 if (struct_init.ast.fields.len == 0) {
1600 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
1601 const result = try gz.addUnNode(.struct_init_empty, ty_inst, node);
1602 return rvalue(gz, ri, result, node);
1603 }
1604 break :array;
16201605 };
16211606 const is_inferred_array_len = node_tags[array_type.ast.elem_count] == .identifier and
16221607 // This intentionally does not support `@"_"` syntax.
......@@ -2321,10 +2306,10 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod
23212306 while (true) {
23222307 switch (node_tags[inner_node]) {
23232308 // zig fmt: off
2324 .global_var_decl => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.globalVarDecl(statement)),
2325 .local_var_decl => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.localVarDecl(statement)),
2326 .simple_var_decl => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.simpleVarDecl(statement)),
2327 .aligned_var_decl => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.alignedVarDecl(statement)),
2309 .global_var_decl,
2310 .local_var_decl,
2311 .simple_var_decl,
2312 .aligned_var_decl, => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.fullVarDecl(statement).?),
23282313
23292314 .@"defer" => scope = try deferStmt(gz, scope, statement, block_arena_allocator, .defer_normal),
23302315 .@"errdefer" => scope = try deferStmt(gz, scope, statement, block_arena_allocator, .defer_error),
......@@ -2351,12 +2336,12 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod
23512336 continue;
23522337 },
23532338
2354 .while_simple => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.whileSimple(inner_node), true),
2355 .while_cont => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.whileCont(inner_node), true),
2356 .@"while" => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.whileFull(inner_node), true),
2339 .while_simple,
2340 .while_cont,
2341 .@"while", => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.fullWhile(inner_node).?, true),
23572342
2358 .for_simple => _ = try forExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.forSimple(inner_node), true),
2359 .@"for" => _ = try forExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.forFull(inner_node), true),
2343 .for_simple,
2344 .@"for", => _ = try forExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.fullWhile(inner_node).?, true),
23602345
23612346 else => noreturn_src_node = try unusedResultExpr(gz, scope, inner_node),
23622347 // zig fmt: on
......@@ -4491,12 +4476,8 @@ fn structDeclInner(
44914476 var is_tuple = false;
44924477 const node_tags = tree.nodes.items(.tag);
44934478 for (container_decl.ast.members) |member_node| {
4494 switch (node_tags[member_node]) {
4495 .container_field_init => is_tuple = tree.containerFieldInit(member_node).ast.tuple_like,
4496 .container_field_align => is_tuple = tree.containerFieldAlign(member_node).ast.tuple_like,
4497 .container_field => is_tuple = tree.containerField(member_node).ast.tuple_like,
4498 else => continue,
4499 }
4479 const container_field = tree.fullContainerField(member_node) orelse continue;
4480 is_tuple = container_field.ast.tuple_like;
45004481 if (is_tuple) break;
45014482 }
45024483 if (is_tuple) for (container_decl.ast.members) |member_node| {
......@@ -4802,7 +4783,6 @@ fn containerDecl(
48024783 const gpa = astgen.gpa;
48034784 const tree = astgen.tree;
48044785 const token_tags = tree.tokens.items(.tag);
4805 const node_tags = tree.nodes.items(.tag);
48064786
48074787 const prev_fn_block = astgen.fn_block;
48084788 astgen.fn_block = null;
......@@ -4844,14 +4824,9 @@ fn containerDecl(
48444824 var nonexhaustive_node: Ast.Node.Index = 0;
48454825 var nonfinal_nonexhaustive = false;
48464826 for (container_decl.ast.members) |member_node| {
4847 var member = switch (node_tags[member_node]) {
4848 .container_field_init => tree.containerFieldInit(member_node),
4849 .container_field_align => tree.containerFieldAlign(member_node),
4850 .container_field => tree.containerField(member_node),
4851 else => {
4852 decls += 1;
4853 continue;
4854 },
4827 var member = tree.fullContainerField(member_node) orelse {
4828 decls += 1;
4829 continue;
48554830 };
48564831 member.convertToNonTupleLike(astgen.tree.nodes);
48574832 if (member.ast.tuple_like) {
......@@ -5114,90 +5089,33 @@ fn containerMember(
51145089 const node_tags = tree.nodes.items(.tag);
51155090 const node_datas = tree.nodes.items(.data);
51165091 switch (node_tags[member_node]) {
5117 .container_field_init => return ContainerMemberResult{ .field = tree.containerFieldInit(member_node) },
5118 .container_field_align => return ContainerMemberResult{ .field = tree.containerFieldAlign(member_node) },
5119 .container_field => return ContainerMemberResult{ .field = tree.containerField(member_node) },
5120
5121 .fn_decl => {
5122 const fn_proto = node_datas[member_node].lhs;
5123 const body = node_datas[member_node].rhs;
5124 switch (node_tags[fn_proto]) {
5125 .fn_proto_simple => {
5126 var params: [1]Ast.Node.Index = undefined;
5127 astgen.fnDecl(gz, scope, wip_members, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) {
5128 error.OutOfMemory => return error.OutOfMemory,
5129 error.AnalysisFail => {},
5130 };
5131 },
5132 .fn_proto_multi => {
5133 astgen.fnDecl(gz, scope, wip_members, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) {
5134 error.OutOfMemory => return error.OutOfMemory,
5135 error.AnalysisFail => {},
5136 };
5137 },
5138 .fn_proto_one => {
5139 var params: [1]Ast.Node.Index = undefined;
5140 astgen.fnDecl(gz, scope, wip_members, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) {
5141 error.OutOfMemory => return error.OutOfMemory,
5142 error.AnalysisFail => {},
5143 };
5144 },
5145 .fn_proto => {
5146 astgen.fnDecl(gz, scope, wip_members, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) {
5147 error.OutOfMemory => return error.OutOfMemory,
5148 error.AnalysisFail => {},
5149 };
5150 },
5151 else => unreachable,
5152 }
5153 },
5154 .fn_proto_simple => {
5155 var params: [1]Ast.Node.Index = undefined;
5156 astgen.fnDecl(gz, scope, wip_members, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) {
5157 error.OutOfMemory => return error.OutOfMemory,
5158 error.AnalysisFail => {},
5159 };
5160 },
5161 .fn_proto_multi => {
5162 astgen.fnDecl(gz, scope, wip_members, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) {
5163 error.OutOfMemory => return error.OutOfMemory,
5164 error.AnalysisFail => {},
5165 };
5166 },
5167 .fn_proto_one => {
5168 var params: [1]Ast.Node.Index = undefined;
5169 astgen.fnDecl(gz, scope, wip_members, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) {
5170 error.OutOfMemory => return error.OutOfMemory,
5171 error.AnalysisFail => {},
5172 };
5173 },
5174 .fn_proto => {
5175 astgen.fnDecl(gz, scope, wip_members, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) {
5176 error.OutOfMemory => return error.OutOfMemory,
5177 error.AnalysisFail => {},
5178 };
5179 },
5092 .container_field_init,
5093 .container_field_align,
5094 .container_field,
5095 => return ContainerMemberResult{ .field = tree.fullContainerField(member_node).? },
51805096
5181 .global_var_decl => {
5182 astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) {
5183 error.OutOfMemory => return error.OutOfMemory,
5184 error.AnalysisFail => {},
5185 };
5186 },
5187 .local_var_decl => {
5188 astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) {
5189 error.OutOfMemory => return error.OutOfMemory,
5190 error.AnalysisFail => {},
5191 };
5192 },
5193 .simple_var_decl => {
5194 astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) {
5097 .fn_proto,
5098 .fn_proto_multi,
5099 .fn_proto_one,
5100 .fn_proto_simple,
5101 .fn_decl,
5102 => {
5103 var buf: [1]Ast.Node.Index = undefined;
5104 const full = tree.fullFnProto(&buf, member_node).?;
5105 const body = if (node_tags[member_node] == .fn_decl) node_datas[member_node].rhs else 0;
5106
5107 astgen.fnDecl(gz, scope, wip_members, member_node, body, full) catch |err| switch (err) {
51955108 error.OutOfMemory => return error.OutOfMemory,
51965109 error.AnalysisFail => {},
51975110 };
51985111 },
5199 .aligned_var_decl => {
5200 astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) {
5112
5113 .global_var_decl,
5114 .local_var_decl,
5115 .simple_var_decl,
5116 .aligned_var_decl,
5117 => {
5118 astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.fullVarDecl(member_node).?) catch |err| switch (err) {
52015119 error.OutOfMemory => return error.OutOfMemory,
52025120 error.AnalysisFail => {},
52035121 };
......@@ -6538,11 +6456,7 @@ fn switchExpr(
65386456 var else_src: ?Ast.TokenIndex = null;
65396457 var underscore_src: ?Ast.TokenIndex = null;
65406458 for (case_nodes) |case_node| {
6541 const case = switch (node_tags[case_node]) {
6542 .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
6543 .switch_case, .switch_case_inline => tree.switchCase(case_node),
6544 else => unreachable,
6545 };
6459 const case = tree.fullSwitchCase(case_node).?;
65466460 if (case.payload_token) |payload_token| {
65476461 if (token_tags[payload_token] == .asterisk) {
65486462 any_payload_is_ref = true;
......@@ -6689,11 +6603,7 @@ fn switchExpr(
66896603 var multi_case_index: u32 = 0;
66906604 var scalar_case_index: u32 = 0;
66916605 for (case_nodes) |case_node| {
6692 const case = switch (node_tags[case_node]) {
6693 .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
6694 .switch_case, .switch_case_inline => tree.switchCase(case_node),
6695 else => unreachable,
6696 };
6606 const case = tree.fullSwitchCase(case_node).?;
66976607
66986608 const is_multi_case = case.ast.values.len > 1 or
66996609 (case.ast.values.len == 1 and node_tags[case.ast.values[0]] == .switch_range);
src/Module.zig+80-404
......@@ -1040,34 +1040,13 @@ pub const Struct = struct {
10401040 return s.srcLoc(mod);
10411041 };
10421042 const node = owner_decl.relativeToNodeIndex(0);
1043 const node_tags = tree.nodes.items(.tag);
1044 switch (node_tags[node]) {
1045 .container_decl,
1046 .container_decl_trailing,
1047 => return queryFieldSrc(tree.*, query, file, tree.containerDecl(node)),
1048 .container_decl_two, .container_decl_two_trailing => {
1049 var buffer: [2]Ast.Node.Index = undefined;
1050 return queryFieldSrc(tree.*, query, file, tree.containerDeclTwo(&buffer, node));
1051 },
1052 .container_decl_arg,
1053 .container_decl_arg_trailing,
1054 => return queryFieldSrc(tree.*, query, file, tree.containerDeclArg(node)),
1055
1056 .tagged_union,
1057 .tagged_union_trailing,
1058 => return queryFieldSrc(tree.*, query, file, tree.taggedUnion(node)),
1059 .tagged_union_two, .tagged_union_two_trailing => {
1060 var buffer: [2]Ast.Node.Index = undefined;
1061 return queryFieldSrc(tree.*, query, file, tree.taggedUnionTwo(&buffer, node));
1062 },
1063 .tagged_union_enum_tag,
1064 .tagged_union_enum_tag_trailing,
1065 => return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
1066
1067 .root => return queryFieldSrc(tree.*, query, file, tree.containerDeclRoot()),
10681043
1044 var buf: [2]Ast.Node.Index = undefined;
1045 if (tree.fullContainerDecl(&buf, node)) |container_decl| {
1046 return queryFieldSrc(tree.*, query, file, container_decl);
1047 } else {
10691048 // This struct was generated using @Type
1070 else => return s.srcLoc(mod),
1049 return s.srcLoc(mod);
10711050 }
10721051 }
10731052
......@@ -1207,34 +1186,12 @@ pub const EnumFull = struct {
12071186 return e.srcLoc(mod);
12081187 };
12091188 const node = owner_decl.relativeToNodeIndex(0);
1210 const node_tags = tree.nodes.items(.tag);
1211 switch (node_tags[node]) {
1212 .container_decl,
1213 .container_decl_trailing,
1214 => return queryFieldSrc(tree.*, query, file, tree.containerDecl(node)),
1215 .container_decl_two, .container_decl_two_trailing => {
1216 var buffer: [2]Ast.Node.Index = undefined;
1217 return queryFieldSrc(tree.*, query, file, tree.containerDeclTwo(&buffer, node));
1218 },
1219 .container_decl_arg,
1220 .container_decl_arg_trailing,
1221 => return queryFieldSrc(tree.*, query, file, tree.containerDeclArg(node)),
1222
1223 .tagged_union,
1224 .tagged_union_trailing,
1225 => return queryFieldSrc(tree.*, query, file, tree.taggedUnion(node)),
1226 .tagged_union_two, .tagged_union_two_trailing => {
1227 var buffer: [2]Ast.Node.Index = undefined;
1228 return queryFieldSrc(tree.*, query, file, tree.taggedUnionTwo(&buffer, node));
1229 },
1230 .tagged_union_enum_tag,
1231 .tagged_union_enum_tag_trailing,
1232 => return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
1233
1234 .root => return queryFieldSrc(tree.*, query, file, tree.containerDeclRoot()),
1235
1236 // This struct was generated using @Type
1237 else => return e.srcLoc(mod),
1189 var buf: [2]Ast.Node.Index = undefined;
1190 if (tree.fullContainerDecl(&buf, node)) |container_decl| {
1191 return queryFieldSrc(tree.*, query, file, container_decl);
1192 } else {
1193 // This enum was generated using @Type
1194 return e.srcLoc(mod);
12381195 }
12391196 }
12401197};
......@@ -1315,30 +1272,13 @@ pub const Union = struct {
13151272 return u.srcLoc(mod);
13161273 };
13171274 const node = owner_decl.relativeToNodeIndex(0);
1318 const node_tags = tree.nodes.items(.tag);
1275
13191276 var buf: [2]Ast.Node.Index = undefined;
1320 switch (node_tags[node]) {
1321 .container_decl,
1322 .container_decl_trailing,
1323 => return queryFieldSrc(tree.*, query, file, tree.containerDecl(node)),
1324 .container_decl_two, .container_decl_two_trailing => {
1325 var buffer: [2]Ast.Node.Index = undefined;
1326 return queryFieldSrc(tree.*, query, file, tree.containerDeclTwo(&buffer, node));
1327 },
1328 .container_decl_arg,
1329 .container_decl_arg_trailing,
1330 => return queryFieldSrc(tree.*, query, file, tree.containerDeclArg(node)),
1331 .tagged_union,
1332 .tagged_union_trailing,
1333 => return queryFieldSrc(tree.*, query, file, tree.taggedUnion(node)),
1334 .tagged_union_two,
1335 .tagged_union_two_trailing,
1336 => return queryFieldSrc(tree.*, query, file, tree.taggedUnionTwo(&buf, node)),
1337 .tagged_union_enum_tag,
1338 .tagged_union_enum_tag_trailing,
1339 => return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
1277 if (tree.fullContainerDecl(&buf, node)) |container_decl| {
1278 return queryFieldSrc(tree.*, query, file, container_decl);
1279 } else {
13401280 // This union was generated using @Type
1341 else => return u.srcLoc(mod),
1281 return u.srcLoc(mod);
13421282 }
13431283 }
13441284
......@@ -2304,10 +2244,11 @@ pub const SrcLoc = struct {
23042244 const node = src_loc.declRelativeToNodeIndex(node_off);
23052245 const node_tags = tree.nodes.items(.tag);
23062246 const full = switch (node_tags[node]) {
2307 .global_var_decl => tree.globalVarDecl(node),
2308 .local_var_decl => tree.localVarDecl(node),
2309 .simple_var_decl => tree.simpleVarDecl(node),
2310 .aligned_var_decl => tree.alignedVarDecl(node),
2247 .global_var_decl,
2248 .local_var_decl,
2249 .simple_var_decl,
2250 .aligned_var_decl,
2251 => tree.fullVarDecl(node).?,
23112252 .@"usingnamespace" => {
23122253 const node_data = tree.nodes.items(.data);
23132254 return nodeToSpan(tree, node_data[node].lhs);
......@@ -2325,53 +2266,25 @@ pub const SrcLoc = struct {
23252266 .node_offset_var_decl_align => |node_off| {
23262267 const tree = try src_loc.file_scope.getTree(gpa);
23272268 const node = src_loc.declRelativeToNodeIndex(node_off);
2328 const node_tags = tree.nodes.items(.tag);
2329 const full: Ast.full.VarDecl = switch (node_tags[node]) {
2330 .global_var_decl => tree.globalVarDecl(node),
2331 .local_var_decl => tree.localVarDecl(node),
2332 .simple_var_decl => tree.simpleVarDecl(node),
2333 .aligned_var_decl => tree.alignedVarDecl(node),
2334 else => unreachable,
2335 };
2269 const full = tree.fullVarDecl(node).?;
23362270 return nodeToSpan(tree, full.ast.align_node);
23372271 },
23382272 .node_offset_var_decl_section => |node_off| {
23392273 const tree = try src_loc.file_scope.getTree(gpa);
23402274 const node = src_loc.declRelativeToNodeIndex(node_off);
2341 const node_tags = tree.nodes.items(.tag);
2342 const full: Ast.full.VarDecl = switch (node_tags[node]) {
2343 .global_var_decl => tree.globalVarDecl(node),
2344 .local_var_decl => tree.localVarDecl(node),
2345 .simple_var_decl => tree.simpleVarDecl(node),
2346 .aligned_var_decl => tree.alignedVarDecl(node),
2347 else => unreachable,
2348 };
2275 const full = tree.fullVarDecl(node).?;
23492276 return nodeToSpan(tree, full.ast.section_node);
23502277 },
23512278 .node_offset_var_decl_addrspace => |node_off| {
23522279 const tree = try src_loc.file_scope.getTree(gpa);
23532280 const node = src_loc.declRelativeToNodeIndex(node_off);
2354 const node_tags = tree.nodes.items(.tag);
2355 const full: Ast.full.VarDecl = switch (node_tags[node]) {
2356 .global_var_decl => tree.globalVarDecl(node),
2357 .local_var_decl => tree.localVarDecl(node),
2358 .simple_var_decl => tree.simpleVarDecl(node),
2359 .aligned_var_decl => tree.alignedVarDecl(node),
2360 else => unreachable,
2361 };
2281 const full = tree.fullVarDecl(node).?;
23622282 return nodeToSpan(tree, full.ast.addrspace_node);
23632283 },
23642284 .node_offset_var_decl_init => |node_off| {
23652285 const tree = try src_loc.file_scope.getTree(gpa);
23662286 const node = src_loc.declRelativeToNodeIndex(node_off);
2367 const node_tags = tree.nodes.items(.tag);
2368 const full: Ast.full.VarDecl = switch (node_tags[node]) {
2369 .global_var_decl => tree.globalVarDecl(node),
2370 .local_var_decl => tree.localVarDecl(node),
2371 .simple_var_decl => tree.simpleVarDecl(node),
2372 .aligned_var_decl => tree.alignedVarDecl(node),
2373 else => unreachable,
2374 };
2287 const full = tree.fullVarDecl(node).?;
23752288 return nodeToSpan(tree, full.ast.init_node);
23762289 },
23772290 .node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0),
......@@ -2392,14 +2305,8 @@ pub const SrcLoc = struct {
23922305 .node_offset_slice_sentinel,
23932306 => |node_off| {
23942307 const tree = try src_loc.file_scope.getTree(gpa);
2395 const node_tags = tree.nodes.items(.tag);
23962308 const node = src_loc.declRelativeToNodeIndex(node_off);
2397 const full = switch (node_tags[node]) {
2398 .slice_open => tree.sliceOpen(node),
2399 .slice => tree.slice(node),
2400 .slice_sentinel => tree.sliceSentinel(node),
2401 else => unreachable,
2402 };
2309 const full = tree.fullSlice(node).?;
24032310 const part_node = switch (src_loc.lazy) {
24042311 .node_offset_slice_ptr => full.ast.sliced,
24052312 .node_offset_slice_start => full.ast.start,
......@@ -2411,24 +2318,9 @@ pub const SrcLoc = struct {
24112318 },
24122319 .node_offset_call_func => |node_off| {
24132320 const tree = try src_loc.file_scope.getTree(gpa);
2414 const node_tags = tree.nodes.items(.tag);
24152321 const node = src_loc.declRelativeToNodeIndex(node_off);
2416 var params: [1]Ast.Node.Index = undefined;
2417 const full = switch (node_tags[node]) {
2418 .call_one,
2419 .call_one_comma,
2420 .async_call_one,
2421 .async_call_one_comma,
2422 => tree.callOne(&params, node),
2423
2424 .call,
2425 .call_comma,
2426 .async_call,
2427 .async_call_comma,
2428 => tree.callFull(node),
2429
2430 else => unreachable,
2431 };
2322 var buf: [1]Ast.Node.Index = undefined;
2323 const full = tree.fullCall(&buf, node).?;
24322324 return nodeToSpan(tree, full.ast.fn_expr);
24332325 },
24342326 .node_offset_field_name => |node_off| {
......@@ -2451,24 +2343,14 @@ pub const SrcLoc = struct {
24512343 },
24522344 .node_offset_asm_source => |node_off| {
24532345 const tree = try src_loc.file_scope.getTree(gpa);
2454 const node_tags = tree.nodes.items(.tag);
24552346 const node = src_loc.declRelativeToNodeIndex(node_off);
2456 const full = switch (node_tags[node]) {
2457 .asm_simple => tree.asmSimple(node),
2458 .@"asm" => tree.asmFull(node),
2459 else => unreachable,
2460 };
2347 const full = tree.fullAsm(node).?;
24612348 return nodeToSpan(tree, full.ast.template);
24622349 },
24632350 .node_offset_asm_ret_ty => |node_off| {
24642351 const tree = try src_loc.file_scope.getTree(gpa);
2465 const node_tags = tree.nodes.items(.tag);
24662352 const node = src_loc.declRelativeToNodeIndex(node_off);
2467 const full = switch (node_tags[node]) {
2468 .asm_simple => tree.asmSimple(node),
2469 .@"asm" => tree.asmFull(node),
2470 else => unreachable,
2471 };
2353 const full = tree.fullAsm(node).?;
24722354 const asm_output = full.outputs[0];
24732355 const node_datas = tree.nodes.items(.data);
24742356 return nodeToSpan(tree, node_datas[asm_output].lhs);
......@@ -2479,13 +2361,17 @@ pub const SrcLoc = struct {
24792361 const node = src_loc.declRelativeToNodeIndex(node_off);
24802362 const node_tags = tree.nodes.items(.tag);
24812363 const src_node = switch (node_tags[node]) {
2482 .if_simple => tree.ifSimple(node).ast.cond_expr,
2483 .@"if" => tree.ifFull(node).ast.cond_expr,
2484 .while_simple => tree.whileSimple(node).ast.cond_expr,
2485 .while_cont => tree.whileCont(node).ast.cond_expr,
2486 .@"while" => tree.whileFull(node).ast.cond_expr,
2487 .for_simple => tree.forSimple(node).ast.cond_expr,
2488 .@"for" => tree.forFull(node).ast.cond_expr,
2364 .if_simple,
2365 .@"if",
2366 => tree.fullIf(node).?.ast.cond_expr,
2367
2368 .while_simple,
2369 .while_cont,
2370 .@"while",
2371 .for_simple,
2372 .@"for",
2373 => tree.fullWhile(node).?.ast.cond_expr,
2374
24892375 .@"orelse" => node,
24902376 .@"catch" => node,
24912377 else => unreachable,
......@@ -2521,11 +2407,7 @@ pub const SrcLoc = struct {
25212407 const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
25222408 const case_nodes = tree.extra_data[extra.start..extra.end];
25232409 for (case_nodes) |case_node| {
2524 const case = switch (node_tags[case_node]) {
2525 .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
2526 .switch_case, .switch_case_inline => tree.switchCase(case_node),
2527 else => unreachable,
2528 };
2410 const case = tree.fullSwitchCase(case_node).?;
25292411 const is_special = (case.ast.values.len == 0) or
25302412 (case.ast.values.len == 1 and
25312413 node_tags[case.ast.values[0]] == .identifier and
......@@ -2545,11 +2427,7 @@ pub const SrcLoc = struct {
25452427 const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
25462428 const case_nodes = tree.extra_data[extra.start..extra.end];
25472429 for (case_nodes) |case_node| {
2548 const case = switch (node_tags[case_node]) {
2549 .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
2550 .switch_case, .switch_case_inline => tree.switchCase(case_node),
2551 else => unreachable,
2552 };
2430 const case = tree.fullSwitchCase(case_node).?;
25532431 const is_special = (case.ast.values.len == 0) or
25542432 (case.ast.values.len == 1 and
25552433 node_tags[case.ast.values[0]] == .identifier and
......@@ -2566,12 +2444,7 @@ pub const SrcLoc = struct {
25662444 .node_offset_switch_prong_capture => |node_off| {
25672445 const tree = try src_loc.file_scope.getTree(gpa);
25682446 const case_node = src_loc.declRelativeToNodeIndex(node_off);
2569 const node_tags = tree.nodes.items(.tag);
2570 const case = switch (node_tags[case_node]) {
2571 .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
2572 .switch_case, .switch_case_inline => tree.switchCase(case_node),
2573 else => unreachable,
2574 };
2447 const case = tree.fullSwitchCase(case_node).?;
25752448 const start_tok = case.payload_token.?;
25762449 const token_tags = tree.tokens.items(.tag);
25772450 const end_tok = switch (token_tags[start_tok]) {
......@@ -2585,116 +2458,38 @@ pub const SrcLoc = struct {
25852458 },
25862459 .node_offset_fn_type_align => |node_off| {
25872460 const tree = try src_loc.file_scope.getTree(gpa);
2588 const node_datas = tree.nodes.items(.data);
2589 const node_tags = tree.nodes.items(.tag);
25902461 const node = src_loc.declRelativeToNodeIndex(node_off);
2591 var params: [1]Ast.Node.Index = undefined;
2592 const full = switch (node_tags[node]) {
2593 .fn_proto_simple => tree.fnProtoSimple(&params, node),
2594 .fn_proto_multi => tree.fnProtoMulti(node),
2595 .fn_proto_one => tree.fnProtoOne(&params, node),
2596 .fn_proto => tree.fnProto(node),
2597 .fn_decl => switch (node_tags[node_datas[node].lhs]) {
2598 .fn_proto_simple => tree.fnProtoSimple(&params, node_datas[node].lhs),
2599 .fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
2600 .fn_proto_one => tree.fnProtoOne(&params, node_datas[node].lhs),
2601 .fn_proto => tree.fnProto(node_datas[node].lhs),
2602 else => unreachable,
2603 },
2604 else => unreachable,
2605 };
2462 var buf: [1]Ast.Node.Index = undefined;
2463 const full = tree.fullFnProto(&buf, node).?;
26062464 return nodeToSpan(tree, full.ast.align_expr);
26072465 },
26082466 .node_offset_fn_type_addrspace => |node_off| {
26092467 const tree = try src_loc.file_scope.getTree(gpa);
2610 const node_datas = tree.nodes.items(.data);
2611 const node_tags = tree.nodes.items(.tag);
26122468 const node = src_loc.declRelativeToNodeIndex(node_off);
2613 var params: [1]Ast.Node.Index = undefined;
2614 const full = switch (node_tags[node]) {
2615 .fn_proto_simple => tree.fnProtoSimple(&params, node),
2616 .fn_proto_multi => tree.fnProtoMulti(node),
2617 .fn_proto_one => tree.fnProtoOne(&params, node),
2618 .fn_proto => tree.fnProto(node),
2619 .fn_decl => switch (node_tags[node_datas[node].lhs]) {
2620 .fn_proto_simple => tree.fnProtoSimple(&params, node_datas[node].lhs),
2621 .fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
2622 .fn_proto_one => tree.fnProtoOne(&params, node_datas[node].lhs),
2623 .fn_proto => tree.fnProto(node_datas[node].lhs),
2624 else => unreachable,
2625 },
2626 else => unreachable,
2627 };
2469 var buf: [1]Ast.Node.Index = undefined;
2470 const full = tree.fullFnProto(&buf, node).?;
26282471 return nodeToSpan(tree, full.ast.addrspace_expr);
26292472 },
26302473 .node_offset_fn_type_section => |node_off| {
26312474 const tree = try src_loc.file_scope.getTree(gpa);
2632 const node_datas = tree.nodes.items(.data);
2633 const node_tags = tree.nodes.items(.tag);
26342475 const node = src_loc.declRelativeToNodeIndex(node_off);
2635 var params: [1]Ast.Node.Index = undefined;
2636 const full = switch (node_tags[node]) {
2637 .fn_proto_simple => tree.fnProtoSimple(&params, node),
2638 .fn_proto_multi => tree.fnProtoMulti(node),
2639 .fn_proto_one => tree.fnProtoOne(&params, node),
2640 .fn_proto => tree.fnProto(node),
2641 .fn_decl => switch (node_tags[node_datas[node].lhs]) {
2642 .fn_proto_simple => tree.fnProtoSimple(&params, node_datas[node].lhs),
2643 .fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
2644 .fn_proto_one => tree.fnProtoOne(&params, node_datas[node].lhs),
2645 .fn_proto => tree.fnProto(node_datas[node].lhs),
2646 else => unreachable,
2647 },
2648 else => unreachable,
2649 };
2476 var buf: [1]Ast.Node.Index = undefined;
2477 const full = tree.fullFnProto(&buf, node).?;
26502478 return nodeToSpan(tree, full.ast.section_expr);
26512479 },
26522480 .node_offset_fn_type_cc => |node_off| {
26532481 const tree = try src_loc.file_scope.getTree(gpa);
2654 const node_datas = tree.nodes.items(.data);
2655 const node_tags = tree.nodes.items(.tag);
26562482 const node = src_loc.declRelativeToNodeIndex(node_off);
2657 var params: [1]Ast.Node.Index = undefined;
2658 const full = switch (node_tags[node]) {
2659 .fn_proto_simple => tree.fnProtoSimple(&params, node),
2660 .fn_proto_multi => tree.fnProtoMulti(node),
2661 .fn_proto_one => tree.fnProtoOne(&params, node),
2662 .fn_proto => tree.fnProto(node),
2663 .fn_decl => switch (node_tags[node_datas[node].lhs]) {
2664 .fn_proto_simple => tree.fnProtoSimple(&params, node_datas[node].lhs),
2665 .fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
2666 .fn_proto_one => tree.fnProtoOne(&params, node_datas[node].lhs),
2667 .fn_proto => tree.fnProto(node_datas[node].lhs),
2668 else => unreachable,
2669 },
2670 else => unreachable,
2671 };
2483 var buf: [1]Ast.Node.Index = undefined;
2484 const full = tree.fullFnProto(&buf, node).?;
26722485 return nodeToSpan(tree, full.ast.callconv_expr);
26732486 },
26742487
26752488 .node_offset_fn_type_ret_ty => |node_off| {
26762489 const tree = try src_loc.file_scope.getTree(gpa);
2677 const node_datas = tree.nodes.items(.data);
2678 const node_tags = tree.nodes.items(.tag);
26792490 const node = src_loc.declRelativeToNodeIndex(node_off);
2680 var params: [1]Ast.Node.Index = undefined;
2681 const full = switch (node_tags[node]) {
2682 .fn_proto_simple => tree.fnProtoSimple(&params, node),
2683 .fn_proto_multi => tree.fnProtoMulti(node),
2684 .fn_proto_one => tree.fnProtoOne(&params, node),
2685 .fn_proto => tree.fnProto(node),
2686 .fn_decl => blk: {
2687 const fn_proto = node_datas[node].lhs;
2688 break :blk switch (node_tags[fn_proto]) {
2689 .fn_proto_simple => tree.fnProtoSimple(&params, fn_proto),
2690 .fn_proto_multi => tree.fnProtoMulti(fn_proto),
2691 .fn_proto_one => tree.fnProtoOne(&params, fn_proto),
2692 .fn_proto => tree.fnProto(fn_proto),
2693 else => unreachable,
2694 };
2695 },
2696 else => unreachable,
2697 };
2491 var buf: [1]Ast.Node.Index = undefined;
2492 const full = tree.fullFnProto(&buf, node).?;
26982493 return nodeToSpan(tree, full.ast.return_type);
26992494 },
27002495 .node_offset_param => |node_off| {
......@@ -2742,27 +2537,9 @@ pub const SrcLoc = struct {
27422537
27432538 .node_offset_lib_name => |node_off| {
27442539 const tree = try src_loc.file_scope.getTree(gpa);
2745 const node_datas = tree.nodes.items(.data);
2746 const node_tags = tree.nodes.items(.tag);
27472540 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
2748 var params: [1]Ast.Node.Index = undefined;
2749 const full = switch (node_tags[parent_node]) {
2750 .fn_proto_simple => tree.fnProtoSimple(&params, parent_node),
2751 .fn_proto_multi => tree.fnProtoMulti(parent_node),
2752 .fn_proto_one => tree.fnProtoOne(&params, parent_node),
2753 .fn_proto => tree.fnProto(parent_node),
2754 .fn_decl => blk: {
2755 const fn_proto = node_datas[parent_node].lhs;
2756 break :blk switch (node_tags[fn_proto]) {
2757 .fn_proto_simple => tree.fnProtoSimple(&params, fn_proto),
2758 .fn_proto_multi => tree.fnProtoMulti(fn_proto),
2759 .fn_proto_one => tree.fnProtoOne(&params, fn_proto),
2760 .fn_proto => tree.fnProto(fn_proto),
2761 else => unreachable,
2762 };
2763 },
2764 else => unreachable,
2765 };
2541 var buf: [1]Ast.Node.Index = undefined;
2542 const full = tree.fullFnProto(&buf, parent_node).?;
27662543 const tok_index = full.lib_name.?;
27672544 const start = tree.tokens.items(.start)[tok_index];
27682545 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);
......@@ -2771,38 +2548,23 @@ pub const SrcLoc = struct {
27712548
27722549 .node_offset_array_type_len => |node_off| {
27732550 const tree = try src_loc.file_scope.getTree(gpa);
2774 const node_tags = tree.nodes.items(.tag);
27752551 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
27762552
2777 const full: Ast.full.ArrayType = switch (node_tags[parent_node]) {
2778 .array_type => tree.arrayType(parent_node),
2779 .array_type_sentinel => tree.arrayTypeSentinel(parent_node),
2780 else => unreachable,
2781 };
2553 const full = tree.fullArrayType(parent_node).?;
27822554 return nodeToSpan(tree, full.ast.elem_count);
27832555 },
27842556 .node_offset_array_type_sentinel => |node_off| {
27852557 const tree = try src_loc.file_scope.getTree(gpa);
2786 const node_tags = tree.nodes.items(.tag);
27872558 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
27882559
2789 const full: Ast.full.ArrayType = switch (node_tags[parent_node]) {
2790 .array_type => tree.arrayType(parent_node),
2791 .array_type_sentinel => tree.arrayTypeSentinel(parent_node),
2792 else => unreachable,
2793 };
2560 const full = tree.fullArrayType(parent_node).?;
27942561 return nodeToSpan(tree, full.ast.sentinel);
27952562 },
27962563 .node_offset_array_type_elem => |node_off| {
27972564 const tree = try src_loc.file_scope.getTree(gpa);
2798 const node_tags = tree.nodes.items(.tag);
27992565 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
28002566
2801 const full: Ast.full.ArrayType = switch (node_tags[parent_node]) {
2802 .array_type => tree.arrayType(parent_node),
2803 .array_type_sentinel => tree.arrayTypeSentinel(parent_node),
2804 else => unreachable,
2805 };
2567 const full = tree.fullArrayType(parent_node).?;
28062568 return nodeToSpan(tree, full.ast.elem_type);
28072569 },
28082570 .node_offset_un_op => |node_off| {
......@@ -2814,86 +2576,44 @@ pub const SrcLoc = struct {
28142576 },
28152577 .node_offset_ptr_elem => |node_off| {
28162578 const tree = try src_loc.file_scope.getTree(gpa);
2817 const node_tags = tree.nodes.items(.tag);
28182579 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
28192580
2820 const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
2821 .ptr_type_aligned => tree.ptrTypeAligned(parent_node),
2822 .ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
2823 .ptr_type => tree.ptrType(parent_node),
2824 .ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
2825 else => unreachable,
2826 };
2581 const full = tree.fullPtrType(parent_node).?;
28272582 return nodeToSpan(tree, full.ast.child_type);
28282583 },
28292584 .node_offset_ptr_sentinel => |node_off| {
28302585 const tree = try src_loc.file_scope.getTree(gpa);
2831 const node_tags = tree.nodes.items(.tag);
28322586 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
28332587
2834 const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
2835 .ptr_type_aligned => tree.ptrTypeAligned(parent_node),
2836 .ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
2837 .ptr_type => tree.ptrType(parent_node),
2838 .ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
2839 else => unreachable,
2840 };
2588 const full = tree.fullPtrType(parent_node).?;
28412589 return nodeToSpan(tree, full.ast.sentinel);
28422590 },
28432591 .node_offset_ptr_align => |node_off| {
28442592 const tree = try src_loc.file_scope.getTree(gpa);
2845 const node_tags = tree.nodes.items(.tag);
28462593 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
28472594
2848 const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
2849 .ptr_type_aligned => tree.ptrTypeAligned(parent_node),
2850 .ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
2851 .ptr_type => tree.ptrType(parent_node),
2852 .ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
2853 else => unreachable,
2854 };
2595 const full = tree.fullPtrType(parent_node).?;
28552596 return nodeToSpan(tree, full.ast.align_node);
28562597 },
28572598 .node_offset_ptr_addrspace => |node_off| {
28582599 const tree = try src_loc.file_scope.getTree(gpa);
2859 const node_tags = tree.nodes.items(.tag);
28602600 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
28612601
2862 const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
2863 .ptr_type_aligned => tree.ptrTypeAligned(parent_node),
2864 .ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
2865 .ptr_type => tree.ptrType(parent_node),
2866 .ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
2867 else => unreachable,
2868 };
2602 const full = tree.fullPtrType(parent_node).?;
28692603 return nodeToSpan(tree, full.ast.addrspace_node);
28702604 },
28712605 .node_offset_ptr_bitoffset => |node_off| {
28722606 const tree = try src_loc.file_scope.getTree(gpa);
2873 const node_tags = tree.nodes.items(.tag);
28742607 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
28752608
2876 const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
2877 .ptr_type_aligned => tree.ptrTypeAligned(parent_node),
2878 .ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
2879 .ptr_type => tree.ptrType(parent_node),
2880 .ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
2881 else => unreachable,
2882 };
2609 const full = tree.fullPtrType(parent_node).?;
28832610 return nodeToSpan(tree, full.ast.bit_range_start);
28842611 },
28852612 .node_offset_ptr_hostsize => |node_off| {
28862613 const tree = try src_loc.file_scope.getTree(gpa);
2887 const node_tags = tree.nodes.items(.tag);
28882614 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
28892615
2890 const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
2891 .ptr_type_aligned => tree.ptrTypeAligned(parent_node),
2892 .ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
2893 .ptr_type => tree.ptrType(parent_node),
2894 .ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
2895 else => unreachable,
2896 };
2616 const full = tree.fullPtrType(parent_node).?;
28972617 return nodeToSpan(tree, full.ast.bit_range_end);
28982618 },
28992619 .node_offset_container_tag => |node_off| {
......@@ -2933,17 +2653,10 @@ pub const SrcLoc = struct {
29332653 },
29342654 .node_offset_init_ty => |node_off| {
29352655 const tree = try src_loc.file_scope.getTree(gpa);
2936 const node_tags = tree.nodes.items(.tag);
29372656 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
29382657
29392658 var buf: [2]Ast.Node.Index = undefined;
2940 const full: Ast.full.ArrayInit = switch (node_tags[parent_node]) {
2941 .array_init_one, .array_init_one_comma => tree.arrayInitOne(buf[0..1], parent_node),
2942 .array_init_dot_two, .array_init_dot_two_comma => tree.arrayInitDotTwo(&buf, parent_node),
2943 .array_init_dot, .array_init_dot_comma => tree.arrayInitDot(parent_node),
2944 .array_init, .array_init_comma => tree.arrayInit(parent_node),
2945 else => unreachable,
2946 };
2659 const full = tree.fullArrayInit(&buf, parent_node).?;
29472660 return nodeToSpan(tree, full.ast.type_expr);
29482661 },
29492662 .node_offset_store_ptr => |node_off| {
......@@ -6097,11 +5810,7 @@ pub const SwitchProngSrc = union(enum) {
60975810 var multi_i: u32 = 0;
60985811 var scalar_i: u32 = 0;
60995812 for (case_nodes) |case_node| {
6100 const case = switch (node_tags[case_node]) {
6101 .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
6102 .switch_case, .switch_case_inline => tree.switchCase(case_node),
6103 else => unreachable,
6104 };
5813 const case = tree.fullSwitchCase(case_node).?;
61055814 if (case.ast.values.len == 0)
61065815 continue;
61075816 if (case.ast.values.len == 1 and
......@@ -6223,15 +5932,9 @@ fn queryFieldSrc(
62235932 file_scope: *File,
62245933 container_decl: Ast.full.ContainerDecl,
62255934) SrcLoc {
6226 const node_tags = tree.nodes.items(.tag);
62275935 var field_index: usize = 0;
62285936 for (container_decl.ast.members) |member_node| {
6229 const field = switch (node_tags[member_node]) {
6230 .container_field_init => tree.containerFieldInit(member_node),
6231 .container_field_align => tree.containerFieldAlign(member_node),
6232 .container_field => tree.containerField(member_node),
6233 else => continue,
6234 };
5937 const field = tree.fullContainerField(member_node) orelse continue;
62355938 if (field_index == query.index) {
62365939 return switch (query.range) {
62375940 .name => .{
......@@ -6275,24 +5978,9 @@ pub fn paramSrc(
62755978 });
62765979 return LazySrcLoc.nodeOffset(0);
62775980 };
6278 const node_datas = tree.nodes.items(.data);
6279 const node_tags = tree.nodes.items(.tag);
62805981 const node = decl.relativeToNodeIndex(func_node_offset);
6281 var params: [1]Ast.Node.Index = undefined;
6282 const full = switch (node_tags[node]) {
6283 .fn_proto_simple => tree.fnProtoSimple(&params, node),
6284 .fn_proto_multi => tree.fnProtoMulti(node),
6285 .fn_proto_one => tree.fnProtoOne(&params, node),
6286 .fn_proto => tree.fnProto(node),
6287 .fn_decl => switch (node_tags[node_datas[node].lhs]) {
6288 .fn_proto_simple => tree.fnProtoSimple(&params, node_datas[node].lhs),
6289 .fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
6290 .fn_proto_one => tree.fnProtoOne(&params, node_datas[node].lhs),
6291 .fn_proto => tree.fnProto(node_datas[node].lhs),
6292 else => unreachable,
6293 },
6294 else => unreachable,
6295 };
5982 var buf: [1]Ast.Node.Index = undefined;
5983 const full = tree.fullFnProto(&buf, node).?;
62965984 var it = full.iterate(tree);
62975985 var i: usize = 0;
62985986 while (it.next()) |param| : (i += 1) {
......@@ -6358,18 +6046,6 @@ pub fn initSrc(
63586046 const node_tags = tree.nodes.items(.tag);
63596047 const node = decl.relativeToNodeIndex(init_node_offset);
63606048 var buf: [2]Ast.Node.Index = undefined;
6361 const full = switch (node_tags[node]) {
6362 .array_init_one, .array_init_one_comma => tree.arrayInitOne(buf[0..1], node).ast.elements,
6363 .array_init_dot_two, .array_init_dot_two_comma => tree.arrayInitDotTwo(&buf, node).ast.elements,
6364 .array_init_dot, .array_init_dot_comma => tree.arrayInitDot(node).ast.elements,
6365 .array_init, .array_init_comma => tree.arrayInit(node).ast.elements,
6366
6367 .struct_init_one, .struct_init_one_comma => tree.structInitOne(buf[0..1], node).ast.fields,
6368 .struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(&buf, node).ast.fields,
6369 .struct_init_dot, .struct_init_dot_comma => tree.structInitDot(node).ast.fields,
6370 .struct_init, .struct_init_comma => tree.structInit(node).ast.fields,
6371 else => return LazySrcLoc.nodeOffset(init_node_offset),
6372 };
63736049 switch (node_tags[node]) {
63746050 .array_init_one,
63756051 .array_init_one_comma,
......@@ -6379,7 +6055,10 @@ pub fn initSrc(
63796055 .array_init_dot_comma,
63806056 .array_init,
63816057 .array_init_comma,
6382 => return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full[init_index])),
6058 => {
6059 const full = tree.fullArrayInit(&buf, node).?.ast.elements;
6060 return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full[init_index]));
6061 },
63836062 .struct_init_one,
63846063 .struct_init_one_comma,
63856064 .struct_init_dot_two,
......@@ -6388,8 +6067,11 @@ pub fn initSrc(
63886067 .struct_init_dot_comma,
63896068 .struct_init,
63906069 .struct_init_comma,
6391 => return LazySrcLoc{ .node_offset_initializer = decl.nodeIndexToRelative(full[init_index]) },
6392 else => unreachable,
6070 => {
6071 const full = tree.fullStructInit(&buf, node).?.ast.fields;
6072 return LazySrcLoc{ .node_offset_initializer = decl.nodeIndexToRelative(full[init_index]) };
6073 },
6074 else => return LazySrcLoc.nodeOffset(init_node_offset),
63936075 }
63946076}
63956077
......@@ -6422,13 +6104,7 @@ pub fn optionsSrc(gpa: Allocator, decl: *Decl, base_src: LazySrcLoc, wanted: []c
64226104 else => unreachable,
64236105 };
64246106 var buf: [2]std.zig.Ast.Node.Index = undefined;
6425 const init_nodes = switch (node_tags[arg_node]) {
6426 .struct_init_one, .struct_init_one_comma => tree.structInitOne(buf[0..1], arg_node).ast.fields,
6427 .struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(&buf, arg_node).ast.fields,
6428 .struct_init_dot, .struct_init_dot_comma => tree.structInitDot(arg_node).ast.fields,
6429 .struct_init, .struct_init_comma => tree.structInit(arg_node).ast.fields,
6430 else => return base_src,
6431 };
6107 const init_nodes = if (tree.fullStructInit(&buf, arg_node)) |struct_init| struct_init.ast.fields else return base_src;
64326108 for (init_nodes) |init_node| {
64336109 // . IDENTIFIER = init_node
64346110 const name_token = tree.firstToken(init_node) - 2;
src/Sema.zig+2-23
......@@ -2150,29 +2150,8 @@ fn addFieldErrNote(
21502150
21512151 const container_node = decl.relativeToNodeIndex(0);
21522152 const node_tags = tree.nodes.items(.tag);
2153 var buffer: [2]std.zig.Ast.Node.Index = undefined;
2154 const container_decl = switch (node_tags[container_node]) {
2155 .root => tree.containerDeclRoot(),
2156 .container_decl,
2157 .container_decl_trailing,
2158 => tree.containerDecl(container_node),
2159 .container_decl_two,
2160 .container_decl_two_trailing,
2161 => tree.containerDeclTwo(&buffer, container_node),
2162 .container_decl_arg,
2163 .container_decl_arg_trailing,
2164 => tree.containerDeclArg(container_node),
2165 .tagged_union,
2166 .tagged_union_trailing,
2167 => tree.taggedUnion(container_node),
2168 .tagged_union_two,
2169 .tagged_union_two_trailing,
2170 => tree.taggedUnionTwo(&buffer, container_node),
2171 .tagged_union_enum_tag,
2172 .tagged_union_enum_tag_trailing,
2173 => tree.taggedUnionEnumTag(container_node),
2174 else => break :blk decl.srcLoc(),
2175 };
2153 var buf: [2]std.zig.Ast.Node.Index = undefined;
2154 const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc();
21762155
21772156 var it_index: usize = 0;
21782157 for (container_decl.ast.members) |member_node| {