| author | |
| committer | |
| log | 1884ad0ea37fcb01f763987a930715ba6ab737c7 |
| tree | 9107e949916a914016777822c73dca67d95c7346 |
| parent | 8e72a25285b5e782ee44828b6d1904d91fb16a29 |
12 files changed, 803 insertions(+), 802 deletions(-)
lib/std/zig/Ast.zig+364-364| ... | @@ -83,18 +83,6 @@ pub fn tokenStart(tree: *const Ast, token_index: TokenIndex) ByteOffset { | ... | @@ -83,18 +83,6 @@ pub fn tokenStart(tree: *const Ast, token_index: TokenIndex) ByteOffset { |
| 83 | return tree.tokens.items(.start)[token_index]; | 83 | return tree.tokens.items(.start)[token_index]; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | pub fn nodeTag(tree: *const Ast, node: Node.Index) Node.Tag { | ||
| 87 | return tree.nodes.items(.tag)[@intFromEnum(node)]; | ||
| 88 | } | ||
| 89 | |||
| 90 | pub fn nodeMainToken(tree: *const Ast, node: Node.Index) TokenIndex { | ||
| 91 | return tree.nodes.items(.main_token)[@intFromEnum(node)]; | ||
| 92 | } | ||
| 93 | |||
| 94 | pub fn nodeData(tree: *const Ast, node: Node.Index) Node.Data { | ||
| 95 | return tree.nodes.items(.data)[@intFromEnum(node)]; | ||
| 96 | } | ||
| 97 | |||
| 98 | pub fn isTokenPrecededByTags( | 86 | pub fn isTokenPrecededByTags( |
| 99 | tree: *const Ast, | 87 | tree: *const Ast, |
| 100 | ti: TokenIndex, | 88 | ti: TokenIndex, |
| ... | @@ -199,7 +187,7 @@ pub fn parse(gpa: Allocator, source: [:0]const u8, mode: Mode) Allocator.Error!A | ... | @@ -199,7 +187,7 @@ pub fn parse(gpa: Allocator, source: [:0]const u8, mode: Mode) Allocator.Error!A |
| 199 | 187 | ||
| 200 | /// `gpa` is used for allocating the resulting formatted source code. | 188 | /// `gpa` is used for allocating the resulting formatted source code. |
| 201 | /// Caller owns the returned slice of bytes, allocated with `gpa`. | 189 | /// Caller owns the returned slice of bytes, allocated with `gpa`. |
| 202 | pub fn render(tree: Ast, gpa: Allocator) RenderError![]u8 { | 190 | pub fn render(tree: *const Ast, gpa: Allocator) RenderError![]u8 { |
| 203 | var buffer = std.ArrayList(u8).init(gpa); | 191 | var buffer = std.ArrayList(u8).init(gpa); |
| 204 | defer buffer.deinit(); | 192 | defer buffer.deinit(); |
| 205 | 193 | ||
| ... | @@ -209,20 +197,20 @@ pub fn render(tree: Ast, gpa: Allocator) RenderError![]u8 { | ... | @@ -209,20 +197,20 @@ pub fn render(tree: Ast, gpa: Allocator) RenderError![]u8 { |
| 209 | 197 | ||
| 210 | pub const Fixups = private_render.Fixups; | 198 | pub const Fixups = private_render.Fixups; |
| 211 | 199 | ||
| 212 | pub fn renderToArrayList(tree: Ast, buffer: *std.ArrayList(u8), fixups: Fixups) RenderError!void { | 200 | pub fn renderToArrayList(tree: *const Ast, buffer: *std.ArrayList(u8), fixups: Fixups) RenderError!void { |
| 213 | return @import("./render.zig").renderTree(buffer, tree, fixups); | 201 | return @import("./render.zig").renderTree(buffer, tree, fixups); |
| 214 | } | 202 | } |
| 215 | 203 | ||
| 216 | /// Returns an extra offset for column and byte offset of errors that | 204 | /// Returns an extra offset for column and byte offset of errors that |
| 217 | /// should point after the token in the error message. | 205 | /// should point after the token in the error message. |
| 218 | pub fn errorOffset(tree: Ast, parse_error: Error) u32 { | 206 | pub fn errorOffset(tree: *const Ast, parse_error: Error) u32 { |
| 219 | return if (parse_error.token_is_prev) | 207 | return if (parse_error.token_is_prev) |
| 220 | @as(u32, @intCast(tree.tokenSlice(parse_error.token).len)) | 208 | @as(u32, @intCast(tree.tokenSlice(parse_error.token).len)) |
| 221 | else | 209 | else |
| 222 | 0; | 210 | 0; |
| 223 | } | 211 | } |
| 224 | 212 | ||
| 225 | pub fn tokenLocation(self: Ast, start_offset: ByteOffset, token_index: TokenIndex) Location { | 213 | pub fn tokenLocation(self: *const Ast, start_offset: ByteOffset, token_index: TokenIndex) Location { |
| 226 | var loc = Location{ | 214 | var loc = Location{ |
| 227 | .line = 0, | 215 | .line = 0, |
| 228 | .column = 0, | 216 | .column = 0, |
| ... | @@ -260,7 +248,7 @@ pub fn tokenLocation(self: Ast, start_offset: ByteOffset, token_index: TokenInde | ... | @@ -260,7 +248,7 @@ pub fn tokenLocation(self: Ast, start_offset: ByteOffset, token_index: TokenInde |
| 260 | return loc; | 248 | return loc; |
| 261 | } | 249 | } |
| 262 | 250 | ||
| 263 | pub fn tokenSlice(tree: Ast, token_index: TokenIndex) []const u8 { | 251 | pub fn tokenSlice(tree: *const Ast, token_index: TokenIndex) []const u8 { |
| 264 | const token_tag = tree.tokenTag(token_index); | 252 | const token_tag = tree.tokenTag(token_index); |
| 265 | 253 | ||
| 266 | // Many tokens can be determined entirely by their tag. | 254 | // Many tokens can be determined entirely by their tag. |
| ... | @@ -278,15 +266,15 @@ pub fn tokenSlice(tree: Ast, token_index: TokenIndex) []const u8 { | ... | @@ -278,15 +266,15 @@ pub fn tokenSlice(tree: Ast, token_index: TokenIndex) []const u8 { |
| 278 | return tree.source[token.loc.start..token.loc.end]; | 266 | return tree.source[token.loc.start..token.loc.end]; |
| 279 | } | 267 | } |
| 280 | 268 | ||
| 281 | pub fn extraDataSlice(tree: Ast, range: Node.SubRange, comptime T: type) []const T { | 269 | pub fn extraDataSlice(tree: *const Ast, range: Node.SubRange, comptime T: type) []const T { |
| 282 | return @ptrCast(tree.extra_data[@intFromEnum(range.start)..@intFromEnum(range.end)]); | 270 | return @ptrCast(tree.extra_data[@intFromEnum(range.start)..@intFromEnum(range.end)]); |
| 283 | } | 271 | } |
| 284 | 272 | ||
| 285 | pub fn extraDataSliceWithLen(tree: Ast, start: ExtraIndex, len: u32, comptime T: type) []const T { | 273 | pub fn extraDataSliceWithLen(tree: *const Ast, start: ExtraIndex, len: u32, comptime T: type) []const T { |
| 286 | return @ptrCast(tree.extra_data[@intFromEnum(start)..][0..len]); | 274 | return @ptrCast(tree.extra_data[@intFromEnum(start)..][0..len]); |
| 287 | } | 275 | } |
| 288 | 276 | ||
| 289 | pub fn extraData(tree: Ast, index: ExtraIndex, comptime T: type) T { | 277 | pub fn extraData(tree: *const Ast, index: ExtraIndex, comptime T: type) T { |
| 290 | const fields = std.meta.fields(T); | 278 | const fields = std.meta.fields(T); |
| 291 | var result: T = undefined; | 279 | var result: T = undefined; |
| 292 | inline for (fields, 0..) |field, i| { | 280 | inline for (fields, 0..) |field, i| { |
| ... | @@ -310,15 +298,15 @@ fn loadOptionalNodesIntoBuffer(comptime size: usize, buffer: *[size]Node.Index, | ... | @@ -310,15 +298,15 @@ fn loadOptionalNodesIntoBuffer(comptime size: usize, buffer: *[size]Node.Index, |
| 310 | return buffer[0..]; | 298 | return buffer[0..]; |
| 311 | } | 299 | } |
| 312 | 300 | ||
| 313 | pub fn rootDecls(tree: Ast) []const Node.Index { | 301 | pub fn rootDecls(tree: *const Ast) []const Node.Index { |
| 314 | switch (tree.mode) { | 302 | switch (tree.mode) { |
| 315 | .zig => return tree.extraDataSlice(tree.nodeData(.root).extra_range, Node.Index), | 303 | .zig => return tree.extraDataSlice(Node.Index.root.data(tree).extra_range, Node.Index), |
| 316 | // Ensure that the returned slice points into the existing memory of the Ast | 304 | // Ensure that the returned slice points into the existing memory of the Ast |
| 317 | .zon => return (&tree.nodes.items(.data)[@intFromEnum(Node.Index.root)].node)[0..1], | 305 | .zon => return (&tree.nodes.items(.data)[@intFromEnum(Node.Index.root)].node)[0..1], |
| 318 | } | 306 | } |
| 319 | } | 307 | } |
| 320 | 308 | ||
| 321 | pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { | 309 | pub fn renderError(tree: *const Ast, parse_error: Error, stream: anytype) !void { |
| 322 | switch (parse_error.tag) { | 310 | switch (parse_error.tag) { |
| 323 | .asterisk_after_ptr_deref => { | 311 | .asterisk_after_ptr_deref => { |
| 324 | // Note that the token will point at the `.*` but ideally the source | 312 | // Note that the token will point at the `.*` but ideally the source |
| ... | @@ -591,10 +579,10 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { | ... | @@ -591,10 +579,10 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { |
| 591 | } | 579 | } |
| 592 | } | 580 | } |
| 593 | 581 | ||
| 594 | pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | 582 | pub fn firstToken(tree: *const Ast, node: Node.Index) TokenIndex { |
| 595 | var end_offset: u32 = 0; | 583 | var end_offset: u32 = 0; |
| 596 | var n = node; | 584 | var n = node; |
| 597 | while (true) switch (tree.nodeTag(n)) { | 585 | while (true) switch (n.tag(tree)) { |
| 598 | .root => return 0, | 586 | .root => return 0, |
| 599 | 587 | ||
| 600 | .test_decl, | 588 | .test_decl, |
| ... | @@ -638,7 +626,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -638,7 +626,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 638 | .array_type, | 626 | .array_type, |
| 639 | .array_type_sentinel, | 627 | .array_type_sentinel, |
| 640 | .error_value, | 628 | .error_value, |
| 641 | => return tree.nodeMainToken(n) - end_offset, | 629 | => return n.mainToken(tree) - end_offset, |
| 642 | 630 | ||
| 643 | .array_init_dot, | 631 | .array_init_dot, |
| 644 | .array_init_dot_comma, | 632 | .array_init_dot_comma, |
| ... | @@ -649,7 +637,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -649,7 +637,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 649 | .struct_init_dot_two, | 637 | .struct_init_dot_two, |
| 650 | .struct_init_dot_two_comma, | 638 | .struct_init_dot_two_comma, |
| 651 | .enum_literal, | 639 | .enum_literal, |
| 652 | => return tree.nodeMainToken(n) - 1 - end_offset, | 640 | => return n.mainToken(tree) - 1 - end_offset, |
| 653 | 641 | ||
| 654 | .@"catch", | 642 | .@"catch", |
| 655 | .equal_equal, | 643 | .equal_equal, |
| ... | @@ -705,18 +693,18 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -705,18 +693,18 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 705 | .array_init_one_comma, | 693 | .array_init_one_comma, |
| 706 | .switch_range, | 694 | .switch_range, |
| 707 | .error_union, | 695 | .error_union, |
| 708 | => n = tree.nodeData(n).node_and_node[0], | 696 | => n = n.data(tree).node_and_node[0], |
| 709 | 697 | ||
| 710 | .for_range, | 698 | .for_range, |
| 711 | .call_one, | 699 | .call_one, |
| 712 | .call_one_comma, | 700 | .call_one_comma, |
| 713 | .struct_init_one, | 701 | .struct_init_one, |
| 714 | .struct_init_one_comma, | 702 | .struct_init_one_comma, |
| 715 | => n = tree.nodeData(n).node_and_opt_node[0], | 703 | => n = n.data(tree).node_and_opt_node[0], |
| 716 | 704 | ||
| 717 | .field_access, | 705 | .field_access, |
| 718 | .unwrap_optional, | 706 | .unwrap_optional, |
| 719 | => n = tree.nodeData(n).node_and_token[0], | 707 | => n = n.data(tree).node_and_token[0], |
| 720 | 708 | ||
| 721 | .slice, | 709 | .slice, |
| 722 | .slice_sentinel, | 710 | .slice_sentinel, |
| ... | @@ -726,9 +714,9 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -726,9 +714,9 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 726 | .struct_init_comma, | 714 | .struct_init_comma, |
| 727 | .call, | 715 | .call, |
| 728 | .call_comma, | 716 | .call_comma, |
| 729 | => n = tree.nodeData(n).node_and_extra[0], | 717 | => n = n.data(tree).node_and_extra[0], |
| 730 | 718 | ||
| 731 | .deref => n = tree.nodeData(n).node, | 719 | .deref => n = n.data(tree).node, |
| 732 | 720 | ||
| 733 | .assign_destructure => n = tree.assignDestructure(n).ast.variables[0], | 721 | .assign_destructure => n = tree.assignDestructure(n).ast.variables[0], |
| 734 | 722 | ||
| ... | @@ -738,7 +726,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -738,7 +726,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 738 | .fn_proto_one, | 726 | .fn_proto_one, |
| 739 | .fn_proto, | 727 | .fn_proto, |
| 740 | => { | 728 | => { |
| 741 | var i = tree.nodeMainToken(n); // fn token | 729 | var i = n.mainToken(tree); // fn token |
| 742 | while (i > 0) { | 730 | while (i > 0) { |
| 743 | i -= 1; | 731 | i -= 1; |
| 744 | switch (tree.tokenTag(i)) { | 732 | switch (tree.tokenTag(i)) { |
| ... | @@ -757,7 +745,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -757,7 +745,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 757 | }, | 745 | }, |
| 758 | 746 | ||
| 759 | .@"usingnamespace" => { | 747 | .@"usingnamespace" => { |
| 760 | const main_token: TokenIndex = tree.nodeMainToken(n); | 748 | const main_token: TokenIndex = n.mainToken(tree); |
| 761 | const has_visib_token = tree.isTokenPrecededByTags(main_token, &.{.keyword_pub}); | 749 | const has_visib_token = tree.isTokenPrecededByTags(main_token, &.{.keyword_pub}); |
| 762 | end_offset += @intFromBool(has_visib_token); | 750 | end_offset += @intFromBool(has_visib_token); |
| 763 | return main_token - end_offset; | 751 | return main_token - end_offset; |
| ... | @@ -767,21 +755,21 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -767,21 +755,21 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 767 | .async_call_one_comma, | 755 | .async_call_one_comma, |
| 768 | => { | 756 | => { |
| 769 | end_offset += 1; // async token | 757 | end_offset += 1; // async token |
| 770 | n = tree.nodeData(n).node_and_opt_node[0]; | 758 | n = n.data(tree).node_and_opt_node[0]; |
| 771 | }, | 759 | }, |
| 772 | 760 | ||
| 773 | .async_call, | 761 | .async_call, |
| 774 | .async_call_comma, | 762 | .async_call_comma, |
| 775 | => { | 763 | => { |
| 776 | end_offset += 1; // async token | 764 | end_offset += 1; // async token |
| 777 | n = tree.nodeData(n).node_and_extra[0]; | 765 | n = n.data(tree).node_and_extra[0]; |
| 778 | }, | 766 | }, |
| 779 | 767 | ||
| 780 | .container_field_init, | 768 | .container_field_init, |
| 781 | .container_field_align, | 769 | .container_field_align, |
| 782 | .container_field, | 770 | .container_field, |
| 783 | => { | 771 | => { |
| 784 | const name_token = tree.nodeMainToken(n); | 772 | const name_token = n.mainToken(tree); |
| 785 | const has_comptime_token = tree.isTokenPrecededByTags(name_token, &.{.keyword_comptime}); | 773 | const has_comptime_token = tree.isTokenPrecededByTags(name_token, &.{.keyword_comptime}); |
| 786 | end_offset += @intFromBool(has_comptime_token); | 774 | end_offset += @intFromBool(has_comptime_token); |
| 787 | return name_token - end_offset; | 775 | return name_token - end_offset; |
| ... | @@ -792,7 +780,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -792,7 +780,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 792 | .simple_var_decl, | 780 | .simple_var_decl, |
| 793 | .aligned_var_decl, | 781 | .aligned_var_decl, |
| 794 | => { | 782 | => { |
| 795 | var i = tree.nodeMainToken(n); // mut token | 783 | var i = n.mainToken(tree); // mut token |
| 796 | while (i > 0) { | 784 | while (i > 0) { |
| 797 | i -= 1; | 785 | i -= 1; |
| 798 | switch (tree.tokenTag(i)) { | 786 | switch (tree.tokenTag(i)) { |
| ... | @@ -816,7 +804,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -816,7 +804,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 816 | .block_two_semicolon, | 804 | .block_two_semicolon, |
| 817 | => { | 805 | => { |
| 818 | // Look for a label. | 806 | // Look for a label. |
| 819 | const lbrace = tree.nodeMainToken(n); | 807 | const lbrace = n.mainToken(tree); |
| 820 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { | 808 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { |
| 821 | end_offset += 2; | 809 | end_offset += 2; |
| 822 | } | 810 | } |
| ... | @@ -836,7 +824,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -836,7 +824,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 836 | .tagged_union_enum_tag, | 824 | .tagged_union_enum_tag, |
| 837 | .tagged_union_enum_tag_trailing, | 825 | .tagged_union_enum_tag_trailing, |
| 838 | => { | 826 | => { |
| 839 | const main_token = tree.nodeMainToken(n); | 827 | const main_token = n.mainToken(tree); |
| 840 | switch (tree.tokenTag(main_token -| 1)) { | 828 | switch (tree.tokenTag(main_token -| 1)) { |
| 841 | .keyword_packed, .keyword_extern => end_offset += 1, | 829 | .keyword_packed, .keyword_extern => end_offset += 1, |
| 842 | else => {}, | 830 | else => {}, |
| ... | @@ -848,7 +836,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -848,7 +836,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 848 | .ptr_type_sentinel, | 836 | .ptr_type_sentinel, |
| 849 | .ptr_type, | 837 | .ptr_type, |
| 850 | .ptr_type_bit_range, | 838 | .ptr_type_bit_range, |
| 851 | => return tree.nodeMainToken(n) - end_offset, | 839 | => return n.mainToken(tree) - end_offset, |
| 852 | 840 | ||
| 853 | .switch_case_one, | 841 | .switch_case_one, |
| 854 | .switch_case_inline_one, | 842 | .switch_case_inline_one, |
| ... | @@ -866,8 +854,8 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -866,8 +854,8 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 866 | }, | 854 | }, |
| 867 | 855 | ||
| 868 | .asm_output, .asm_input => { | 856 | .asm_output, .asm_input => { |
| 869 | assert(tree.tokenTag(tree.nodeMainToken(n) - 1) == .l_bracket); | 857 | assert(tree.tokenTag(n.mainToken(tree) - 1) == .l_bracket); |
| 870 | return tree.nodeMainToken(n) - 1 - end_offset; | 858 | return n.mainToken(tree) - 1 - end_offset; |
| 871 | }, | 859 | }, |
| 872 | 860 | ||
| 873 | .while_simple, | 861 | .while_simple, |
| ... | @@ -877,7 +865,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -877,7 +865,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 877 | .@"for", | 865 | .@"for", |
| 878 | => { | 866 | => { |
| 879 | // Look for a label and inline. | 867 | // Look for a label and inline. |
| 880 | const main_token = tree.nodeMainToken(n); | 868 | const main_token = n.mainToken(tree); |
| 881 | var result = main_token; | 869 | var result = main_token; |
| 882 | if (tree.isTokenPrecededByTags(result, &.{.keyword_inline})) { | 870 | if (tree.isTokenPrecededByTags(result, &.{.keyword_inline})) { |
| 883 | result = result - 1; | 871 | result = result - 1; |
| ... | @@ -890,10 +878,10 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -890,10 +878,10 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 890 | }; | 878 | }; |
| 891 | } | 879 | } |
| 892 | 880 | ||
| 893 | pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | 881 | pub fn lastToken(tree: *const Ast, node: Node.Index) TokenIndex { |
| 894 | var n = node; | 882 | var n = node; |
| 895 | var end_offset: u32 = 0; | 883 | var end_offset: u32 = 0; |
| 896 | while (true) switch (tree.nodeTag(n)) { | 884 | while (true) switch (n.tag(tree)) { |
| 897 | .root => return @intCast(tree.tokens.len - 1), | 885 | .root => return @intCast(tree.tokens.len - 1), |
| 898 | 886 | ||
| 899 | .@"usingnamespace", | 887 | .@"usingnamespace", |
| ... | @@ -909,7 +897,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -909,7 +897,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 909 | .@"resume", | 897 | .@"resume", |
| 910 | .@"nosuspend", | 898 | .@"nosuspend", |
| 911 | .@"comptime", | 899 | .@"comptime", |
| 912 | => n = tree.nodeData(n).node, | 900 | => n = n.data(tree).node, |
| 913 | 901 | ||
| 914 | .@"catch", | 902 | .@"catch", |
| 915 | .equal_equal, | 903 | .equal_equal, |
| ... | @@ -966,45 +954,45 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -966,45 +954,45 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 966 | .fn_decl, | 954 | .fn_decl, |
| 967 | .array_type, | 955 | .array_type, |
| 968 | .switch_range, | 956 | .switch_range, |
| 969 | => n = tree.nodeData(n).node_and_node[1], | 957 | => n = n.data(tree).node_and_node[1], |
| 970 | 958 | ||
| 971 | .test_decl, .@"errdefer" => n = tree.nodeData(n).opt_token_and_node[1], | 959 | .test_decl, .@"errdefer" => n = n.data(tree).opt_token_and_node[1], |
| 972 | .@"defer" => n = tree.nodeData(n).node, | 960 | .@"defer" => n = n.data(tree).node, |
| 973 | .anyframe_type => n = tree.nodeData(n).token_and_node[1], | 961 | .anyframe_type => n = n.data(tree).token_and_node[1], |
| 974 | 962 | ||
| 975 | .switch_case_one, | 963 | .switch_case_one, |
| 976 | .switch_case_inline_one, | 964 | .switch_case_inline_one, |
| 977 | .ptr_type_aligned, | 965 | .ptr_type_aligned, |
| 978 | .ptr_type_sentinel, | 966 | .ptr_type_sentinel, |
| 979 | => n = tree.nodeData(n).opt_node_and_node[1], | 967 | => n = n.data(tree).opt_node_and_node[1], |
| 980 | 968 | ||
| 981 | .assign_destructure, | 969 | .assign_destructure, |
| 982 | .ptr_type, | 970 | .ptr_type, |
| 983 | .ptr_type_bit_range, | 971 | .ptr_type_bit_range, |
| 984 | .switch_case, | 972 | .switch_case, |
| 985 | .switch_case_inline, | 973 | .switch_case_inline, |
| 986 | => n = tree.nodeData(n).extra_and_node[1], | 974 | => n = n.data(tree).extra_and_node[1], |
| 987 | 975 | ||
| 988 | .fn_proto_simple => n = tree.nodeData(n).opt_node_and_opt_node[1].unwrap().?, | 976 | .fn_proto_simple => n = n.data(tree).opt_node_and_opt_node[1].unwrap().?, |
| 989 | .fn_proto_multi, | 977 | .fn_proto_multi, |
| 990 | .fn_proto_one, | 978 | .fn_proto_one, |
| 991 | .fn_proto, | 979 | .fn_proto, |
| 992 | => n = tree.nodeData(n).extra_and_opt_node[1].unwrap().?, | 980 | => n = n.data(tree).extra_and_opt_node[1].unwrap().?, |
| 993 | 981 | ||
| 994 | .for_range => { | 982 | .for_range => { |
| 995 | n = tree.nodeData(n).node_and_opt_node[1].unwrap() orelse { | 983 | n = n.data(tree).node_and_opt_node[1].unwrap() orelse { |
| 996 | return tree.nodeMainToken(n) + end_offset; | 984 | return n.mainToken(tree) + end_offset; |
| 997 | }; | 985 | }; |
| 998 | }, | 986 | }, |
| 999 | 987 | ||
| 1000 | .field_access, | 988 | .field_access, |
| 1001 | .unwrap_optional, | 989 | .unwrap_optional, |
| 1002 | .asm_simple, | 990 | .asm_simple, |
| 1003 | => return tree.nodeData(n).node_and_token[1] + end_offset, | 991 | => return n.data(tree).node_and_token[1] + end_offset, |
| 1004 | .grouped_expression, .asm_input => return tree.nodeData(n).node_and_token[1] + end_offset, | 992 | .grouped_expression, .asm_input => return n.data(tree).node_and_token[1] + end_offset, |
| 1005 | .multiline_string_literal, .error_set_decl => return tree.nodeData(n).token_and_token[1] + end_offset, | 993 | .multiline_string_literal, .error_set_decl => return n.data(tree).token_and_token[1] + end_offset, |
| 1006 | .asm_output => return tree.nodeData(n).opt_node_and_token[1] + end_offset, | 994 | .asm_output => return n.data(tree).opt_node_and_token[1] + end_offset, |
| 1007 | .error_value => return tree.nodeMainToken(n) + 2 + end_offset, | 995 | .error_value => return n.mainToken(tree) + 2 + end_offset, |
| 1008 | 996 | ||
| 1009 | .anyframe_literal, | 997 | .anyframe_literal, |
| 1010 | .char_literal, | 998 | .char_literal, |
| ... | @@ -1014,23 +1002,23 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1014,23 +1002,23 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1014 | .deref, | 1002 | .deref, |
| 1015 | .enum_literal, | 1003 | .enum_literal, |
| 1016 | .string_literal, | 1004 | .string_literal, |
| 1017 | => return tree.nodeMainToken(n) + end_offset, | 1005 | => return n.mainToken(tree) + end_offset, |
| 1018 | 1006 | ||
| 1019 | .@"return" => { | 1007 | .@"return" => { |
| 1020 | n = tree.nodeData(n).opt_node.unwrap() orelse { | 1008 | n = n.data(tree).opt_node.unwrap() orelse { |
| 1021 | return tree.nodeMainToken(n) + end_offset; | 1009 | return n.mainToken(tree) + end_offset; |
| 1022 | }; | 1010 | }; |
| 1023 | }, | 1011 | }, |
| 1024 | 1012 | ||
| 1025 | .call, .async_call => { | 1013 | .call, .async_call => { |
| 1026 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1014 | _, const extra_index = n.data(tree).node_and_extra; |
| 1027 | const params = tree.extraData(extra_index, Node.SubRange); | 1015 | const params = tree.extraData(extra_index, Node.SubRange); |
| 1028 | assert(params.start != params.end); | 1016 | assert(params.start != params.end); |
| 1029 | end_offset += 1; // for the rparen | 1017 | end_offset += 1; // for the rparen |
| 1030 | n = @enumFromInt(tree.extra_data[@intFromEnum(params.end) - 1]); // last parameter | 1018 | n = @enumFromInt(tree.extra_data[@intFromEnum(params.end) - 1]); // last parameter |
| 1031 | }, | 1019 | }, |
| 1032 | .tagged_union_enum_tag => { | 1020 | .tagged_union_enum_tag => { |
| 1033 | const arg, const extra_index = tree.nodeData(n).node_and_extra; | 1021 | const arg, const extra_index = n.data(tree).node_and_extra; |
| 1034 | const members = tree.extraData(extra_index, Node.SubRange); | 1022 | const members = tree.extraData(extra_index, Node.SubRange); |
| 1035 | if (members.start == members.end) { | 1023 | if (members.start == members.end) { |
| 1036 | end_offset += 4; // for the rparen + rparen + lbrace + rbrace | 1024 | end_offset += 4; // for the rparen + rparen + lbrace + rbrace |
| ... | @@ -1044,14 +1032,14 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1044,14 +1032,14 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1044 | .async_call_comma, | 1032 | .async_call_comma, |
| 1045 | .tagged_union_enum_tag_trailing, | 1033 | .tagged_union_enum_tag_trailing, |
| 1046 | => { | 1034 | => { |
| 1047 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1035 | _, const extra_index = n.data(tree).node_and_extra; |
| 1048 | const params = tree.extraData(extra_index, Node.SubRange); | 1036 | const params = tree.extraData(extra_index, Node.SubRange); |
| 1049 | assert(params.start != params.end); | 1037 | assert(params.start != params.end); |
| 1050 | end_offset += 2; // for the comma/semicolon + rparen/rbrace | 1038 | end_offset += 2; // for the comma/semicolon + rparen/rbrace |
| 1051 | n = @enumFromInt(tree.extra_data[@intFromEnum(params.end) - 1]); // last parameter | 1039 | n = @enumFromInt(tree.extra_data[@intFromEnum(params.end) - 1]); // last parameter |
| 1052 | }, | 1040 | }, |
| 1053 | .@"switch" => { | 1041 | .@"switch" => { |
| 1054 | const condition, const extra_index = tree.nodeData(n).node_and_extra; | 1042 | const condition, const extra_index = n.data(tree).node_and_extra; |
| 1055 | const cases = tree.extraData(extra_index, Node.SubRange); | 1043 | const cases = tree.extraData(extra_index, Node.SubRange); |
| 1056 | if (cases.start == cases.end) { | 1044 | if (cases.start == cases.end) { |
| 1057 | end_offset += 3; // rparen, lbrace, rbrace | 1045 | end_offset += 3; // rparen, lbrace, rbrace |
| ... | @@ -1062,7 +1050,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1062,7 +1050,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1062 | } | 1050 | } |
| 1063 | }, | 1051 | }, |
| 1064 | .container_decl_arg => { | 1052 | .container_decl_arg => { |
| 1065 | const arg, const extra_index = tree.nodeData(n).node_and_extra; | 1053 | const arg, const extra_index = n.data(tree).node_and_extra; |
| 1066 | const members = tree.extraData(extra_index, Node.SubRange); | 1054 | const members = tree.extraData(extra_index, Node.SubRange); |
| 1067 | if (members.end == members.start) { | 1055 | if (members.end == members.start) { |
| 1068 | end_offset += 3; // for the rparen + lbrace + rbrace | 1056 | end_offset += 3; // for the rparen + lbrace + rbrace |
| ... | @@ -1073,14 +1061,14 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1073,14 +1061,14 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1073 | } | 1061 | } |
| 1074 | }, | 1062 | }, |
| 1075 | .@"asm" => { | 1063 | .@"asm" => { |
| 1076 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1064 | _, const extra_index = n.data(tree).node_and_extra; |
| 1077 | const extra = tree.extraData(extra_index, Node.Asm); | 1065 | const extra = tree.extraData(extra_index, Node.Asm); |
| 1078 | return extra.rparen + end_offset; | 1066 | return extra.rparen + end_offset; |
| 1079 | }, | 1067 | }, |
| 1080 | .array_init, | 1068 | .array_init, |
| 1081 | .struct_init, | 1069 | .struct_init, |
| 1082 | => { | 1070 | => { |
| 1083 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1071 | _, const extra_index = n.data(tree).node_and_extra; |
| 1084 | const elements = tree.extraData(extra_index, Node.SubRange); | 1072 | const elements = tree.extraData(extra_index, Node.SubRange); |
| 1085 | assert(elements.start != elements.end); | 1073 | assert(elements.start != elements.end); |
| 1086 | end_offset += 1; // for the rbrace | 1074 | end_offset += 1; // for the rbrace |
| ... | @@ -1091,7 +1079,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1091,7 +1079,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1091 | .container_decl_arg_trailing, | 1079 | .container_decl_arg_trailing, |
| 1092 | .switch_comma, | 1080 | .switch_comma, |
| 1093 | => { | 1081 | => { |
| 1094 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1082 | _, const extra_index = n.data(tree).node_and_extra; |
| 1095 | const members = tree.extraData(extra_index, Node.SubRange); | 1083 | const members = tree.extraData(extra_index, Node.SubRange); |
| 1096 | assert(members.start != members.end); | 1084 | assert(members.start != members.end); |
| 1097 | end_offset += 2; // for the comma + rbrace | 1085 | end_offset += 2; // for the comma + rbrace |
| ... | @@ -1104,7 +1092,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1104,7 +1092,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1104 | .tagged_union, | 1092 | .tagged_union, |
| 1105 | .builtin_call, | 1093 | .builtin_call, |
| 1106 | => { | 1094 | => { |
| 1107 | const range = tree.nodeData(n).extra_range; | 1095 | const range = n.data(tree).extra_range; |
| 1108 | assert(range.start != range.end); | 1096 | assert(range.start != range.end); |
| 1109 | end_offset += 1; // for the rbrace | 1097 | end_offset += 1; // for the rbrace |
| 1110 | n = @enumFromInt(tree.extra_data[@intFromEnum(range.end) - 1]); // last statement | 1098 | n = @enumFromInt(tree.extra_data[@intFromEnum(range.end) - 1]); // last statement |
| ... | @@ -1116,7 +1104,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1116,7 +1104,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1116 | .tagged_union_trailing, | 1104 | .tagged_union_trailing, |
| 1117 | .builtin_call_comma, | 1105 | .builtin_call_comma, |
| 1118 | => { | 1106 | => { |
| 1119 | const range = tree.nodeData(n).extra_range; | 1107 | const range = n.data(tree).extra_range; |
| 1120 | assert(range.start != range.end); | 1108 | assert(range.start != range.end); |
| 1121 | end_offset += 2; // for the comma/semicolon + rbrace/rparen | 1109 | end_offset += 2; // for the comma/semicolon + rbrace/rparen |
| 1122 | n = @enumFromInt(tree.extra_data[@intFromEnum(range.end) - 1]); // last member | 1110 | n = @enumFromInt(tree.extra_data[@intFromEnum(range.end) - 1]); // last member |
| ... | @@ -1124,10 +1112,10 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1124,10 +1112,10 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1124 | .call_one, | 1112 | .call_one, |
| 1125 | .async_call_one, | 1113 | .async_call_one, |
| 1126 | => { | 1114 | => { |
| 1127 | _, const first_param = tree.nodeData(n).node_and_opt_node; | 1115 | _, const first_param = n.data(tree).node_and_opt_node; |
| 1128 | end_offset += 1; // for the rparen | 1116 | end_offset += 1; // for the rparen |
| 1129 | n = first_param.unwrap() orelse { | 1117 | n = first_param.unwrap() orelse { |
| 1130 | return tree.nodeMainToken(n) + end_offset; | 1118 | return n.mainToken(tree) + end_offset; |
| 1131 | }; | 1119 | }; |
| 1132 | }, | 1120 | }, |
| 1133 | 1121 | ||
| ... | @@ -1138,7 +1126,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1138,7 +1126,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1138 | .container_decl_two, | 1126 | .container_decl_two, |
| 1139 | .tagged_union_two, | 1127 | .tagged_union_two, |
| 1140 | => { | 1128 | => { |
| 1141 | const opt_lhs, const opt_rhs = tree.nodeData(n).opt_node_and_opt_node; | 1129 | const opt_lhs, const opt_rhs = n.data(tree).opt_node_and_opt_node; |
| 1142 | if (opt_rhs.unwrap()) |rhs| { | 1130 | if (opt_rhs.unwrap()) |rhs| { |
| 1143 | end_offset += 1; // for the rparen/rbrace | 1131 | end_offset += 1; // for the rparen/rbrace |
| 1144 | n = rhs; | 1132 | n = rhs; |
| ... | @@ -1146,7 +1134,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1146,7 +1134,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1146 | end_offset += 1; // for the rparen/rbrace | 1134 | end_offset += 1; // for the rparen/rbrace |
| 1147 | n = lhs; | 1135 | n = lhs; |
| 1148 | } else { | 1136 | } else { |
| 1149 | switch (tree.nodeTag(n)) { | 1137 | switch (n.tag(tree)) { |
| 1150 | .array_init_dot_two, | 1138 | .array_init_dot_two, |
| 1151 | .block_two, | 1139 | .block_two, |
| 1152 | .struct_init_dot_two, | 1140 | .struct_init_dot_two, |
| ... | @@ -1154,17 +1142,17 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1154,17 +1142,17 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1154 | .builtin_call_two => end_offset += 2, // lparen/lbrace + rparen/rbrace | 1142 | .builtin_call_two => end_offset += 2, // lparen/lbrace + rparen/rbrace |
| 1155 | .container_decl_two => { | 1143 | .container_decl_two => { |
| 1156 | var i: u32 = 2; // lbrace + rbrace | 1144 | var i: u32 = 2; // lbrace + rbrace |
| 1157 | while (tree.tokenTag(tree.nodeMainToken(n) + i) == .container_doc_comment) i += 1; | 1145 | while (tree.tokenTag(n.mainToken(tree) + i) == .container_doc_comment) i += 1; |
| 1158 | end_offset += i; | 1146 | end_offset += i; |
| 1159 | }, | 1147 | }, |
| 1160 | .tagged_union_two => { | 1148 | .tagged_union_two => { |
| 1161 | var i: u32 = 5; // (enum) {} | 1149 | var i: u32 = 5; // (enum) {} |
| 1162 | while (tree.tokenTag(tree.nodeMainToken(n) + i) == .container_doc_comment) i += 1; | 1150 | while (tree.tokenTag(n.mainToken(tree) + i) == .container_doc_comment) i += 1; |
| 1163 | end_offset += i; | 1151 | end_offset += i; |
| 1164 | }, | 1152 | }, |
| 1165 | else => unreachable, | 1153 | else => unreachable, |
| 1166 | } | 1154 | } |
| 1167 | return tree.nodeMainToken(n) + end_offset; | 1155 | return n.mainToken(tree) + end_offset; |
| 1168 | } | 1156 | } |
| 1169 | }, | 1157 | }, |
| 1170 | .array_init_dot_two_comma, | 1158 | .array_init_dot_two_comma, |
| ... | @@ -1174,7 +1162,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1174,7 +1162,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1174 | .container_decl_two_trailing, | 1162 | .container_decl_two_trailing, |
| 1175 | .tagged_union_two_trailing, | 1163 | .tagged_union_two_trailing, |
| 1176 | => { | 1164 | => { |
| 1177 | const opt_lhs, const opt_rhs = tree.nodeData(n).opt_node_and_opt_node; | 1165 | const opt_lhs, const opt_rhs = n.data(tree).opt_node_and_opt_node; |
| 1178 | end_offset += 2; // for the comma/semicolon + rbrace/rparen | 1166 | end_offset += 2; // for the comma/semicolon + rbrace/rparen |
| 1179 | if (opt_rhs.unwrap()) |rhs| { | 1167 | if (opt_rhs.unwrap()) |rhs| { |
| 1180 | n = rhs; | 1168 | n = rhs; |
| ... | @@ -1185,18 +1173,18 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1185,18 +1173,18 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1185 | } | 1173 | } |
| 1186 | }, | 1174 | }, |
| 1187 | .simple_var_decl => { | 1175 | .simple_var_decl => { |
| 1188 | const type_node, const init_node = tree.nodeData(n).opt_node_and_opt_node; | 1176 | const type_node, const init_node = n.data(tree).opt_node_and_opt_node; |
| 1189 | if (init_node.unwrap()) |rhs| { | 1177 | if (init_node.unwrap()) |rhs| { |
| 1190 | n = rhs; | 1178 | n = rhs; |
| 1191 | } else if (type_node.unwrap()) |lhs| { | 1179 | } else if (type_node.unwrap()) |lhs| { |
| 1192 | n = lhs; | 1180 | n = lhs; |
| 1193 | } else { | 1181 | } else { |
| 1194 | end_offset += 1; // from mut token to name | 1182 | end_offset += 1; // from mut token to name |
| 1195 | return tree.nodeMainToken(n) + end_offset; | 1183 | return n.mainToken(tree) + end_offset; |
| 1196 | } | 1184 | } |
| 1197 | }, | 1185 | }, |
| 1198 | .aligned_var_decl => { | 1186 | .aligned_var_decl => { |
| 1199 | const align_node, const init_node = tree.nodeData(n).node_and_opt_node; | 1187 | const align_node, const init_node = n.data(tree).node_and_opt_node; |
| 1200 | if (init_node.unwrap()) |rhs| { | 1188 | if (init_node.unwrap()) |rhs| { |
| 1201 | n = rhs; | 1189 | n = rhs; |
| 1202 | } else { | 1190 | } else { |
| ... | @@ -1205,7 +1193,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1205,7 +1193,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1205 | } | 1193 | } |
| 1206 | }, | 1194 | }, |
| 1207 | .global_var_decl => { | 1195 | .global_var_decl => { |
| 1208 | const extra_index, const init_node = tree.nodeData(n).extra_and_opt_node; | 1196 | const extra_index, const init_node = n.data(tree).extra_and_opt_node; |
| 1209 | if (init_node.unwrap()) |rhs| { | 1197 | if (init_node.unwrap()) |rhs| { |
| 1210 | n = rhs; | 1198 | n = rhs; |
| 1211 | } else { | 1199 | } else { |
| ... | @@ -1220,12 +1208,12 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1220,12 +1208,12 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1220 | n = type_node; | 1208 | n = type_node; |
| 1221 | } else { | 1209 | } else { |
| 1222 | end_offset += 1; // from mut token to name | 1210 | end_offset += 1; // from mut token to name |
| 1223 | return tree.nodeMainToken(n) + end_offset; | 1211 | return n.mainToken(tree) + end_offset; |
| 1224 | } | 1212 | } |
| 1225 | } | 1213 | } |
| 1226 | }, | 1214 | }, |
| 1227 | .local_var_decl => { | 1215 | .local_var_decl => { |
| 1228 | const extra_index, const init_node = tree.nodeData(n).extra_and_opt_node; | 1216 | const extra_index, const init_node = n.data(tree).extra_and_opt_node; |
| 1229 | if (init_node.unwrap()) |rhs| { | 1217 | if (init_node.unwrap()) |rhs| { |
| 1230 | n = rhs; | 1218 | n = rhs; |
| 1231 | } else { | 1219 | } else { |
| ... | @@ -1235,7 +1223,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1235,7 +1223,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1235 | } | 1223 | } |
| 1236 | }, | 1224 | }, |
| 1237 | .container_field_init => { | 1225 | .container_field_init => { |
| 1238 | const type_expr, const value_expr = tree.nodeData(n).node_and_opt_node; | 1226 | const type_expr, const value_expr = n.data(tree).node_and_opt_node; |
| 1239 | n = value_expr.unwrap() orelse type_expr; | 1227 | n = value_expr.unwrap() orelse type_expr; |
| 1240 | }, | 1228 | }, |
| 1241 | 1229 | ||
| ... | @@ -1243,30 +1231,30 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1243,30 +1231,30 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1243 | .array_init_one, | 1231 | .array_init_one, |
| 1244 | .container_field_align, | 1232 | .container_field_align, |
| 1245 | => { | 1233 | => { |
| 1246 | _, const rhs = tree.nodeData(n).node_and_node; | 1234 | _, const rhs = n.data(tree).node_and_node; |
| 1247 | end_offset += 1; // for the rbracket/rbrace/rparen | 1235 | end_offset += 1; // for the rbracket/rbrace/rparen |
| 1248 | n = rhs; | 1236 | n = rhs; |
| 1249 | }, | 1237 | }, |
| 1250 | .container_field => { | 1238 | .container_field => { |
| 1251 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1239 | _, const extra_index = n.data(tree).node_and_extra; |
| 1252 | const extra = tree.extraData(extra_index, Node.ContainerField); | 1240 | const extra = tree.extraData(extra_index, Node.ContainerField); |
| 1253 | n = extra.value_expr; | 1241 | n = extra.value_expr; |
| 1254 | }, | 1242 | }, |
| 1255 | 1243 | ||
| 1256 | .struct_init_one => { | 1244 | .struct_init_one => { |
| 1257 | _, const first_field = tree.nodeData(n).node_and_opt_node; | 1245 | _, const first_field = n.data(tree).node_and_opt_node; |
| 1258 | end_offset += 1; // rbrace | 1246 | end_offset += 1; // rbrace |
| 1259 | n = first_field.unwrap() orelse { | 1247 | n = first_field.unwrap() orelse { |
| 1260 | return tree.nodeMainToken(n) + end_offset; | 1248 | return n.mainToken(tree) + end_offset; |
| 1261 | }; | 1249 | }; |
| 1262 | }, | 1250 | }, |
| 1263 | .slice_open => { | 1251 | .slice_open => { |
| 1264 | _, const start_node = tree.nodeData(n).node_and_node; | 1252 | _, const start_node = n.data(tree).node_and_node; |
| 1265 | end_offset += 2; // ellipsis2 + rbracket, or comma + rparen | 1253 | end_offset += 2; // ellipsis2 + rbracket, or comma + rparen |
| 1266 | n = start_node; | 1254 | n = start_node; |
| 1267 | }, | 1255 | }, |
| 1268 | .array_init_one_comma => { | 1256 | .array_init_one_comma => { |
| 1269 | _, const first_element = tree.nodeData(n).node_and_node; | 1257 | _, const first_element = n.data(tree).node_and_node; |
| 1270 | end_offset += 2; // comma + rbrace | 1258 | end_offset += 2; // comma + rbrace |
| 1271 | n = first_element; | 1259 | n = first_element; |
| 1272 | }, | 1260 | }, |
| ... | @@ -1274,67 +1262,67 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1274,67 +1262,67 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1274 | .async_call_one_comma, | 1262 | .async_call_one_comma, |
| 1275 | .struct_init_one_comma, | 1263 | .struct_init_one_comma, |
| 1276 | => { | 1264 | => { |
| 1277 | _, const first_field = tree.nodeData(n).node_and_opt_node; | 1265 | _, const first_field = n.data(tree).node_and_opt_node; |
| 1278 | end_offset += 2; // ellipsis2 + rbracket, or comma + rparen | 1266 | end_offset += 2; // ellipsis2 + rbracket, or comma + rparen |
| 1279 | n = first_field.unwrap().?; | 1267 | n = first_field.unwrap().?; |
| 1280 | }, | 1268 | }, |
| 1281 | .slice => { | 1269 | .slice => { |
| 1282 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1270 | _, const extra_index = n.data(tree).node_and_extra; |
| 1283 | const extra = tree.extraData(extra_index, Node.Slice); | 1271 | const extra = tree.extraData(extra_index, Node.Slice); |
| 1284 | end_offset += 1; // rbracket | 1272 | end_offset += 1; // rbracket |
| 1285 | n = extra.end; | 1273 | n = extra.end; |
| 1286 | }, | 1274 | }, |
| 1287 | .slice_sentinel => { | 1275 | .slice_sentinel => { |
| 1288 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1276 | _, const extra_index = n.data(tree).node_and_extra; |
| 1289 | const extra = tree.extraData(extra_index, Node.SliceSentinel); | 1277 | const extra = tree.extraData(extra_index, Node.SliceSentinel); |
| 1290 | end_offset += 1; // rbracket | 1278 | end_offset += 1; // rbracket |
| 1291 | n = extra.sentinel; | 1279 | n = extra.sentinel; |
| 1292 | }, | 1280 | }, |
| 1293 | 1281 | ||
| 1294 | .@"continue", .@"break" => { | 1282 | .@"continue", .@"break" => { |
| 1295 | const opt_label, const opt_rhs = tree.nodeData(n).opt_token_and_opt_node; | 1283 | const opt_label, const opt_rhs = n.data(tree).opt_token_and_opt_node; |
| 1296 | if (opt_rhs.unwrap()) |rhs| { | 1284 | if (opt_rhs.unwrap()) |rhs| { |
| 1297 | n = rhs; | 1285 | n = rhs; |
| 1298 | } else if (opt_label.unwrap()) |lhs| { | 1286 | } else if (opt_label.unwrap()) |lhs| { |
| 1299 | return lhs + end_offset; | 1287 | return lhs + end_offset; |
| 1300 | } else { | 1288 | } else { |
| 1301 | return tree.nodeMainToken(n) + end_offset; | 1289 | return n.mainToken(tree) + end_offset; |
| 1302 | } | 1290 | } |
| 1303 | }, | 1291 | }, |
| 1304 | .while_cont => { | 1292 | .while_cont => { |
| 1305 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1293 | _, const extra_index = n.data(tree).node_and_extra; |
| 1306 | const extra = tree.extraData(extra_index, Node.WhileCont); | 1294 | const extra = tree.extraData(extra_index, Node.WhileCont); |
| 1307 | n = extra.then_expr; | 1295 | n = extra.then_expr; |
| 1308 | }, | 1296 | }, |
| 1309 | .@"while" => { | 1297 | .@"while" => { |
| 1310 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1298 | _, const extra_index = n.data(tree).node_and_extra; |
| 1311 | const extra = tree.extraData(extra_index, Node.While); | 1299 | const extra = tree.extraData(extra_index, Node.While); |
| 1312 | n = extra.else_expr; | 1300 | n = extra.else_expr; |
| 1313 | }, | 1301 | }, |
| 1314 | .@"if" => { | 1302 | .@"if" => { |
| 1315 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1303 | _, const extra_index = n.data(tree).node_and_extra; |
| 1316 | const extra = tree.extraData(extra_index, Node.If); | 1304 | const extra = tree.extraData(extra_index, Node.If); |
| 1317 | n = extra.else_expr; | 1305 | n = extra.else_expr; |
| 1318 | }, | 1306 | }, |
| 1319 | .@"for" => { | 1307 | .@"for" => { |
| 1320 | const extra_index, const extra = tree.nodeData(n).@"for"; | 1308 | const extra_index, const extra = n.data(tree).@"for"; |
| 1321 | const index = @intFromEnum(extra_index) + extra.inputs + @intFromBool(extra.has_else); | 1309 | const index = @intFromEnum(extra_index) + extra.inputs + @intFromBool(extra.has_else); |
| 1322 | n = @enumFromInt(tree.extra_data[index]); | 1310 | n = @enumFromInt(tree.extra_data[index]); |
| 1323 | }, | 1311 | }, |
| 1324 | .array_type_sentinel => { | 1312 | .array_type_sentinel => { |
| 1325 | _, const extra_index = tree.nodeData(n).node_and_extra; | 1313 | _, const extra_index = n.data(tree).node_and_extra; |
| 1326 | const extra = tree.extraData(extra_index, Node.ArrayTypeSentinel); | 1314 | const extra = tree.extraData(extra_index, Node.ArrayTypeSentinel); |
| 1327 | n = extra.elem_type; | 1315 | n = extra.elem_type; |
| 1328 | }, | 1316 | }, |
| 1329 | }; | 1317 | }; |
| 1330 | } | 1318 | } |
| 1331 | 1319 | ||
| 1332 | pub fn tokensOnSameLine(tree: Ast, token1: TokenIndex, token2: TokenIndex) bool { | 1320 | pub fn tokensOnSameLine(tree: *const Ast, token1: TokenIndex, token2: TokenIndex) bool { |
| 1333 | const source = tree.source[tree.tokenStart(token1)..tree.tokenStart(token2)]; | 1321 | const source = tree.source[tree.tokenStart(token1)..tree.tokenStart(token2)]; |
| 1334 | return mem.indexOfScalar(u8, source, '\n') == null; | 1322 | return mem.indexOfScalar(u8, source, '\n') == null; |
| 1335 | } | 1323 | } |
| 1336 | 1324 | ||
| 1337 | pub fn getNodeSource(tree: Ast, node: Node.Index) []const u8 { | 1325 | pub fn getNodeSource(tree: *const Ast, node: Node.Index) []const u8 { |
| 1338 | const first_token = tree.firstToken(node); | 1326 | const first_token = tree.firstToken(node); |
| 1339 | const last_token = tree.lastToken(node); | 1327 | const last_token = tree.lastToken(node); |
| 1340 | const start = tree.tokenStart(first_token); | 1328 | const start = tree.tokenStart(first_token); |
| ... | @@ -1342,9 +1330,9 @@ pub fn getNodeSource(tree: Ast, node: Node.Index) []const u8 { | ... | @@ -1342,9 +1330,9 @@ pub fn getNodeSource(tree: Ast, node: Node.Index) []const u8 { |
| 1342 | return tree.source[start..end]; | 1330 | return tree.source[start..end]; |
| 1343 | } | 1331 | } |
| 1344 | 1332 | ||
| 1345 | pub fn globalVarDecl(tree: Ast, node: Node.Index) full.VarDecl { | 1333 | pub fn globalVarDecl(tree: *const Ast, node: Node.Index) full.VarDecl { |
| 1346 | assert(tree.nodeTag(node) == .global_var_decl); | 1334 | assert(node.tag(tree) == .global_var_decl); |
| 1347 | const extra_index, const init_node = tree.nodeData(node).extra_and_opt_node; | 1335 | const extra_index, const init_node = node.data(tree).extra_and_opt_node; |
| 1348 | const extra = tree.extraData(extra_index, Node.GlobalVarDecl); | 1336 | const extra = tree.extraData(extra_index, Node.GlobalVarDecl); |
| 1349 | return tree.fullVarDeclComponents(.{ | 1337 | return tree.fullVarDeclComponents(.{ |
| 1350 | .type_node = extra.type_node, | 1338 | .type_node = extra.type_node, |
| ... | @@ -1352,13 +1340,13 @@ pub fn globalVarDecl(tree: Ast, node: Node.Index) full.VarDecl { | ... | @@ -1352,13 +1340,13 @@ pub fn globalVarDecl(tree: Ast, node: Node.Index) full.VarDecl { |
| 1352 | .addrspace_node = extra.addrspace_node, | 1340 | .addrspace_node = extra.addrspace_node, |
| 1353 | .section_node = extra.section_node, | 1341 | .section_node = extra.section_node, |
| 1354 | .init_node = init_node, | 1342 | .init_node = init_node, |
| 1355 | .mut_token = tree.nodeMainToken(node), | 1343 | .mut_token = node.mainToken(tree), |
| 1356 | }); | 1344 | }); |
| 1357 | } | 1345 | } |
| 1358 | 1346 | ||
| 1359 | pub fn localVarDecl(tree: Ast, node: Node.Index) full.VarDecl { | 1347 | pub fn localVarDecl(tree: *const Ast, node: Node.Index) full.VarDecl { |
| 1360 | assert(tree.nodeTag(node) == .local_var_decl); | 1348 | assert(node.tag(tree) == .local_var_decl); |
| 1361 | const extra_index, const init_node = tree.nodeData(node).extra_and_opt_node; | 1349 | const extra_index, const init_node = node.data(tree).extra_and_opt_node; |
| 1362 | const extra = tree.extraData(extra_index, Node.LocalVarDecl); | 1350 | const extra = tree.extraData(extra_index, Node.LocalVarDecl); |
| 1363 | return tree.fullVarDeclComponents(.{ | 1351 | return tree.fullVarDeclComponents(.{ |
| 1364 | .type_node = extra.type_node.toOptional(), | 1352 | .type_node = extra.type_node.toOptional(), |
| ... | @@ -1366,74 +1354,74 @@ pub fn localVarDecl(tree: Ast, node: Node.Index) full.VarDecl { | ... | @@ -1366,74 +1354,74 @@ pub fn localVarDecl(tree: Ast, node: Node.Index) full.VarDecl { |
| 1366 | .addrspace_node = .none, | 1354 | .addrspace_node = .none, |
| 1367 | .section_node = .none, | 1355 | .section_node = .none, |
| 1368 | .init_node = init_node, | 1356 | .init_node = init_node, |
| 1369 | .mut_token = tree.nodeMainToken(node), | 1357 | .mut_token = node.mainToken(tree), |
| 1370 | }); | 1358 | }); |
| 1371 | } | 1359 | } |
| 1372 | 1360 | ||
| 1373 | pub fn simpleVarDecl(tree: Ast, node: Node.Index) full.VarDecl { | 1361 | pub fn simpleVarDecl(tree: *const Ast, node: Node.Index) full.VarDecl { |
| 1374 | assert(tree.nodeTag(node) == .simple_var_decl); | 1362 | assert(node.tag(tree) == .simple_var_decl); |
| 1375 | const type_node, const init_node = tree.nodeData(node).opt_node_and_opt_node; | 1363 | const type_node, const init_node = node.data(tree).opt_node_and_opt_node; |
| 1376 | return tree.fullVarDeclComponents(.{ | 1364 | return tree.fullVarDeclComponents(.{ |
| 1377 | .type_node = type_node, | 1365 | .type_node = type_node, |
| 1378 | .align_node = .none, | 1366 | .align_node = .none, |
| 1379 | .addrspace_node = .none, | 1367 | .addrspace_node = .none, |
| 1380 | .section_node = .none, | 1368 | .section_node = .none, |
| 1381 | .init_node = init_node, | 1369 | .init_node = init_node, |
| 1382 | .mut_token = tree.nodeMainToken(node), | 1370 | .mut_token = node.mainToken(tree), |
| 1383 | }); | 1371 | }); |
| 1384 | } | 1372 | } |
| 1385 | 1373 | ||
| 1386 | pub fn alignedVarDecl(tree: Ast, node: Node.Index) full.VarDecl { | 1374 | pub fn alignedVarDecl(tree: *const Ast, node: Node.Index) full.VarDecl { |
| 1387 | assert(tree.nodeTag(node) == .aligned_var_decl); | 1375 | assert(node.tag(tree) == .aligned_var_decl); |
| 1388 | const align_node, const init_node = tree.nodeData(node).node_and_opt_node; | 1376 | const align_node, const init_node = node.data(tree).node_and_opt_node; |
| 1389 | return tree.fullVarDeclComponents(.{ | 1377 | return tree.fullVarDeclComponents(.{ |
| 1390 | .type_node = .none, | 1378 | .type_node = .none, |
| 1391 | .align_node = align_node.toOptional(), | 1379 | .align_node = align_node.toOptional(), |
| 1392 | .addrspace_node = .none, | 1380 | .addrspace_node = .none, |
| 1393 | .section_node = .none, | 1381 | .section_node = .none, |
| 1394 | .init_node = init_node, | 1382 | .init_node = init_node, |
| 1395 | .mut_token = tree.nodeMainToken(node), | 1383 | .mut_token = node.mainToken(tree), |
| 1396 | }); | 1384 | }); |
| 1397 | } | 1385 | } |
| 1398 | 1386 | ||
| 1399 | pub fn assignDestructure(tree: Ast, node: Node.Index) full.AssignDestructure { | 1387 | pub fn assignDestructure(tree: *const Ast, node: Node.Index) full.AssignDestructure { |
| 1400 | const extra_index, const value_expr = tree.nodeData(node).extra_and_node; | 1388 | const extra_index, const value_expr = node.data(tree).extra_and_node; |
| 1401 | const variable_count = tree.extra_data[@intFromEnum(extra_index)]; | 1389 | const variable_count = tree.extra_data[@intFromEnum(extra_index)]; |
| 1402 | return tree.fullAssignDestructureComponents(.{ | 1390 | return tree.fullAssignDestructureComponents(.{ |
| 1403 | .variables = tree.extraDataSliceWithLen(@enumFromInt(@intFromEnum(extra_index) + 1), variable_count, Node.Index), | 1391 | .variables = tree.extraDataSliceWithLen(@enumFromInt(@intFromEnum(extra_index) + 1), variable_count, Node.Index), |
| 1404 | .equal_token = tree.nodeMainToken(node), | 1392 | .equal_token = node.mainToken(tree), |
| 1405 | .value_expr = value_expr, | 1393 | .value_expr = value_expr, |
| 1406 | }); | 1394 | }); |
| 1407 | } | 1395 | } |
| 1408 | 1396 | ||
| 1409 | pub fn ifSimple(tree: Ast, node: Node.Index) full.If { | 1397 | pub fn ifSimple(tree: *const Ast, node: Node.Index) full.If { |
| 1410 | assert(tree.nodeTag(node) == .if_simple); | 1398 | assert(node.tag(tree) == .if_simple); |
| 1411 | const cond_expr, const then_expr = tree.nodeData(node).node_and_node; | 1399 | const cond_expr, const then_expr = node.data(tree).node_and_node; |
| 1412 | return tree.fullIfComponents(.{ | 1400 | return tree.fullIfComponents(.{ |
| 1413 | .cond_expr = cond_expr, | 1401 | .cond_expr = cond_expr, |
| 1414 | .then_expr = then_expr, | 1402 | .then_expr = then_expr, |
| 1415 | .else_expr = .none, | 1403 | .else_expr = .none, |
| 1416 | .if_token = tree.nodeMainToken(node), | 1404 | .if_token = node.mainToken(tree), |
| 1417 | }); | 1405 | }); |
| 1418 | } | 1406 | } |
| 1419 | 1407 | ||
| 1420 | pub fn ifFull(tree: Ast, node: Node.Index) full.If { | 1408 | pub fn ifFull(tree: *const Ast, node: Node.Index) full.If { |
| 1421 | assert(tree.nodeTag(node) == .@"if"); | 1409 | assert(node.tag(tree) == .@"if"); |
| 1422 | const cond_expr, const extra_index = tree.nodeData(node).node_and_extra; | 1410 | const cond_expr, const extra_index = node.data(tree).node_and_extra; |
| 1423 | const extra = tree.extraData(extra_index, Node.If); | 1411 | const extra = tree.extraData(extra_index, Node.If); |
| 1424 | return tree.fullIfComponents(.{ | 1412 | return tree.fullIfComponents(.{ |
| 1425 | .cond_expr = cond_expr, | 1413 | .cond_expr = cond_expr, |
| 1426 | .then_expr = extra.then_expr, | 1414 | .then_expr = extra.then_expr, |
| 1427 | .else_expr = extra.else_expr.toOptional(), | 1415 | .else_expr = extra.else_expr.toOptional(), |
| 1428 | .if_token = tree.nodeMainToken(node), | 1416 | .if_token = node.mainToken(tree), |
| 1429 | }); | 1417 | }); |
| 1430 | } | 1418 | } |
| 1431 | 1419 | ||
| 1432 | pub fn containerField(tree: Ast, node: Node.Index) full.ContainerField { | 1420 | pub fn containerField(tree: *const Ast, node: Node.Index) full.ContainerField { |
| 1433 | assert(tree.nodeTag(node) == .container_field); | 1421 | assert(node.tag(tree) == .container_field); |
| 1434 | const type_expr, const extra_index = tree.nodeData(node).node_and_extra; | 1422 | const type_expr, const extra_index = node.data(tree).node_and_extra; |
| 1435 | const extra = tree.extraData(extra_index, Node.ContainerField); | 1423 | const extra = tree.extraData(extra_index, Node.ContainerField); |
| 1436 | const main_token = tree.nodeMainToken(node); | 1424 | const main_token = node.mainToken(tree); |
| 1437 | return tree.fullContainerFieldComponents(.{ | 1425 | return tree.fullContainerFieldComponents(.{ |
| 1438 | .main_token = main_token, | 1426 | .main_token = main_token, |
| 1439 | .type_expr = type_expr.toOptional(), | 1427 | .type_expr = type_expr.toOptional(), |
| ... | @@ -1444,10 +1432,10 @@ pub fn containerField(tree: Ast, node: Node.Index) full.ContainerField { | ... | @@ -1444,10 +1432,10 @@ pub fn containerField(tree: Ast, node: Node.Index) full.ContainerField { |
| 1444 | }); | 1432 | }); |
| 1445 | } | 1433 | } |
| 1446 | 1434 | ||
| 1447 | pub fn containerFieldInit(tree: Ast, node: Node.Index) full.ContainerField { | 1435 | pub fn containerFieldInit(tree: *const Ast, node: Node.Index) full.ContainerField { |
| 1448 | assert(tree.nodeTag(node) == .container_field_init); | 1436 | assert(node.tag(tree) == .container_field_init); |
| 1449 | const type_expr, const value_expr = tree.nodeData(node).node_and_opt_node; | 1437 | const type_expr, const value_expr = node.data(tree).node_and_opt_node; |
| 1450 | const main_token = tree.nodeMainToken(node); | 1438 | const main_token = node.mainToken(tree); |
| 1451 | return tree.fullContainerFieldComponents(.{ | 1439 | return tree.fullContainerFieldComponents(.{ |
| 1452 | .main_token = main_token, | 1440 | .main_token = main_token, |
| 1453 | .type_expr = type_expr.toOptional(), | 1441 | .type_expr = type_expr.toOptional(), |
| ... | @@ -1458,10 +1446,10 @@ pub fn containerFieldInit(tree: Ast, node: Node.Index) full.ContainerField { | ... | @@ -1458,10 +1446,10 @@ pub fn containerFieldInit(tree: Ast, node: Node.Index) full.ContainerField { |
| 1458 | }); | 1446 | }); |
| 1459 | } | 1447 | } |
| 1460 | 1448 | ||
| 1461 | pub fn containerFieldAlign(tree: Ast, node: Node.Index) full.ContainerField { | 1449 | pub fn containerFieldAlign(tree: *const Ast, node: Node.Index) full.ContainerField { |
| 1462 | assert(tree.nodeTag(node) == .container_field_align); | 1450 | assert(node.tag(tree) == .container_field_align); |
| 1463 | const type_expr, const align_expr = tree.nodeData(node).node_and_node; | 1451 | const type_expr, const align_expr = node.data(tree).node_and_node; |
| 1464 | const main_token = tree.nodeMainToken(node); | 1452 | const main_token = node.mainToken(tree); |
| 1465 | return tree.fullContainerFieldComponents(.{ | 1453 | return tree.fullContainerFieldComponents(.{ |
| 1466 | .main_token = main_token, | 1454 | .main_token = main_token, |
| 1467 | .type_expr = type_expr.toOptional(), | 1455 | .type_expr = type_expr.toOptional(), |
| ... | @@ -1472,13 +1460,13 @@ pub fn containerFieldAlign(tree: Ast, node: Node.Index) full.ContainerField { | ... | @@ -1472,13 +1460,13 @@ pub fn containerFieldAlign(tree: Ast, node: Node.Index) full.ContainerField { |
| 1472 | }); | 1460 | }); |
| 1473 | } | 1461 | } |
| 1474 | 1462 | ||
| 1475 | pub fn fnProtoSimple(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.FnProto { | 1463 | pub fn fnProtoSimple(tree: *const Ast, buffer: *[1]Node.Index, node: Node.Index) full.FnProto { |
| 1476 | assert(tree.nodeTag(node) == .fn_proto_simple); | 1464 | assert(node.tag(tree) == .fn_proto_simple); |
| 1477 | const first_param, const return_type = tree.nodeData(node).opt_node_and_opt_node; | 1465 | const first_param, const return_type = node.data(tree).opt_node_and_opt_node; |
| 1478 | const params = loadOptionalNodesIntoBuffer(1, buffer, .{first_param}); | 1466 | const params = loadOptionalNodesIntoBuffer(1, buffer, .{first_param}); |
| 1479 | return tree.fullFnProtoComponents(.{ | 1467 | return tree.fullFnProtoComponents(.{ |
| 1480 | .proto_node = node, | 1468 | .proto_node = node, |
| 1481 | .fn_token = tree.nodeMainToken(node), | 1469 | .fn_token = node.mainToken(tree), |
| 1482 | .return_type = return_type, | 1470 | .return_type = return_type, |
| 1483 | .params = params, | 1471 | .params = params, |
| 1484 | .align_expr = .none, | 1472 | .align_expr = .none, |
| ... | @@ -1488,13 +1476,13 @@ pub fn fnProtoSimple(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.F | ... | @@ -1488,13 +1476,13 @@ pub fn fnProtoSimple(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.F |
| 1488 | }); | 1476 | }); |
| 1489 | } | 1477 | } |
| 1490 | 1478 | ||
| 1491 | pub fn fnProtoMulti(tree: Ast, node: Node.Index) full.FnProto { | 1479 | pub fn fnProtoMulti(tree: *const Ast, node: Node.Index) full.FnProto { |
| 1492 | assert(tree.nodeTag(node) == .fn_proto_multi); | 1480 | assert(node.tag(tree) == .fn_proto_multi); |
| 1493 | const extra_index, const return_type = tree.nodeData(node).extra_and_opt_node; | 1481 | const extra_index, const return_type = node.data(tree).extra_and_opt_node; |
| 1494 | const params = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); | 1482 | const params = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); |
| 1495 | return tree.fullFnProtoComponents(.{ | 1483 | return tree.fullFnProtoComponents(.{ |
| 1496 | .proto_node = node, | 1484 | .proto_node = node, |
| 1497 | .fn_token = tree.nodeMainToken(node), | 1485 | .fn_token = node.mainToken(tree), |
| 1498 | .return_type = return_type, | 1486 | .return_type = return_type, |
| 1499 | .params = params, | 1487 | .params = params, |
| 1500 | .align_expr = .none, | 1488 | .align_expr = .none, |
| ... | @@ -1504,14 +1492,14 @@ pub fn fnProtoMulti(tree: Ast, node: Node.Index) full.FnProto { | ... | @@ -1504,14 +1492,14 @@ pub fn fnProtoMulti(tree: Ast, node: Node.Index) full.FnProto { |
| 1504 | }); | 1492 | }); |
| 1505 | } | 1493 | } |
| 1506 | 1494 | ||
| 1507 | pub fn fnProtoOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.FnProto { | 1495 | pub fn fnProtoOne(tree: *const Ast, buffer: *[1]Node.Index, node: Node.Index) full.FnProto { |
| 1508 | assert(tree.nodeTag(node) == .fn_proto_one); | 1496 | assert(node.tag(tree) == .fn_proto_one); |
| 1509 | const extra_index, const return_type = tree.nodeData(node).extra_and_opt_node; | 1497 | const extra_index, const return_type = node.data(tree).extra_and_opt_node; |
| 1510 | const extra = tree.extraData(extra_index, Node.FnProtoOne); | 1498 | const extra = tree.extraData(extra_index, Node.FnProtoOne); |
| 1511 | const params = loadOptionalNodesIntoBuffer(1, buffer, .{extra.param}); | 1499 | const params = loadOptionalNodesIntoBuffer(1, buffer, .{extra.param}); |
| 1512 | return tree.fullFnProtoComponents(.{ | 1500 | return tree.fullFnProtoComponents(.{ |
| 1513 | .proto_node = node, | 1501 | .proto_node = node, |
| 1514 | .fn_token = tree.nodeMainToken(node), | 1502 | .fn_token = node.mainToken(tree), |
| 1515 | .return_type = return_type, | 1503 | .return_type = return_type, |
| 1516 | .params = params, | 1504 | .params = params, |
| 1517 | .align_expr = extra.align_expr, | 1505 | .align_expr = extra.align_expr, |
| ... | @@ -1521,14 +1509,14 @@ pub fn fnProtoOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.FnPr | ... | @@ -1521,14 +1509,14 @@ pub fn fnProtoOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.FnPr |
| 1521 | }); | 1509 | }); |
| 1522 | } | 1510 | } |
| 1523 | 1511 | ||
| 1524 | pub fn fnProto(tree: Ast, node: Node.Index) full.FnProto { | 1512 | pub fn fnProto(tree: *const Ast, node: Node.Index) full.FnProto { |
| 1525 | assert(tree.nodeTag(node) == .fn_proto); | 1513 | assert(node.tag(tree) == .fn_proto); |
| 1526 | const extra_index, const return_type = tree.nodeData(node).extra_and_opt_node; | 1514 | const extra_index, const return_type = node.data(tree).extra_and_opt_node; |
| 1527 | const extra = tree.extraData(extra_index, Node.FnProto); | 1515 | const extra = tree.extraData(extra_index, Node.FnProto); |
| 1528 | const params = tree.extraDataSlice(.{ .start = extra.params_start, .end = extra.params_end }, Node.Index); | 1516 | const params = tree.extraDataSlice(.{ .start = extra.params_start, .end = extra.params_end }, Node.Index); |
| 1529 | return tree.fullFnProtoComponents(.{ | 1517 | return tree.fullFnProtoComponents(.{ |
| 1530 | .proto_node = node, | 1518 | .proto_node = node, |
| 1531 | .fn_token = tree.nodeMainToken(node), | 1519 | .fn_token = node.mainToken(tree), |
| 1532 | .return_type = return_type, | 1520 | .return_type = return_type, |
| 1533 | .params = params, | 1521 | .params = params, |
| 1534 | .align_expr = extra.align_expr, | 1522 | .align_expr = extra.align_expr, |
| ... | @@ -1538,119 +1526,119 @@ pub fn fnProto(tree: Ast, node: Node.Index) full.FnProto { | ... | @@ -1538,119 +1526,119 @@ pub fn fnProto(tree: Ast, node: Node.Index) full.FnProto { |
| 1538 | }); | 1526 | }); |
| 1539 | } | 1527 | } |
| 1540 | 1528 | ||
| 1541 | pub fn structInitOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.StructInit { | 1529 | pub fn structInitOne(tree: *const Ast, buffer: *[1]Node.Index, node: Node.Index) full.StructInit { |
| 1542 | assert(tree.nodeTag(node) == .struct_init_one or | 1530 | assert(node.tag(tree) == .struct_init_one or |
| 1543 | tree.nodeTag(node) == .struct_init_one_comma); | 1531 | node.tag(tree) == .struct_init_one_comma); |
| 1544 | const type_expr, const first_field = tree.nodeData(node).node_and_opt_node; | 1532 | const type_expr, const first_field = node.data(tree).node_and_opt_node; |
| 1545 | const fields = loadOptionalNodesIntoBuffer(1, buffer, .{first_field}); | 1533 | const fields = loadOptionalNodesIntoBuffer(1, buffer, .{first_field}); |
| 1546 | return .{ | 1534 | return .{ |
| 1547 | .ast = .{ | 1535 | .ast = .{ |
| 1548 | .lbrace = tree.nodeMainToken(node), | 1536 | .lbrace = node.mainToken(tree), |
| 1549 | .fields = fields, | 1537 | .fields = fields, |
| 1550 | .type_expr = type_expr.toOptional(), | 1538 | .type_expr = type_expr.toOptional(), |
| 1551 | }, | 1539 | }, |
| 1552 | }; | 1540 | }; |
| 1553 | } | 1541 | } |
| 1554 | 1542 | ||
| 1555 | pub fn structInitDotTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full.StructInit { | 1543 | pub fn structInitDotTwo(tree: *const Ast, buffer: *[2]Node.Index, node: Node.Index) full.StructInit { |
| 1556 | assert(tree.nodeTag(node) == .struct_init_dot_two or | 1544 | assert(node.tag(tree) == .struct_init_dot_two or |
| 1557 | tree.nodeTag(node) == .struct_init_dot_two_comma); | 1545 | node.tag(tree) == .struct_init_dot_two_comma); |
| 1558 | const fields = loadOptionalNodesIntoBuffer(2, buffer, tree.nodeData(node).opt_node_and_opt_node); | 1546 | const fields = loadOptionalNodesIntoBuffer(2, buffer, node.data(tree).opt_node_and_opt_node); |
| 1559 | return .{ | 1547 | return .{ |
| 1560 | .ast = .{ | 1548 | .ast = .{ |
| 1561 | .lbrace = tree.nodeMainToken(node), | 1549 | .lbrace = node.mainToken(tree), |
| 1562 | .fields = fields, | 1550 | .fields = fields, |
| 1563 | .type_expr = .none, | 1551 | .type_expr = .none, |
| 1564 | }, | 1552 | }, |
| 1565 | }; | 1553 | }; |
| 1566 | } | 1554 | } |
| 1567 | 1555 | ||
| 1568 | pub fn structInitDot(tree: Ast, node: Node.Index) full.StructInit { | 1556 | pub fn structInitDot(tree: *const Ast, node: Node.Index) full.StructInit { |
| 1569 | assert(tree.nodeTag(node) == .struct_init_dot or | 1557 | assert(node.tag(tree) == .struct_init_dot or |
| 1570 | tree.nodeTag(node) == .struct_init_dot_comma); | 1558 | node.tag(tree) == .struct_init_dot_comma); |
| 1571 | const fields = tree.extraDataSlice(tree.nodeData(node).extra_range, Node.Index); | 1559 | const fields = tree.extraDataSlice(node.data(tree).extra_range, Node.Index); |
| 1572 | return .{ | 1560 | return .{ |
| 1573 | .ast = .{ | 1561 | .ast = .{ |
| 1574 | .lbrace = tree.nodeMainToken(node), | 1562 | .lbrace = node.mainToken(tree), |
| 1575 | .fields = fields, | 1563 | .fields = fields, |
| 1576 | .type_expr = .none, | 1564 | .type_expr = .none, |
| 1577 | }, | 1565 | }, |
| 1578 | }; | 1566 | }; |
| 1579 | } | 1567 | } |
| 1580 | 1568 | ||
| 1581 | pub fn structInit(tree: Ast, node: Node.Index) full.StructInit { | 1569 | pub fn structInit(tree: *const Ast, node: Node.Index) full.StructInit { |
| 1582 | assert(tree.nodeTag(node) == .struct_init or | 1570 | assert(node.tag(tree) == .struct_init or |
| 1583 | tree.nodeTag(node) == .struct_init_comma); | 1571 | node.tag(tree) == .struct_init_comma); |
| 1584 | const type_expr, const extra_index = tree.nodeData(node).node_and_extra; | 1572 | const type_expr, const extra_index = node.data(tree).node_and_extra; |
| 1585 | const fields = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); | 1573 | const fields = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); |
| 1586 | return .{ | 1574 | return .{ |
| 1587 | .ast = .{ | 1575 | .ast = .{ |
| 1588 | .lbrace = tree.nodeMainToken(node), | 1576 | .lbrace = node.mainToken(tree), |
| 1589 | .fields = fields, | 1577 | .fields = fields, |
| 1590 | .type_expr = type_expr.toOptional(), | 1578 | .type_expr = type_expr.toOptional(), |
| 1591 | }, | 1579 | }, |
| 1592 | }; | 1580 | }; |
| 1593 | } | 1581 | } |
| 1594 | 1582 | ||
| 1595 | pub fn arrayInitOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.ArrayInit { | 1583 | pub fn arrayInitOne(tree: *const Ast, buffer: *[1]Node.Index, node: Node.Index) full.ArrayInit { |
| 1596 | assert(tree.nodeTag(node) == .array_init_one or | 1584 | assert(node.tag(tree) == .array_init_one or |
| 1597 | tree.nodeTag(node) == .array_init_one_comma); | 1585 | node.tag(tree) == .array_init_one_comma); |
| 1598 | const type_expr, buffer[0] = tree.nodeData(node).node_and_node; | 1586 | const type_expr, buffer[0] = node.data(tree).node_and_node; |
| 1599 | return .{ | 1587 | return .{ |
| 1600 | .ast = .{ | 1588 | .ast = .{ |
| 1601 | .lbrace = tree.nodeMainToken(node), | 1589 | .lbrace = node.mainToken(tree), |
| 1602 | .elements = buffer[0..1], | 1590 | .elements = buffer[0..1], |
| 1603 | .type_expr = type_expr.toOptional(), | 1591 | .type_expr = type_expr.toOptional(), |
| 1604 | }, | 1592 | }, |
| 1605 | }; | 1593 | }; |
| 1606 | } | 1594 | } |
| 1607 | 1595 | ||
| 1608 | pub fn arrayInitDotTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full.ArrayInit { | 1596 | pub fn arrayInitDotTwo(tree: *const Ast, buffer: *[2]Node.Index, node: Node.Index) full.ArrayInit { |
| 1609 | assert(tree.nodeTag(node) == .array_init_dot_two or | 1597 | assert(node.tag(tree) == .array_init_dot_two or |
| 1610 | tree.nodeTag(node) == .array_init_dot_two_comma); | 1598 | node.tag(tree) == .array_init_dot_two_comma); |
| 1611 | const elements = loadOptionalNodesIntoBuffer(2, buffer, tree.nodeData(node).opt_node_and_opt_node); | 1599 | const elements = loadOptionalNodesIntoBuffer(2, buffer, node.data(tree).opt_node_and_opt_node); |
| 1612 | return .{ | 1600 | return .{ |
| 1613 | .ast = .{ | 1601 | .ast = .{ |
| 1614 | .lbrace = tree.nodeMainToken(node), | 1602 | .lbrace = node.mainToken(tree), |
| 1615 | .elements = elements, | 1603 | .elements = elements, |
| 1616 | .type_expr = .none, | 1604 | .type_expr = .none, |
| 1617 | }, | 1605 | }, |
| 1618 | }; | 1606 | }; |
| 1619 | } | 1607 | } |
| 1620 | 1608 | ||
| 1621 | pub fn arrayInitDot(tree: Ast, node: Node.Index) full.ArrayInit { | 1609 | pub fn arrayInitDot(tree: *const Ast, node: Node.Index) full.ArrayInit { |
| 1622 | assert(tree.nodeTag(node) == .array_init_dot or | 1610 | assert(node.tag(tree) == .array_init_dot or |
| 1623 | tree.nodeTag(node) == .array_init_dot_comma); | 1611 | node.tag(tree) == .array_init_dot_comma); |
| 1624 | const elements = tree.extraDataSlice(tree.nodeData(node).extra_range, Node.Index); | 1612 | const elements = tree.extraDataSlice(node.data(tree).extra_range, Node.Index); |
| 1625 | return .{ | 1613 | return .{ |
| 1626 | .ast = .{ | 1614 | .ast = .{ |
| 1627 | .lbrace = tree.nodeMainToken(node), | 1615 | .lbrace = node.mainToken(tree), |
| 1628 | .elements = elements, | 1616 | .elements = elements, |
| 1629 | .type_expr = .none, | 1617 | .type_expr = .none, |
| 1630 | }, | 1618 | }, |
| 1631 | }; | 1619 | }; |
| 1632 | } | 1620 | } |
| 1633 | 1621 | ||
| 1634 | pub fn arrayInit(tree: Ast, node: Node.Index) full.ArrayInit { | 1622 | pub fn arrayInit(tree: *const Ast, node: Node.Index) full.ArrayInit { |
| 1635 | assert(tree.nodeTag(node) == .array_init or | 1623 | assert(node.tag(tree) == .array_init or |
| 1636 | tree.nodeTag(node) == .array_init_comma); | 1624 | node.tag(tree) == .array_init_comma); |
| 1637 | const type_expr, const extra_index = tree.nodeData(node).node_and_extra; | 1625 | const type_expr, const extra_index = node.data(tree).node_and_extra; |
| 1638 | const elements = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); | 1626 | const elements = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); |
| 1639 | return .{ | 1627 | return .{ |
| 1640 | .ast = .{ | 1628 | .ast = .{ |
| 1641 | .lbrace = tree.nodeMainToken(node), | 1629 | .lbrace = node.mainToken(tree), |
| 1642 | .elements = elements, | 1630 | .elements = elements, |
| 1643 | .type_expr = type_expr.toOptional(), | 1631 | .type_expr = type_expr.toOptional(), |
| 1644 | }, | 1632 | }, |
| 1645 | }; | 1633 | }; |
| 1646 | } | 1634 | } |
| 1647 | 1635 | ||
| 1648 | pub fn arrayType(tree: Ast, node: Node.Index) full.ArrayType { | 1636 | pub fn arrayType(tree: *const Ast, node: Node.Index) full.ArrayType { |
| 1649 | assert(tree.nodeTag(node) == .array_type); | 1637 | assert(node.tag(tree) == .array_type); |
| 1650 | const elem_count, const elem_type = tree.nodeData(node).node_and_node; | 1638 | const elem_count, const elem_type = node.data(tree).node_and_node; |
| 1651 | return .{ | 1639 | return .{ |
| 1652 | .ast = .{ | 1640 | .ast = .{ |
| 1653 | .lbracket = tree.nodeMainToken(node), | 1641 | .lbracket = node.mainToken(tree), |
| 1654 | .elem_count = elem_count, | 1642 | .elem_count = elem_count, |
| 1655 | .sentinel = .none, | 1643 | .sentinel = .none, |
| 1656 | .elem_type = elem_type, | 1644 | .elem_type = elem_type, |
| ... | @@ -1658,13 +1646,13 @@ pub fn arrayType(tree: Ast, node: Node.Index) full.ArrayType { | ... | @@ -1658,13 +1646,13 @@ pub fn arrayType(tree: Ast, node: Node.Index) full.ArrayType { |
| 1658 | }; | 1646 | }; |
| 1659 | } | 1647 | } |
| 1660 | 1648 | ||
| 1661 | pub fn arrayTypeSentinel(tree: Ast, node: Node.Index) full.ArrayType { | 1649 | pub fn arrayTypeSentinel(tree: *const Ast, node: Node.Index) full.ArrayType { |
| 1662 | assert(tree.nodeTag(node) == .array_type_sentinel); | 1650 | assert(node.tag(tree) == .array_type_sentinel); |
| 1663 | const elem_count, const extra_index = tree.nodeData(node).node_and_extra; | 1651 | const elem_count, const extra_index = node.data(tree).node_and_extra; |
| 1664 | const extra = tree.extraData(extra_index, Node.ArrayTypeSentinel); | 1652 | const extra = tree.extraData(extra_index, Node.ArrayTypeSentinel); |
| 1665 | return .{ | 1653 | return .{ |
| 1666 | .ast = .{ | 1654 | .ast = .{ |
| 1667 | .lbracket = tree.nodeMainToken(node), | 1655 | .lbracket = node.mainToken(tree), |
| 1668 | .elem_count = elem_count, | 1656 | .elem_count = elem_count, |
| 1669 | .sentinel = extra.sentinel.toOptional(), | 1657 | .sentinel = extra.sentinel.toOptional(), |
| 1670 | .elem_type = extra.elem_type, | 1658 | .elem_type = extra.elem_type, |
| ... | @@ -1672,11 +1660,11 @@ pub fn arrayTypeSentinel(tree: Ast, node: Node.Index) full.ArrayType { | ... | @@ -1672,11 +1660,11 @@ pub fn arrayTypeSentinel(tree: Ast, node: Node.Index) full.ArrayType { |
| 1672 | }; | 1660 | }; |
| 1673 | } | 1661 | } |
| 1674 | 1662 | ||
| 1675 | pub fn ptrTypeAligned(tree: Ast, node: Node.Index) full.PtrType { | 1663 | pub fn ptrTypeAligned(tree: *const Ast, node: Node.Index) full.PtrType { |
| 1676 | assert(tree.nodeTag(node) == .ptr_type_aligned); | 1664 | assert(node.tag(tree) == .ptr_type_aligned); |
| 1677 | const align_node, const child_type = tree.nodeData(node).opt_node_and_node; | 1665 | const align_node, const child_type = node.data(tree).opt_node_and_node; |
| 1678 | return tree.fullPtrTypeComponents(.{ | 1666 | return tree.fullPtrTypeComponents(.{ |
| 1679 | .main_token = tree.nodeMainToken(node), | 1667 | .main_token = node.mainToken(tree), |
| 1680 | .align_node = align_node, | 1668 | .align_node = align_node, |
| 1681 | .addrspace_node = .none, | 1669 | .addrspace_node = .none, |
| 1682 | .sentinel = .none, | 1670 | .sentinel = .none, |
| ... | @@ -1686,11 +1674,11 @@ pub fn ptrTypeAligned(tree: Ast, node: Node.Index) full.PtrType { | ... | @@ -1686,11 +1674,11 @@ pub fn ptrTypeAligned(tree: Ast, node: Node.Index) full.PtrType { |
| 1686 | }); | 1674 | }); |
| 1687 | } | 1675 | } |
| 1688 | 1676 | ||
| 1689 | pub fn ptrTypeSentinel(tree: Ast, node: Node.Index) full.PtrType { | 1677 | pub fn ptrTypeSentinel(tree: *const Ast, node: Node.Index) full.PtrType { |
| 1690 | assert(tree.nodeTag(node) == .ptr_type_sentinel); | 1678 | assert(node.tag(tree) == .ptr_type_sentinel); |
| 1691 | const sentinel, const child_type = tree.nodeData(node).opt_node_and_node; | 1679 | const sentinel, const child_type = node.data(tree).opt_node_and_node; |
| 1692 | return tree.fullPtrTypeComponents(.{ | 1680 | return tree.fullPtrTypeComponents(.{ |
| 1693 | .main_token = tree.nodeMainToken(node), | 1681 | .main_token = node.mainToken(tree), |
| 1694 | .align_node = .none, | 1682 | .align_node = .none, |
| 1695 | .addrspace_node = .none, | 1683 | .addrspace_node = .none, |
| 1696 | .sentinel = sentinel, | 1684 | .sentinel = sentinel, |
| ... | @@ -1700,12 +1688,12 @@ pub fn ptrTypeSentinel(tree: Ast, node: Node.Index) full.PtrType { | ... | @@ -1700,12 +1688,12 @@ pub fn ptrTypeSentinel(tree: Ast, node: Node.Index) full.PtrType { |
| 1700 | }); | 1688 | }); |
| 1701 | } | 1689 | } |
| 1702 | 1690 | ||
| 1703 | pub fn ptrType(tree: Ast, node: Node.Index) full.PtrType { | 1691 | pub fn ptrType(tree: *const Ast, node: Node.Index) full.PtrType { |
| 1704 | assert(tree.nodeTag(node) == .ptr_type); | 1692 | assert(node.tag(tree) == .ptr_type); |
| 1705 | const extra_index, const child_type = tree.nodeData(node).extra_and_node; | 1693 | const extra_index, const child_type = node.data(tree).extra_and_node; |
| 1706 | const extra = tree.extraData(extra_index, Node.PtrType); | 1694 | const extra = tree.extraData(extra_index, Node.PtrType); |
| 1707 | return tree.fullPtrTypeComponents(.{ | 1695 | return tree.fullPtrTypeComponents(.{ |
| 1708 | .main_token = tree.nodeMainToken(node), | 1696 | .main_token = node.mainToken(tree), |
| 1709 | .align_node = extra.align_node, | 1697 | .align_node = extra.align_node, |
| 1710 | .addrspace_node = extra.addrspace_node, | 1698 | .addrspace_node = extra.addrspace_node, |
| 1711 | .sentinel = extra.sentinel, | 1699 | .sentinel = extra.sentinel, |
| ... | @@ -1715,12 +1703,12 @@ pub fn ptrType(tree: Ast, node: Node.Index) full.PtrType { | ... | @@ -1715,12 +1703,12 @@ pub fn ptrType(tree: Ast, node: Node.Index) full.PtrType { |
| 1715 | }); | 1703 | }); |
| 1716 | } | 1704 | } |
| 1717 | 1705 | ||
| 1718 | pub fn ptrTypeBitRange(tree: Ast, node: Node.Index) full.PtrType { | 1706 | pub fn ptrTypeBitRange(tree: *const Ast, node: Node.Index) full.PtrType { |
| 1719 | assert(tree.nodeTag(node) == .ptr_type_bit_range); | 1707 | assert(node.tag(tree) == .ptr_type_bit_range); |
| 1720 | const extra_index, const child_type = tree.nodeData(node).extra_and_node; | 1708 | const extra_index, const child_type = node.data(tree).extra_and_node; |
| 1721 | const extra = tree.extraData(extra_index, Node.PtrTypeBitRange); | 1709 | const extra = tree.extraData(extra_index, Node.PtrTypeBitRange); |
| 1722 | return tree.fullPtrTypeComponents(.{ | 1710 | return tree.fullPtrTypeComponents(.{ |
| 1723 | .main_token = tree.nodeMainToken(node), | 1711 | .main_token = node.mainToken(tree), |
| 1724 | .align_node = extra.align_node.toOptional(), | 1712 | .align_node = extra.align_node.toOptional(), |
| 1725 | .addrspace_node = extra.addrspace_node, | 1713 | .addrspace_node = extra.addrspace_node, |
| 1726 | .sentinel = extra.sentinel, | 1714 | .sentinel = extra.sentinel, |
| ... | @@ -1730,13 +1718,13 @@ pub fn ptrTypeBitRange(tree: Ast, node: Node.Index) full.PtrType { | ... | @@ -1730,13 +1718,13 @@ pub fn ptrTypeBitRange(tree: Ast, node: Node.Index) full.PtrType { |
| 1730 | }); | 1718 | }); |
| 1731 | } | 1719 | } |
| 1732 | 1720 | ||
| 1733 | pub fn sliceOpen(tree: Ast, node: Node.Index) full.Slice { | 1721 | pub fn sliceOpen(tree: *const Ast, node: Node.Index) full.Slice { |
| 1734 | assert(tree.nodeTag(node) == .slice_open); | 1722 | assert(node.tag(tree) == .slice_open); |
| 1735 | const sliced, const start = tree.nodeData(node).node_and_node; | 1723 | const sliced, const start = node.data(tree).node_and_node; |
| 1736 | return .{ | 1724 | return .{ |
| 1737 | .ast = .{ | 1725 | .ast = .{ |
| 1738 | .sliced = sliced, | 1726 | .sliced = sliced, |
| 1739 | .lbracket = tree.nodeMainToken(node), | 1727 | .lbracket = node.mainToken(tree), |
| 1740 | .start = start, | 1728 | .start = start, |
| 1741 | .end = .none, | 1729 | .end = .none, |
| 1742 | .sentinel = .none, | 1730 | .sentinel = .none, |
| ... | @@ -1744,14 +1732,14 @@ pub fn sliceOpen(tree: Ast, node: Node.Index) full.Slice { | ... | @@ -1744,14 +1732,14 @@ pub fn sliceOpen(tree: Ast, node: Node.Index) full.Slice { |
| 1744 | }; | 1732 | }; |
| 1745 | } | 1733 | } |
| 1746 | 1734 | ||
| 1747 | pub fn slice(tree: Ast, node: Node.Index) full.Slice { | 1735 | pub fn slice(tree: *const Ast, node: Node.Index) full.Slice { |
| 1748 | assert(tree.nodeTag(node) == .slice); | 1736 | assert(node.tag(tree) == .slice); |
| 1749 | const sliced, const extra_index = tree.nodeData(node).node_and_extra; | 1737 | const sliced, const extra_index = node.data(tree).node_and_extra; |
| 1750 | const extra = tree.extraData(extra_index, Node.Slice); | 1738 | const extra = tree.extraData(extra_index, Node.Slice); |
| 1751 | return .{ | 1739 | return .{ |
| 1752 | .ast = .{ | 1740 | .ast = .{ |
| 1753 | .sliced = sliced, | 1741 | .sliced = sliced, |
| 1754 | .lbracket = tree.nodeMainToken(node), | 1742 | .lbracket = node.mainToken(tree), |
| 1755 | .start = extra.start, | 1743 | .start = extra.start, |
| 1756 | .end = extra.end.toOptional(), | 1744 | .end = extra.end.toOptional(), |
| 1757 | .sentinel = .none, | 1745 | .sentinel = .none, |
| ... | @@ -1759,14 +1747,14 @@ pub fn slice(tree: Ast, node: Node.Index) full.Slice { | ... | @@ -1759,14 +1747,14 @@ pub fn slice(tree: Ast, node: Node.Index) full.Slice { |
| 1759 | }; | 1747 | }; |
| 1760 | } | 1748 | } |
| 1761 | 1749 | ||
| 1762 | pub fn sliceSentinel(tree: Ast, node: Node.Index) full.Slice { | 1750 | pub fn sliceSentinel(tree: *const Ast, node: Node.Index) full.Slice { |
| 1763 | assert(tree.nodeTag(node) == .slice_sentinel); | 1751 | assert(node.tag(tree) == .slice_sentinel); |
| 1764 | const sliced, const extra_index = tree.nodeData(node).node_and_extra; | 1752 | const sliced, const extra_index = node.data(tree).node_and_extra; |
| 1765 | const extra = tree.extraData(extra_index, Node.SliceSentinel); | 1753 | const extra = tree.extraData(extra_index, Node.SliceSentinel); |
| 1766 | return .{ | 1754 | return .{ |
| 1767 | .ast = .{ | 1755 | .ast = .{ |
| 1768 | .sliced = sliced, | 1756 | .sliced = sliced, |
| 1769 | .lbracket = tree.nodeMainToken(node), | 1757 | .lbracket = node.mainToken(tree), |
| 1770 | .start = extra.start, | 1758 | .start = extra.start, |
| 1771 | .end = extra.end, | 1759 | .end = extra.end, |
| 1772 | .sentinel = extra.sentinel.toOptional(), | 1760 | .sentinel = extra.sentinel.toOptional(), |
| ... | @@ -1774,44 +1762,44 @@ pub fn sliceSentinel(tree: Ast, node: Node.Index) full.Slice { | ... | @@ -1774,44 +1762,44 @@ pub fn sliceSentinel(tree: Ast, node: Node.Index) full.Slice { |
| 1774 | }; | 1762 | }; |
| 1775 | } | 1763 | } |
| 1776 | 1764 | ||
| 1777 | pub fn containerDeclTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full.ContainerDecl { | 1765 | pub fn containerDeclTwo(tree: *const Ast, buffer: *[2]Node.Index, node: Node.Index) full.ContainerDecl { |
| 1778 | assert(tree.nodeTag(node) == .container_decl_two or | 1766 | assert(node.tag(tree) == .container_decl_two or |
| 1779 | tree.nodeTag(node) == .container_decl_two_trailing); | 1767 | node.tag(tree) == .container_decl_two_trailing); |
| 1780 | const members = loadOptionalNodesIntoBuffer(2, buffer, tree.nodeData(node).opt_node_and_opt_node); | 1768 | const members = loadOptionalNodesIntoBuffer(2, buffer, node.data(tree).opt_node_and_opt_node); |
| 1781 | return tree.fullContainerDeclComponents(.{ | 1769 | return tree.fullContainerDeclComponents(.{ |
| 1782 | .main_token = tree.nodeMainToken(node), | 1770 | .main_token = node.mainToken(tree), |
| 1783 | .enum_token = null, | 1771 | .enum_token = null, |
| 1784 | .members = members, | 1772 | .members = members, |
| 1785 | .arg = .none, | 1773 | .arg = .none, |
| 1786 | }); | 1774 | }); |
| 1787 | } | 1775 | } |
| 1788 | 1776 | ||
| 1789 | pub fn containerDecl(tree: Ast, node: Node.Index) full.ContainerDecl { | 1777 | pub fn containerDecl(tree: *const Ast, node: Node.Index) full.ContainerDecl { |
| 1790 | assert(tree.nodeTag(node) == .container_decl or | 1778 | assert(node.tag(tree) == .container_decl or |
| 1791 | tree.nodeTag(node) == .container_decl_trailing); | 1779 | node.tag(tree) == .container_decl_trailing); |
| 1792 | const members = tree.extraDataSlice(tree.nodeData(node).extra_range, Node.Index); | 1780 | const members = tree.extraDataSlice(node.data(tree).extra_range, Node.Index); |
| 1793 | return tree.fullContainerDeclComponents(.{ | 1781 | return tree.fullContainerDeclComponents(.{ |
| 1794 | .main_token = tree.nodeMainToken(node), | 1782 | .main_token = node.mainToken(tree), |
| 1795 | .enum_token = null, | 1783 | .enum_token = null, |
| 1796 | .members = members, | 1784 | .members = members, |
| 1797 | .arg = .none, | 1785 | .arg = .none, |
| 1798 | }); | 1786 | }); |
| 1799 | } | 1787 | } |
| 1800 | 1788 | ||
| 1801 | pub fn containerDeclArg(tree: Ast, node: Node.Index) full.ContainerDecl { | 1789 | pub fn containerDeclArg(tree: *const Ast, node: Node.Index) full.ContainerDecl { |
| 1802 | assert(tree.nodeTag(node) == .container_decl_arg or | 1790 | assert(node.tag(tree) == .container_decl_arg or |
| 1803 | tree.nodeTag(node) == .container_decl_arg_trailing); | 1791 | node.tag(tree) == .container_decl_arg_trailing); |
| 1804 | const arg, const extra_index = tree.nodeData(node).node_and_extra; | 1792 | const arg, const extra_index = node.data(tree).node_and_extra; |
| 1805 | const members = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); | 1793 | const members = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); |
| 1806 | return tree.fullContainerDeclComponents(.{ | 1794 | return tree.fullContainerDeclComponents(.{ |
| 1807 | .main_token = tree.nodeMainToken(node), | 1795 | .main_token = node.mainToken(tree), |
| 1808 | .enum_token = null, | 1796 | .enum_token = null, |
| 1809 | .members = members, | 1797 | .members = members, |
| 1810 | .arg = arg.toOptional(), | 1798 | .arg = arg.toOptional(), |
| 1811 | }); | 1799 | }); |
| 1812 | } | 1800 | } |
| 1813 | 1801 | ||
| 1814 | pub fn containerDeclRoot(tree: Ast) full.ContainerDecl { | 1802 | pub fn containerDeclRoot(tree: *const Ast) full.ContainerDecl { |
| 1815 | return .{ | 1803 | return .{ |
| 1816 | .layout_token = null, | 1804 | .layout_token = null, |
| 1817 | .ast = .{ | 1805 | .ast = .{ |
| ... | @@ -1823,11 +1811,11 @@ pub fn containerDeclRoot(tree: Ast) full.ContainerDecl { | ... | @@ -1823,11 +1811,11 @@ pub fn containerDeclRoot(tree: Ast) full.ContainerDecl { |
| 1823 | }; | 1811 | }; |
| 1824 | } | 1812 | } |
| 1825 | 1813 | ||
| 1826 | pub fn taggedUnionTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full.ContainerDecl { | 1814 | pub fn taggedUnionTwo(tree: *const Ast, buffer: *[2]Node.Index, node: Node.Index) full.ContainerDecl { |
| 1827 | assert(tree.nodeTag(node) == .tagged_union_two or | 1815 | assert(node.tag(tree) == .tagged_union_two or |
| 1828 | tree.nodeTag(node) == .tagged_union_two_trailing); | 1816 | node.tag(tree) == .tagged_union_two_trailing); |
| 1829 | const members = loadOptionalNodesIntoBuffer(2, buffer, tree.nodeData(node).opt_node_and_opt_node); | 1817 | const members = loadOptionalNodesIntoBuffer(2, buffer, node.data(tree).opt_node_and_opt_node); |
| 1830 | const main_token = tree.nodeMainToken(node); | 1818 | const main_token = node.mainToken(tree); |
| 1831 | return tree.fullContainerDeclComponents(.{ | 1819 | return tree.fullContainerDeclComponents(.{ |
| 1832 | .main_token = main_token, | 1820 | .main_token = main_token, |
| 1833 | .enum_token = main_token + 2, // union lparen enum | 1821 | .enum_token = main_token + 2, // union lparen enum |
| ... | @@ -1836,11 +1824,11 @@ pub fn taggedUnionTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full. | ... | @@ -1836,11 +1824,11 @@ pub fn taggedUnionTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full. |
| 1836 | }); | 1824 | }); |
| 1837 | } | 1825 | } |
| 1838 | 1826 | ||
| 1839 | pub fn taggedUnion(tree: Ast, node: Node.Index) full.ContainerDecl { | 1827 | pub fn taggedUnion(tree: *const Ast, node: Node.Index) full.ContainerDecl { |
| 1840 | assert(tree.nodeTag(node) == .tagged_union or | 1828 | assert(node.tag(tree) == .tagged_union or |
| 1841 | tree.nodeTag(node) == .tagged_union_trailing); | 1829 | node.tag(tree) == .tagged_union_trailing); |
| 1842 | const members = tree.extraDataSlice(tree.nodeData(node).extra_range, Node.Index); | 1830 | const members = tree.extraDataSlice(node.data(tree).extra_range, Node.Index); |
| 1843 | const main_token = tree.nodeMainToken(node); | 1831 | const main_token = node.mainToken(tree); |
| 1844 | return tree.fullContainerDeclComponents(.{ | 1832 | return tree.fullContainerDeclComponents(.{ |
| 1845 | .main_token = main_token, | 1833 | .main_token = main_token, |
| 1846 | .enum_token = main_token + 2, // union lparen enum | 1834 | .enum_token = main_token + 2, // union lparen enum |
| ... | @@ -1849,12 +1837,12 @@ pub fn taggedUnion(tree: Ast, node: Node.Index) full.ContainerDecl { | ... | @@ -1849,12 +1837,12 @@ pub fn taggedUnion(tree: Ast, node: Node.Index) full.ContainerDecl { |
| 1849 | }); | 1837 | }); |
| 1850 | } | 1838 | } |
| 1851 | 1839 | ||
| 1852 | pub fn taggedUnionEnumTag(tree: Ast, node: Node.Index) full.ContainerDecl { | 1840 | pub fn taggedUnionEnumTag(tree: *const Ast, node: Node.Index) full.ContainerDecl { |
| 1853 | assert(tree.nodeTag(node) == .tagged_union_enum_tag or | 1841 | assert(node.tag(tree) == .tagged_union_enum_tag or |
| 1854 | tree.nodeTag(node) == .tagged_union_enum_tag_trailing); | 1842 | node.tag(tree) == .tagged_union_enum_tag_trailing); |
| 1855 | const arg, const extra_index = tree.nodeData(node).node_and_extra; | 1843 | const arg, const extra_index = node.data(tree).node_and_extra; |
| 1856 | const members = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); | 1844 | const members = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); |
| 1857 | const main_token = tree.nodeMainToken(node); | 1845 | const main_token = node.mainToken(tree); |
| 1858 | return tree.fullContainerDeclComponents(.{ | 1846 | return tree.fullContainerDeclComponents(.{ |
| 1859 | .main_token = main_token, | 1847 | .main_token = main_token, |
| 1860 | .enum_token = main_token + 2, // union lparen enum | 1848 | .enum_token = main_token + 2, // union lparen enum |
| ... | @@ -1863,14 +1851,14 @@ pub fn taggedUnionEnumTag(tree: Ast, node: Node.Index) full.ContainerDecl { | ... | @@ -1863,14 +1851,14 @@ pub fn taggedUnionEnumTag(tree: Ast, node: Node.Index) full.ContainerDecl { |
| 1863 | }); | 1851 | }); |
| 1864 | } | 1852 | } |
| 1865 | 1853 | ||
| 1866 | pub fn switchFull(tree: Ast, node: Node.Index) full.Switch { | 1854 | pub fn switchFull(tree: *const Ast, node: Node.Index) full.Switch { |
| 1867 | const main_token = tree.nodeMainToken(node); | 1855 | const main_token = node.mainToken(tree); |
| 1868 | const switch_token: TokenIndex, const label_token: ?TokenIndex = switch (tree.tokenTag(main_token)) { | 1856 | const switch_token: TokenIndex, const label_token: ?TokenIndex = switch (tree.tokenTag(main_token)) { |
| 1869 | .identifier => .{ main_token + 2, main_token }, | 1857 | .identifier => .{ main_token + 2, main_token }, |
| 1870 | .keyword_switch => .{ main_token, null }, | 1858 | .keyword_switch => .{ main_token, null }, |
| 1871 | else => unreachable, | 1859 | else => unreachable, |
| 1872 | }; | 1860 | }; |
| 1873 | const condition, const extra_index = tree.nodeData(node).node_and_extra; | 1861 | const condition, const extra_index = node.data(tree).node_and_extra; |
| 1874 | const cases = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Node.Index); | 1862 | const cases = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Node.Index); |
| 1875 | return .{ | 1863 | return .{ |
| 1876 | .ast = .{ | 1864 | .ast = .{ |
| ... | @@ -1882,55 +1870,55 @@ pub fn switchFull(tree: Ast, node: Node.Index) full.Switch { | ... | @@ -1882,55 +1870,55 @@ pub fn switchFull(tree: Ast, node: Node.Index) full.Switch { |
| 1882 | }; | 1870 | }; |
| 1883 | } | 1871 | } |
| 1884 | 1872 | ||
| 1885 | pub fn switchCaseOne(tree: Ast, node: Node.Index) full.SwitchCase { | 1873 | pub fn switchCaseOne(tree: *const Ast, node: Node.Index) full.SwitchCase { |
| 1886 | const first_value, const target_expr = tree.nodeData(node).opt_node_and_node; | 1874 | const first_value, const target_expr = node.data(tree).opt_node_and_node; |
| 1887 | return tree.fullSwitchCaseComponents(.{ | 1875 | return tree.fullSwitchCaseComponents(.{ |
| 1888 | .values = if (first_value == .none) | 1876 | .values = if (first_value == .none) |
| 1889 | &.{} | 1877 | &.{} |
| 1890 | else | 1878 | else |
| 1891 | // Ensure that the returned slice points into the existing memory of the Ast | 1879 | // Ensure that the returned slice points into the existing memory of the Ast |
| 1892 | (@as(*const Node.Index, @ptrCast(&tree.nodes.items(.data)[@intFromEnum(node)].opt_node_and_node[0])))[0..1], | 1880 | (@as(*const Node.Index, @ptrCast(&tree.nodes.items(.data)[@intFromEnum(node)].opt_node_and_node[0])))[0..1], |
| 1893 | .arrow_token = tree.nodeMainToken(node), | 1881 | .arrow_token = node.mainToken(tree), |
| 1894 | .target_expr = target_expr, | 1882 | .target_expr = target_expr, |
| 1895 | }, node); | 1883 | }, node); |
| 1896 | } | 1884 | } |
| 1897 | 1885 | ||
| 1898 | pub fn switchCase(tree: Ast, node: Node.Index) full.SwitchCase { | 1886 | pub fn switchCase(tree: *const Ast, node: Node.Index) full.SwitchCase { |
| 1899 | const extra_index, const target_expr = tree.nodeData(node).extra_and_node; | 1887 | const extra_index, const target_expr = node.data(tree).extra_and_node; |
| 1900 | const values = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); | 1888 | const values = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); |
| 1901 | return tree.fullSwitchCaseComponents(.{ | 1889 | return tree.fullSwitchCaseComponents(.{ |
| 1902 | .values = values, | 1890 | .values = values, |
| 1903 | .arrow_token = tree.nodeMainToken(node), | 1891 | .arrow_token = node.mainToken(tree), |
| 1904 | .target_expr = target_expr, | 1892 | .target_expr = target_expr, |
| 1905 | }, node); | 1893 | }, node); |
| 1906 | } | 1894 | } |
| 1907 | 1895 | ||
| 1908 | pub fn asmSimple(tree: Ast, node: Node.Index) full.Asm { | 1896 | pub fn asmSimple(tree: *const Ast, node: Node.Index) full.Asm { |
| 1909 | const template, const rparen = tree.nodeData(node).node_and_token; | 1897 | const template, const rparen = node.data(tree).node_and_token; |
| 1910 | return tree.fullAsmComponents(.{ | 1898 | return tree.fullAsmComponents(.{ |
| 1911 | .asm_token = tree.nodeMainToken(node), | 1899 | .asm_token = node.mainToken(tree), |
| 1912 | .template = template, | 1900 | .template = template, |
| 1913 | .items = &.{}, | 1901 | .items = &.{}, |
| 1914 | .rparen = rparen, | 1902 | .rparen = rparen, |
| 1915 | }); | 1903 | }); |
| 1916 | } | 1904 | } |
| 1917 | 1905 | ||
| 1918 | pub fn asmFull(tree: Ast, node: Node.Index) full.Asm { | 1906 | pub fn asmFull(tree: *const Ast, node: Node.Index) full.Asm { |
| 1919 | const template, const extra_index = tree.nodeData(node).node_and_extra; | 1907 | const template, const extra_index = node.data(tree).node_and_extra; |
| 1920 | const extra = tree.extraData(extra_index, Node.Asm); | 1908 | const extra = tree.extraData(extra_index, Node.Asm); |
| 1921 | const items = tree.extraDataSlice(.{ .start = extra.items_start, .end = extra.items_end }, Node.Index); | 1909 | const items = tree.extraDataSlice(.{ .start = extra.items_start, .end = extra.items_end }, Node.Index); |
| 1922 | return tree.fullAsmComponents(.{ | 1910 | return tree.fullAsmComponents(.{ |
| 1923 | .asm_token = tree.nodeMainToken(node), | 1911 | .asm_token = node.mainToken(tree), |
| 1924 | .template = template, | 1912 | .template = template, |
| 1925 | .items = items, | 1913 | .items = items, |
| 1926 | .rparen = extra.rparen, | 1914 | .rparen = extra.rparen, |
| 1927 | }); | 1915 | }); |
| 1928 | } | 1916 | } |
| 1929 | 1917 | ||
| 1930 | pub fn whileSimple(tree: Ast, node: Node.Index) full.While { | 1918 | pub fn whileSimple(tree: *const Ast, node: Node.Index) full.While { |
| 1931 | const cond_expr, const then_expr = tree.nodeData(node).node_and_node; | 1919 | const cond_expr, const then_expr = node.data(tree).node_and_node; |
| 1932 | return tree.fullWhileComponents(.{ | 1920 | return tree.fullWhileComponents(.{ |
| 1933 | .while_token = tree.nodeMainToken(node), | 1921 | .while_token = node.mainToken(tree), |
| 1934 | .cond_expr = cond_expr, | 1922 | .cond_expr = cond_expr, |
| 1935 | .cont_expr = .none, | 1923 | .cont_expr = .none, |
| 1936 | .then_expr = then_expr, | 1924 | .then_expr = then_expr, |
| ... | @@ -1938,11 +1926,11 @@ pub fn whileSimple(tree: Ast, node: Node.Index) full.While { | ... | @@ -1938,11 +1926,11 @@ pub fn whileSimple(tree: Ast, node: Node.Index) full.While { |
| 1938 | }); | 1926 | }); |
| 1939 | } | 1927 | } |
| 1940 | 1928 | ||
| 1941 | pub fn whileCont(tree: Ast, node: Node.Index) full.While { | 1929 | pub fn whileCont(tree: *const Ast, node: Node.Index) full.While { |
| 1942 | const cond_expr, const extra_index = tree.nodeData(node).node_and_extra; | 1930 | const cond_expr, const extra_index = node.data(tree).node_and_extra; |
| 1943 | const extra = tree.extraData(extra_index, Node.WhileCont); | 1931 | const extra = tree.extraData(extra_index, Node.WhileCont); |
| 1944 | return tree.fullWhileComponents(.{ | 1932 | return tree.fullWhileComponents(.{ |
| 1945 | .while_token = tree.nodeMainToken(node), | 1933 | .while_token = node.mainToken(tree), |
| 1946 | .cond_expr = cond_expr, | 1934 | .cond_expr = cond_expr, |
| 1947 | .cont_expr = extra.cont_expr.toOptional(), | 1935 | .cont_expr = extra.cont_expr.toOptional(), |
| 1948 | .then_expr = extra.then_expr, | 1936 | .then_expr = extra.then_expr, |
| ... | @@ -1950,11 +1938,11 @@ pub fn whileCont(tree: Ast, node: Node.Index) full.While { | ... | @@ -1950,11 +1938,11 @@ pub fn whileCont(tree: Ast, node: Node.Index) full.While { |
| 1950 | }); | 1938 | }); |
| 1951 | } | 1939 | } |
| 1952 | 1940 | ||
| 1953 | pub fn whileFull(tree: Ast, node: Node.Index) full.While { | 1941 | pub fn whileFull(tree: *const Ast, node: Node.Index) full.While { |
| 1954 | const cond_expr, const extra_index = tree.nodeData(node).node_and_extra; | 1942 | const cond_expr, const extra_index = node.data(tree).node_and_extra; |
| 1955 | const extra = tree.extraData(extra_index, Node.While); | 1943 | const extra = tree.extraData(extra_index, Node.While); |
| 1956 | return tree.fullWhileComponents(.{ | 1944 | return tree.fullWhileComponents(.{ |
| 1957 | .while_token = tree.nodeMainToken(node), | 1945 | .while_token = node.mainToken(tree), |
| 1958 | .cond_expr = cond_expr, | 1946 | .cond_expr = cond_expr, |
| 1959 | .cont_expr = extra.cont_expr, | 1947 | .cont_expr = extra.cont_expr, |
| 1960 | .then_expr = extra.then_expr, | 1948 | .then_expr = extra.then_expr, |
| ... | @@ -1962,50 +1950,50 @@ pub fn whileFull(tree: Ast, node: Node.Index) full.While { | ... | @@ -1962,50 +1950,50 @@ pub fn whileFull(tree: Ast, node: Node.Index) full.While { |
| 1962 | }); | 1950 | }); |
| 1963 | } | 1951 | } |
| 1964 | 1952 | ||
| 1965 | pub fn forSimple(tree: Ast, node: Node.Index) full.For { | 1953 | pub fn forSimple(tree: *const Ast, node: Node.Index) full.For { |
| 1966 | const data = &tree.nodes.items(.data)[@intFromEnum(node)].node_and_node; | 1954 | const data = &tree.nodes.items(.data)[@intFromEnum(node)].node_and_node; |
| 1967 | return tree.fullForComponents(.{ | 1955 | return tree.fullForComponents(.{ |
| 1968 | .for_token = tree.nodeMainToken(node), | 1956 | .for_token = node.mainToken(tree), |
| 1969 | .inputs = (&data[0])[0..1], | 1957 | .inputs = (&data[0])[0..1], |
| 1970 | .then_expr = data[1], | 1958 | .then_expr = data[1], |
| 1971 | .else_expr = .none, | 1959 | .else_expr = .none, |
| 1972 | }); | 1960 | }); |
| 1973 | } | 1961 | } |
| 1974 | 1962 | ||
| 1975 | pub fn forFull(tree: Ast, node: Node.Index) full.For { | 1963 | pub fn forFull(tree: *const Ast, node: Node.Index) full.For { |
| 1976 | const extra_index, const extra = tree.nodeData(node).@"for"; | 1964 | const extra_index, const extra = node.data(tree).@"for"; |
| 1977 | const inputs = tree.extraDataSliceWithLen(extra_index, extra.inputs, Node.Index); | 1965 | const inputs = tree.extraDataSliceWithLen(extra_index, extra.inputs, Node.Index); |
| 1978 | const then_expr: Node.Index = @enumFromInt(tree.extra_data[@intFromEnum(extra_index) + extra.inputs]); | 1966 | const then_expr: Node.Index = @enumFromInt(tree.extra_data[@intFromEnum(extra_index) + extra.inputs]); |
| 1979 | const else_expr: Node.OptionalIndex = if (extra.has_else) @enumFromInt(tree.extra_data[@intFromEnum(extra_index) + extra.inputs + 1]) else .none; | 1967 | const else_expr: Node.OptionalIndex = if (extra.has_else) @enumFromInt(tree.extra_data[@intFromEnum(extra_index) + extra.inputs + 1]) else .none; |
| 1980 | return tree.fullForComponents(.{ | 1968 | return tree.fullForComponents(.{ |
| 1981 | .for_token = tree.nodeMainToken(node), | 1969 | .for_token = node.mainToken(tree), |
| 1982 | .inputs = inputs, | 1970 | .inputs = inputs, |
| 1983 | .then_expr = then_expr, | 1971 | .then_expr = then_expr, |
| 1984 | .else_expr = else_expr, | 1972 | .else_expr = else_expr, |
| 1985 | }); | 1973 | }); |
| 1986 | } | 1974 | } |
| 1987 | 1975 | ||
| 1988 | pub fn callOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.Call { | 1976 | pub fn callOne(tree: *const Ast, buffer: *[1]Node.Index, node: Node.Index) full.Call { |
| 1989 | const fn_expr, const first_param = tree.nodeData(node).node_and_opt_node; | 1977 | const fn_expr, const first_param = node.data(tree).node_and_opt_node; |
| 1990 | const params = loadOptionalNodesIntoBuffer(1, buffer, .{first_param}); | 1978 | const params = loadOptionalNodesIntoBuffer(1, buffer, .{first_param}); |
| 1991 | return tree.fullCallComponents(.{ | 1979 | return tree.fullCallComponents(.{ |
| 1992 | .lparen = tree.nodeMainToken(node), | 1980 | .lparen = node.mainToken(tree), |
| 1993 | .fn_expr = fn_expr, | 1981 | .fn_expr = fn_expr, |
| 1994 | .params = params, | 1982 | .params = params, |
| 1995 | }); | 1983 | }); |
| 1996 | } | 1984 | } |
| 1997 | 1985 | ||
| 1998 | pub fn callFull(tree: Ast, node: Node.Index) full.Call { | 1986 | pub fn callFull(tree: *const Ast, node: Node.Index) full.Call { |
| 1999 | const fn_expr, const extra_index = tree.nodeData(node).node_and_extra; | 1987 | const fn_expr, const extra_index = node.data(tree).node_and_extra; |
| 2000 | const params = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); | 1988 | const params = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); |
| 2001 | return tree.fullCallComponents(.{ | 1989 | return tree.fullCallComponents(.{ |
| 2002 | .lparen = tree.nodeMainToken(node), | 1990 | .lparen = node.mainToken(tree), |
| 2003 | .fn_expr = fn_expr, | 1991 | .fn_expr = fn_expr, |
| 2004 | .params = params, | 1992 | .params = params, |
| 2005 | }); | 1993 | }); |
| 2006 | } | 1994 | } |
| 2007 | 1995 | ||
| 2008 | fn fullVarDeclComponents(tree: Ast, info: full.VarDecl.Components) full.VarDecl { | 1996 | fn fullVarDeclComponents(tree: *const Ast, info: full.VarDecl.Components) full.VarDecl { |
| 2009 | var result: full.VarDecl = .{ | 1997 | var result: full.VarDecl = .{ |
| 2010 | .ast = info, | 1998 | .ast = info, |
| 2011 | .visib_token = null, | 1999 | .visib_token = null, |
| ... | @@ -2029,13 +2017,13 @@ fn fullVarDeclComponents(tree: Ast, info: full.VarDecl.Components) full.VarDecl | ... | @@ -2029,13 +2017,13 @@ fn fullVarDeclComponents(tree: Ast, info: full.VarDecl.Components) full.VarDecl |
| 2029 | return result; | 2017 | return result; |
| 2030 | } | 2018 | } |
| 2031 | 2019 | ||
| 2032 | fn fullAssignDestructureComponents(tree: Ast, info: full.AssignDestructure.Components) full.AssignDestructure { | 2020 | fn fullAssignDestructureComponents(tree: *const Ast, info: full.AssignDestructure.Components) full.AssignDestructure { |
| 2033 | var result: full.AssignDestructure = .{ | 2021 | var result: full.AssignDestructure = .{ |
| 2034 | .comptime_token = null, | 2022 | .comptime_token = null, |
| 2035 | .ast = info, | 2023 | .ast = info, |
| 2036 | }; | 2024 | }; |
| 2037 | const first_variable_token = tree.firstToken(info.variables[0]); | 2025 | const first_variable_token = tree.firstToken(info.variables[0]); |
| 2038 | const maybe_comptime_token = switch (tree.nodeTag(info.variables[0])) { | 2026 | const maybe_comptime_token = switch (info.variables[0].tag(tree)) { |
| 2039 | .global_var_decl, | 2027 | .global_var_decl, |
| 2040 | .local_var_decl, | 2028 | .local_var_decl, |
| 2041 | .aligned_var_decl, | 2029 | .aligned_var_decl, |
| ... | @@ -2049,7 +2037,7 @@ fn fullAssignDestructureComponents(tree: Ast, info: full.AssignDestructure.Compo | ... | @@ -2049,7 +2037,7 @@ fn fullAssignDestructureComponents(tree: Ast, info: full.AssignDestructure.Compo |
| 2049 | return result; | 2037 | return result; |
| 2050 | } | 2038 | } |
| 2051 | 2039 | ||
| 2052 | fn fullIfComponents(tree: Ast, info: full.If.Components) full.If { | 2040 | fn fullIfComponents(tree: *const Ast, info: full.If.Components) full.If { |
| 2053 | var result: full.If = .{ | 2041 | var result: full.If = .{ |
| 2054 | .ast = info, | 2042 | .ast = info, |
| 2055 | .payload_token = null, | 2043 | .payload_token = null, |
| ... | @@ -2073,7 +2061,7 @@ fn fullIfComponents(tree: Ast, info: full.If.Components) full.If { | ... | @@ -2073,7 +2061,7 @@ fn fullIfComponents(tree: Ast, info: full.If.Components) full.If { |
| 2073 | return result; | 2061 | return result; |
| 2074 | } | 2062 | } |
| 2075 | 2063 | ||
| 2076 | fn fullContainerFieldComponents(tree: Ast, info: full.ContainerField.Components) full.ContainerField { | 2064 | fn fullContainerFieldComponents(tree: *const Ast, info: full.ContainerField.Components) full.ContainerField { |
| 2077 | var result: full.ContainerField = .{ | 2065 | var result: full.ContainerField = .{ |
| 2078 | .ast = info, | 2066 | .ast = info, |
| 2079 | .comptime_token = null, | 2067 | .comptime_token = null, |
| ... | @@ -2088,7 +2076,7 @@ fn fullContainerFieldComponents(tree: Ast, info: full.ContainerField.Components) | ... | @@ -2088,7 +2076,7 @@ fn fullContainerFieldComponents(tree: Ast, info: full.ContainerField.Components) |
| 2088 | return result; | 2076 | return result; |
| 2089 | } | 2077 | } |
| 2090 | 2078 | ||
| 2091 | fn fullFnProtoComponents(tree: Ast, info: full.FnProto.Components) full.FnProto { | 2079 | fn fullFnProtoComponents(tree: *const Ast, info: full.FnProto.Components) full.FnProto { |
| 2092 | var result: full.FnProto = .{ | 2080 | var result: full.FnProto = .{ |
| 2093 | .ast = info, | 2081 | .ast = info, |
| 2094 | .visib_token = null, | 2082 | .visib_token = null, |
| ... | @@ -2123,7 +2111,7 @@ fn fullFnProtoComponents(tree: Ast, info: full.FnProto.Components) full.FnProto | ... | @@ -2123,7 +2111,7 @@ fn fullFnProtoComponents(tree: Ast, info: full.FnProto.Components) full.FnProto |
| 2123 | return result; | 2111 | return result; |
| 2124 | } | 2112 | } |
| 2125 | 2113 | ||
| 2126 | fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType { | 2114 | fn fullPtrTypeComponents(tree: *const Ast, info: full.PtrType.Components) full.PtrType { |
| 2127 | const size: std.builtin.Type.Pointer.Size = switch (tree.tokenTag(info.main_token)) { | 2115 | const size: std.builtin.Type.Pointer.Size = switch (tree.tokenTag(info.main_token)) { |
| 2128 | .asterisk, | 2116 | .asterisk, |
| 2129 | .asterisk_asterisk, | 2117 | .asterisk_asterisk, |
| ... | @@ -2170,7 +2158,7 @@ fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType | ... | @@ -2170,7 +2158,7 @@ fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType |
| 2170 | return result; | 2158 | return result; |
| 2171 | } | 2159 | } |
| 2172 | 2160 | ||
| 2173 | fn fullContainerDeclComponents(tree: Ast, info: full.ContainerDecl.Components) full.ContainerDecl { | 2161 | fn fullContainerDeclComponents(tree: *const Ast, info: full.ContainerDecl.Components) full.ContainerDecl { |
| 2174 | var result: full.ContainerDecl = .{ | 2162 | var result: full.ContainerDecl = .{ |
| 2175 | .ast = info, | 2163 | .ast = info, |
| 2176 | .layout_token = null, | 2164 | .layout_token = null, |
| ... | @@ -2186,7 +2174,7 @@ fn fullContainerDeclComponents(tree: Ast, info: full.ContainerDecl.Components) f | ... | @@ -2186,7 +2174,7 @@ fn fullContainerDeclComponents(tree: Ast, info: full.ContainerDecl.Components) f |
| 2186 | return result; | 2174 | return result; |
| 2187 | } | 2175 | } |
| 2188 | 2176 | ||
| 2189 | fn fullSwitchComponents(tree: Ast, info: full.Switch.Components) full.Switch { | 2177 | fn fullSwitchComponents(tree: *const Ast, info: full.Switch.Components) full.Switch { |
| 2190 | const tok_i = info.switch_token -| 1; | 2178 | const tok_i = info.switch_token -| 1; |
| 2191 | var result: full.Switch = .{ | 2179 | var result: full.Switch = .{ |
| 2192 | .ast = info, | 2180 | .ast = info, |
| ... | @@ -2200,7 +2188,7 @@ fn fullSwitchComponents(tree: Ast, info: full.Switch.Components) full.Switch { | ... | @@ -2200,7 +2188,7 @@ fn fullSwitchComponents(tree: Ast, info: full.Switch.Components) full.Switch { |
| 2200 | return result; | 2188 | return result; |
| 2201 | } | 2189 | } |
| 2202 | 2190 | ||
| 2203 | fn fullSwitchCaseComponents(tree: Ast, info: full.SwitchCase.Components, node: Node.Index) full.SwitchCase { | 2191 | fn fullSwitchCaseComponents(tree: *const Ast, info: full.SwitchCase.Components, node: Node.Index) full.SwitchCase { |
| 2204 | var result: full.SwitchCase = .{ | 2192 | var result: full.SwitchCase = .{ |
| 2205 | .ast = info, | 2193 | .ast = info, |
| 2206 | .payload_token = null, | 2194 | .payload_token = null, |
| ... | @@ -2209,7 +2197,7 @@ fn fullSwitchCaseComponents(tree: Ast, info: full.SwitchCase.Components, node: N | ... | @@ -2209,7 +2197,7 @@ fn fullSwitchCaseComponents(tree: Ast, info: full.SwitchCase.Components, node: N |
| 2209 | if (tree.tokenTag(info.arrow_token + 1) == .pipe) { | 2197 | if (tree.tokenTag(info.arrow_token + 1) == .pipe) { |
| 2210 | result.payload_token = info.arrow_token + 2; | 2198 | result.payload_token = info.arrow_token + 2; |
| 2211 | } | 2199 | } |
| 2212 | result.inline_token = switch (tree.nodeTag(node)) { | 2200 | result.inline_token = switch (node.tag(tree)) { |
| 2213 | .switch_case_inline, .switch_case_inline_one => if (result.ast.values.len == 0) | 2201 | .switch_case_inline, .switch_case_inline_one => if (result.ast.values.len == 0) |
| 2214 | info.arrow_token - 2 | 2202 | info.arrow_token - 2 |
| 2215 | else | 2203 | else |
| ... | @@ -2219,7 +2207,7 @@ fn fullSwitchCaseComponents(tree: Ast, info: full.SwitchCase.Components, node: N | ... | @@ -2219,7 +2207,7 @@ fn fullSwitchCaseComponents(tree: Ast, info: full.SwitchCase.Components, node: N |
| 2219 | return result; | 2207 | return result; |
| 2220 | } | 2208 | } |
| 2221 | 2209 | ||
| 2222 | fn fullAsmComponents(tree: Ast, info: full.Asm.Components) full.Asm { | 2210 | fn fullAsmComponents(tree: *const Ast, info: full.Asm.Components) full.Asm { |
| 2223 | var result: full.Asm = .{ | 2211 | var result: full.Asm = .{ |
| 2224 | .ast = info, | 2212 | .ast = info, |
| 2225 | .volatile_token = null, | 2213 | .volatile_token = null, |
| ... | @@ -2231,7 +2219,7 @@ fn fullAsmComponents(tree: Ast, info: full.Asm.Components) full.Asm { | ... | @@ -2231,7 +2219,7 @@ fn fullAsmComponents(tree: Ast, info: full.Asm.Components) full.Asm { |
| 2231 | result.volatile_token = info.asm_token + 1; | 2219 | result.volatile_token = info.asm_token + 1; |
| 2232 | } | 2220 | } |
| 2233 | const outputs_end: usize = for (info.items, 0..) |item, i| { | 2221 | const outputs_end: usize = for (info.items, 0..) |item, i| { |
| 2234 | switch (tree.nodeTag(item)) { | 2222 | switch (item.tag(tree)) { |
| 2235 | .asm_output => continue, | 2223 | .asm_output => continue, |
| 2236 | else => break i, | 2224 | else => break i, |
| 2237 | } | 2225 | } |
| ... | @@ -2280,7 +2268,7 @@ fn fullAsmComponents(tree: Ast, info: full.Asm.Components) full.Asm { | ... | @@ -2280,7 +2268,7 @@ fn fullAsmComponents(tree: Ast, info: full.Asm.Components) full.Asm { |
| 2280 | return result; | 2268 | return result; |
| 2281 | } | 2269 | } |
| 2282 | 2270 | ||
| 2283 | fn fullWhileComponents(tree: Ast, info: full.While.Components) full.While { | 2271 | fn fullWhileComponents(tree: *const Ast, info: full.While.Components) full.While { |
| 2284 | var result: full.While = .{ | 2272 | var result: full.While = .{ |
| 2285 | .ast = info, | 2273 | .ast = info, |
| 2286 | .inline_token = null, | 2274 | .inline_token = null, |
| ... | @@ -2312,7 +2300,7 @@ fn fullWhileComponents(tree: Ast, info: full.While.Components) full.While { | ... | @@ -2312,7 +2300,7 @@ fn fullWhileComponents(tree: Ast, info: full.While.Components) full.While { |
| 2312 | return result; | 2300 | return result; |
| 2313 | } | 2301 | } |
| 2314 | 2302 | ||
| 2315 | fn fullForComponents(tree: Ast, info: full.For.Components) full.For { | 2303 | fn fullForComponents(tree: *const Ast, info: full.For.Components) full.For { |
| 2316 | var result: full.For = .{ | 2304 | var result: full.For = .{ |
| 2317 | .ast = info, | 2305 | .ast = info, |
| 2318 | .inline_token = null, | 2306 | .inline_token = null, |
| ... | @@ -2336,7 +2324,7 @@ fn fullForComponents(tree: Ast, info: full.For.Components) full.For { | ... | @@ -2336,7 +2324,7 @@ fn fullForComponents(tree: Ast, info: full.For.Components) full.For { |
| 2336 | return result; | 2324 | return result; |
| 2337 | } | 2325 | } |
| 2338 | 2326 | ||
| 2339 | fn fullCallComponents(tree: Ast, info: full.Call.Components) full.Call { | 2327 | fn fullCallComponents(tree: *const Ast, info: full.Call.Components) full.Call { |
| 2340 | var result: full.Call = .{ | 2328 | var result: full.Call = .{ |
| 2341 | .ast = info, | 2329 | .ast = info, |
| 2342 | .async_token = null, | 2330 | .async_token = null, |
| ... | @@ -2348,8 +2336,8 @@ fn fullCallComponents(tree: Ast, info: full.Call.Components) full.Call { | ... | @@ -2348,8 +2336,8 @@ fn fullCallComponents(tree: Ast, info: full.Call.Components) full.Call { |
| 2348 | return result; | 2336 | return result; |
| 2349 | } | 2337 | } |
| 2350 | 2338 | ||
| 2351 | pub fn fullVarDecl(tree: Ast, node: Node.Index) ?full.VarDecl { | 2339 | pub fn fullVarDecl(tree: *const Ast, node: Node.Index) ?full.VarDecl { |
| 2352 | return switch (tree.nodeTag(node)) { | 2340 | return switch (node.tag(tree)) { |
| 2353 | .global_var_decl => tree.globalVarDecl(node), | 2341 | .global_var_decl => tree.globalVarDecl(node), |
| 2354 | .local_var_decl => tree.localVarDecl(node), | 2342 | .local_var_decl => tree.localVarDecl(node), |
| 2355 | .aligned_var_decl => tree.alignedVarDecl(node), | 2343 | .aligned_var_decl => tree.alignedVarDecl(node), |
| ... | @@ -2358,16 +2346,16 @@ pub fn fullVarDecl(tree: Ast, node: Node.Index) ?full.VarDecl { | ... | @@ -2358,16 +2346,16 @@ pub fn fullVarDecl(tree: Ast, node: Node.Index) ?full.VarDecl { |
| 2358 | }; | 2346 | }; |
| 2359 | } | 2347 | } |
| 2360 | 2348 | ||
| 2361 | pub fn fullIf(tree: Ast, node: Node.Index) ?full.If { | 2349 | pub fn fullIf(tree: *const Ast, node: Node.Index) ?full.If { |
| 2362 | return switch (tree.nodeTag(node)) { | 2350 | return switch (node.tag(tree)) { |
| 2363 | .if_simple => tree.ifSimple(node), | 2351 | .if_simple => tree.ifSimple(node), |
| 2364 | .@"if" => tree.ifFull(node), | 2352 | .@"if" => tree.ifFull(node), |
| 2365 | else => null, | 2353 | else => null, |
| 2366 | }; | 2354 | }; |
| 2367 | } | 2355 | } |
| 2368 | 2356 | ||
| 2369 | pub fn fullWhile(tree: Ast, node: Node.Index) ?full.While { | 2357 | pub fn fullWhile(tree: *const Ast, node: Node.Index) ?full.While { |
| 2370 | return switch (tree.nodeTag(node)) { | 2358 | return switch (node.tag(tree)) { |
| 2371 | .while_simple => tree.whileSimple(node), | 2359 | .while_simple => tree.whileSimple(node), |
| 2372 | .while_cont => tree.whileCont(node), | 2360 | .while_cont => tree.whileCont(node), |
| 2373 | .@"while" => tree.whileFull(node), | 2361 | .@"while" => tree.whileFull(node), |
| ... | @@ -2375,16 +2363,16 @@ pub fn fullWhile(tree: Ast, node: Node.Index) ?full.While { | ... | @@ -2375,16 +2363,16 @@ pub fn fullWhile(tree: Ast, node: Node.Index) ?full.While { |
| 2375 | }; | 2363 | }; |
| 2376 | } | 2364 | } |
| 2377 | 2365 | ||
| 2378 | pub fn fullFor(tree: Ast, node: Node.Index) ?full.For { | 2366 | pub fn fullFor(tree: *const Ast, node: Node.Index) ?full.For { |
| 2379 | return switch (tree.nodeTag(node)) { | 2367 | return switch (node.tag(tree)) { |
| 2380 | .for_simple => tree.forSimple(node), | 2368 | .for_simple => tree.forSimple(node), |
| 2381 | .@"for" => tree.forFull(node), | 2369 | .@"for" => tree.forFull(node), |
| 2382 | else => null, | 2370 | else => null, |
| 2383 | }; | 2371 | }; |
| 2384 | } | 2372 | } |
| 2385 | 2373 | ||
| 2386 | pub fn fullContainerField(tree: Ast, node: Node.Index) ?full.ContainerField { | 2374 | pub fn fullContainerField(tree: *const Ast, node: Node.Index) ?full.ContainerField { |
| 2387 | return switch (tree.nodeTag(node)) { | 2375 | return switch (node.tag(tree)) { |
| 2388 | .container_field_init => tree.containerFieldInit(node), | 2376 | .container_field_init => tree.containerFieldInit(node), |
| 2389 | .container_field_align => tree.containerFieldAlign(node), | 2377 | .container_field_align => tree.containerFieldAlign(node), |
| 2390 | .container_field => tree.containerField(node), | 2378 | .container_field => tree.containerField(node), |
| ... | @@ -2392,19 +2380,19 @@ pub fn fullContainerField(tree: Ast, node: Node.Index) ?full.ContainerField { | ... | @@ -2392,19 +2380,19 @@ pub fn fullContainerField(tree: Ast, node: Node.Index) ?full.ContainerField { |
| 2392 | }; | 2380 | }; |
| 2393 | } | 2381 | } |
| 2394 | 2382 | ||
| 2395 | pub fn fullFnProto(tree: Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.FnProto { | 2383 | pub fn fullFnProto(tree: *const Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.FnProto { |
| 2396 | return switch (tree.nodeTag(node)) { | 2384 | return switch (node.tag(tree)) { |
| 2397 | .fn_proto => tree.fnProto(node), | 2385 | .fn_proto => tree.fnProto(node), |
| 2398 | .fn_proto_multi => tree.fnProtoMulti(node), | 2386 | .fn_proto_multi => tree.fnProtoMulti(node), |
| 2399 | .fn_proto_one => tree.fnProtoOne(buffer, node), | 2387 | .fn_proto_one => tree.fnProtoOne(buffer, node), |
| 2400 | .fn_proto_simple => tree.fnProtoSimple(buffer, node), | 2388 | .fn_proto_simple => tree.fnProtoSimple(buffer, node), |
| 2401 | .fn_decl => tree.fullFnProto(buffer, tree.nodeData(node).node_and_node[0]), | 2389 | .fn_decl => tree.fullFnProto(buffer, node.data(tree).node_and_node[0]), |
| 2402 | else => null, | 2390 | else => null, |
| 2403 | }; | 2391 | }; |
| 2404 | } | 2392 | } |
| 2405 | 2393 | ||
| 2406 | pub fn fullStructInit(tree: Ast, buffer: *[2]Ast.Node.Index, node: Node.Index) ?full.StructInit { | 2394 | pub fn fullStructInit(tree: *const Ast, buffer: *[2]Ast.Node.Index, node: Node.Index) ?full.StructInit { |
| 2407 | return switch (tree.nodeTag(node)) { | 2395 | return switch (node.tag(tree)) { |
| 2408 | .struct_init_one, .struct_init_one_comma => tree.structInitOne(buffer[0..1], node), | 2396 | .struct_init_one, .struct_init_one_comma => tree.structInitOne(buffer[0..1], node), |
| 2409 | .struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(buffer, node), | 2397 | .struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(buffer, node), |
| 2410 | .struct_init_dot, .struct_init_dot_comma => tree.structInitDot(node), | 2398 | .struct_init_dot, .struct_init_dot_comma => tree.structInitDot(node), |
| ... | @@ -2413,8 +2401,8 @@ pub fn fullStructInit(tree: Ast, buffer: *[2]Ast.Node.Index, node: Node.Index) ? | ... | @@ -2413,8 +2401,8 @@ pub fn fullStructInit(tree: Ast, buffer: *[2]Ast.Node.Index, node: Node.Index) ? |
| 2413 | }; | 2401 | }; |
| 2414 | } | 2402 | } |
| 2415 | 2403 | ||
| 2416 | pub fn fullArrayInit(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) ?full.ArrayInit { | 2404 | pub fn fullArrayInit(tree: *const Ast, buffer: *[2]Node.Index, node: Node.Index) ?full.ArrayInit { |
| 2417 | return switch (tree.nodeTag(node)) { | 2405 | return switch (node.tag(tree)) { |
| 2418 | .array_init_one, .array_init_one_comma => tree.arrayInitOne(buffer[0..1], node), | 2406 | .array_init_one, .array_init_one_comma => tree.arrayInitOne(buffer[0..1], node), |
| 2419 | .array_init_dot_two, .array_init_dot_two_comma => tree.arrayInitDotTwo(buffer, node), | 2407 | .array_init_dot_two, .array_init_dot_two_comma => tree.arrayInitDotTwo(buffer, node), |
| 2420 | .array_init_dot, .array_init_dot_comma => tree.arrayInitDot(node), | 2408 | .array_init_dot, .array_init_dot_comma => tree.arrayInitDot(node), |
| ... | @@ -2423,16 +2411,16 @@ pub fn fullArrayInit(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) ?full. | ... | @@ -2423,16 +2411,16 @@ pub fn fullArrayInit(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) ?full. |
| 2423 | }; | 2411 | }; |
| 2424 | } | 2412 | } |
| 2425 | 2413 | ||
| 2426 | pub fn fullArrayType(tree: Ast, node: Node.Index) ?full.ArrayType { | 2414 | pub fn fullArrayType(tree: *const Ast, node: Node.Index) ?full.ArrayType { |
| 2427 | return switch (tree.nodeTag(node)) { | 2415 | return switch (node.tag(tree)) { |
| 2428 | .array_type => tree.arrayType(node), | 2416 | .array_type => tree.arrayType(node), |
| 2429 | .array_type_sentinel => tree.arrayTypeSentinel(node), | 2417 | .array_type_sentinel => tree.arrayTypeSentinel(node), |
| 2430 | else => null, | 2418 | else => null, |
| 2431 | }; | 2419 | }; |
| 2432 | } | 2420 | } |
| 2433 | 2421 | ||
| 2434 | pub fn fullPtrType(tree: Ast, node: Node.Index) ?full.PtrType { | 2422 | pub fn fullPtrType(tree: *const Ast, node: Node.Index) ?full.PtrType { |
| 2435 | return switch (tree.nodeTag(node)) { | 2423 | return switch (node.tag(tree)) { |
| 2436 | .ptr_type_aligned => tree.ptrTypeAligned(node), | 2424 | .ptr_type_aligned => tree.ptrTypeAligned(node), |
| 2437 | .ptr_type_sentinel => tree.ptrTypeSentinel(node), | 2425 | .ptr_type_sentinel => tree.ptrTypeSentinel(node), |
| 2438 | .ptr_type => tree.ptrType(node), | 2426 | .ptr_type => tree.ptrType(node), |
| ... | @@ -2441,8 +2429,8 @@ pub fn fullPtrType(tree: Ast, node: Node.Index) ?full.PtrType { | ... | @@ -2441,8 +2429,8 @@ pub fn fullPtrType(tree: Ast, node: Node.Index) ?full.PtrType { |
| 2441 | }; | 2429 | }; |
| 2442 | } | 2430 | } |
| 2443 | 2431 | ||
| 2444 | pub fn fullSlice(tree: Ast, node: Node.Index) ?full.Slice { | 2432 | pub fn fullSlice(tree: *const Ast, node: Node.Index) ?full.Slice { |
| 2445 | return switch (tree.nodeTag(node)) { | 2433 | return switch (node.tag(tree)) { |
| 2446 | .slice_open => tree.sliceOpen(node), | 2434 | .slice_open => tree.sliceOpen(node), |
| 2447 | .slice => tree.slice(node), | 2435 | .slice => tree.slice(node), |
| 2448 | .slice_sentinel => tree.sliceSentinel(node), | 2436 | .slice_sentinel => tree.sliceSentinel(node), |
| ... | @@ -2450,8 +2438,8 @@ pub fn fullSlice(tree: Ast, node: Node.Index) ?full.Slice { | ... | @@ -2450,8 +2438,8 @@ pub fn fullSlice(tree: Ast, node: Node.Index) ?full.Slice { |
| 2450 | }; | 2438 | }; |
| 2451 | } | 2439 | } |
| 2452 | 2440 | ||
| 2453 | pub fn fullContainerDecl(tree: Ast, buffer: *[2]Ast.Node.Index, node: Node.Index) ?full.ContainerDecl { | 2441 | pub fn fullContainerDecl(tree: *const Ast, buffer: *[2]Ast.Node.Index, node: Node.Index) ?full.ContainerDecl { |
| 2454 | return switch (tree.nodeTag(node)) { | 2442 | return switch (node.tag(tree)) { |
| 2455 | .root => tree.containerDeclRoot(), | 2443 | .root => tree.containerDeclRoot(), |
| 2456 | .container_decl, .container_decl_trailing => tree.containerDecl(node), | 2444 | .container_decl, .container_decl_trailing => tree.containerDecl(node), |
| 2457 | .container_decl_arg, .container_decl_arg_trailing => tree.containerDeclArg(node), | 2445 | .container_decl_arg, .container_decl_arg_trailing => tree.containerDeclArg(node), |
| ... | @@ -2463,49 +2451,49 @@ pub fn fullContainerDecl(tree: Ast, buffer: *[2]Ast.Node.Index, node: Node.Index | ... | @@ -2463,49 +2451,49 @@ pub fn fullContainerDecl(tree: Ast, buffer: *[2]Ast.Node.Index, node: Node.Index |
| 2463 | }; | 2451 | }; |
| 2464 | } | 2452 | } |
| 2465 | 2453 | ||
| 2466 | pub fn fullSwitch(tree: Ast, node: Node.Index) ?full.Switch { | 2454 | pub fn fullSwitch(tree: *const Ast, node: Node.Index) ?full.Switch { |
| 2467 | return switch (tree.nodeTag(node)) { | 2455 | return switch (node.tag(tree)) { |
| 2468 | .@"switch", .switch_comma => tree.switchFull(node), | 2456 | .@"switch", .switch_comma => tree.switchFull(node), |
| 2469 | else => null, | 2457 | else => null, |
| 2470 | }; | 2458 | }; |
| 2471 | } | 2459 | } |
| 2472 | 2460 | ||
| 2473 | pub fn fullSwitchCase(tree: Ast, node: Node.Index) ?full.SwitchCase { | 2461 | pub fn fullSwitchCase(tree: *const Ast, node: Node.Index) ?full.SwitchCase { |
| 2474 | return switch (tree.nodeTag(node)) { | 2462 | return switch (node.tag(tree)) { |
| 2475 | .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(node), | 2463 | .switch_case_one, .switch_case_inline_one => tree.switchCaseOne(node), |
| 2476 | .switch_case, .switch_case_inline => tree.switchCase(node), | 2464 | .switch_case, .switch_case_inline => tree.switchCase(node), |
| 2477 | else => null, | 2465 | else => null, |
| 2478 | }; | 2466 | }; |
| 2479 | } | 2467 | } |
| 2480 | 2468 | ||
| 2481 | pub fn fullAsm(tree: Ast, node: Node.Index) ?full.Asm { | 2469 | pub fn fullAsm(tree: *const Ast, node: Node.Index) ?full.Asm { |
| 2482 | return switch (tree.nodeTag(node)) { | 2470 | return switch (node.tag(tree)) { |
| 2483 | .asm_simple => tree.asmSimple(node), | 2471 | .asm_simple => tree.asmSimple(node), |
| 2484 | .@"asm" => tree.asmFull(node), | 2472 | .@"asm" => tree.asmFull(node), |
| 2485 | else => null, | 2473 | else => null, |
| 2486 | }; | 2474 | }; |
| 2487 | } | 2475 | } |
| 2488 | 2476 | ||
| 2489 | pub fn fullCall(tree: Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.Call { | 2477 | pub fn fullCall(tree: *const Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.Call { |
| 2490 | return switch (tree.nodeTag(node)) { | 2478 | return switch (node.tag(tree)) { |
| 2491 | .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node), | 2479 | .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node), |
| 2492 | .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(buffer, node), | 2480 | .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(buffer, node), |
| 2493 | else => null, | 2481 | else => null, |
| 2494 | }; | 2482 | }; |
| 2495 | } | 2483 | } |
| 2496 | 2484 | ||
| 2497 | pub fn builtinCallParams(tree: Ast, buffer: *[2]Ast.Node.Index, node: Ast.Node.Index) ?[]const Node.Index { | 2485 | pub fn builtinCallParams(tree: *const Ast, buffer: *[2]Ast.Node.Index, node: Ast.Node.Index) ?[]const Node.Index { |
| 2498 | return switch (tree.nodeTag(node)) { | 2486 | return switch (node.tag(tree)) { |
| 2499 | .builtin_call_two, .builtin_call_two_comma => loadOptionalNodesIntoBuffer(2, buffer, tree.nodeData(node).opt_node_and_opt_node), | 2487 | .builtin_call_two, .builtin_call_two_comma => loadOptionalNodesIntoBuffer(2, buffer, node.data(tree).opt_node_and_opt_node), |
| 2500 | .builtin_call, .builtin_call_comma => tree.extraDataSlice(tree.nodeData(node).extra_range, Node.Index), | 2488 | .builtin_call, .builtin_call_comma => tree.extraDataSlice(node.data(tree).extra_range, Node.Index), |
| 2501 | else => null, | 2489 | else => null, |
| 2502 | }; | 2490 | }; |
| 2503 | } | 2491 | } |
| 2504 | 2492 | ||
| 2505 | pub fn blockStatements(tree: Ast, buffer: *[2]Ast.Node.Index, node: Ast.Node.Index) ?[]const Node.Index { | 2493 | pub fn blockStatements(tree: *const Ast, buffer: *[2]Ast.Node.Index, node: Ast.Node.Index) ?[]const Node.Index { |
| 2506 | return switch (tree.nodeTag(node)) { | 2494 | return switch (node.tag(tree)) { |
| 2507 | .block_two, .block_two_semicolon => loadOptionalNodesIntoBuffer(2, buffer, tree.nodeData(node).opt_node_and_opt_node), | 2495 | .block_two, .block_two_semicolon => loadOptionalNodesIntoBuffer(2, buffer, node.data(tree).opt_node_and_opt_node), |
| 2508 | .block, .block_semicolon => tree.extraDataSlice(tree.nodeData(node).extra_range, Node.Index), | 2496 | .block, .block_semicolon => tree.extraDataSlice(node.data(tree).extra_range, Node.Index), |
| 2509 | else => null, | 2497 | else => null, |
| 2510 | }; | 2498 | }; |
| 2511 | } | 2499 | } |
| ... | @@ -2620,7 +2608,7 @@ pub const full = struct { | ... | @@ -2620,7 +2608,7 @@ pub const full = struct { |
| 2620 | 2608 | ||
| 2621 | pub fn convertToNonTupleLike(cf: *ContainerField, tree: *const Ast) void { | 2609 | pub fn convertToNonTupleLike(cf: *ContainerField, tree: *const Ast) void { |
| 2622 | if (!cf.ast.tuple_like) return; | 2610 | if (!cf.ast.tuple_like) return; |
| 2623 | if (tree.nodeTag(cf.ast.type_expr.unwrap().?) != .identifier) return; | 2611 | if (cf.ast.type_expr.unwrap().?.tag(tree) != .identifier) return; |
| 2624 | 2612 | ||
| 2625 | cf.ast.type_expr = .none; | 2613 | cf.ast.type_expr = .none; |
| 2626 | cf.ast.tuple_like = false; | 2614 | cf.ast.tuple_like = false; |
| ... | @@ -3004,6 +2992,18 @@ pub const Node = struct { | ... | @@ -3004,6 +2992,18 @@ pub const Node = struct { |
| 3004 | const destination_i64: i64 = @intFromEnum(destination); | 2992 | const destination_i64: i64 = @intFromEnum(destination); |
| 3005 | return @enumFromInt(destination_i64 - base_i64); | 2993 | return @enumFromInt(destination_i64 - base_i64); |
| 3006 | } | 2994 | } |
| 2995 | |||
| 2996 | pub fn tag(i: Node.Index, tree: *const Ast) Tag { | ||
| 2997 | return tree.nodes.items(.tag)[@intFromEnum(i)]; | ||
| 2998 | } | ||
| 2999 | |||
| 3000 | pub fn mainToken(i: Index, ast: *const Ast) TokenIndex { | ||
| 3001 | return ast.nodes.items(.main_token)[@intFromEnum(i)]; | ||
| 3002 | } | ||
| 3003 | |||
| 3004 | pub fn data(i: Index, ast: *const Ast) Data { | ||
| 3005 | return ast.nodes.items(.data)[@intFromEnum(i)]; | ||
| 3006 | } | ||
| 3007 | }; | 3007 | }; |
| 3008 | 3008 | ||
| 3009 | /// Index into `nodes`, or null. | 3009 | /// Index into `nodes`, or null. |
| ... | @@ -4098,7 +4098,7 @@ pub fn nodeToSpan(tree: *const Ast, node: Ast.Node.Index) Span { | ... | @@ -4098,7 +4098,7 @@ pub fn nodeToSpan(tree: *const Ast, node: Ast.Node.Index) Span { |
| 4098 | tree, | 4098 | tree, |
| 4099 | tree.firstToken(node), | 4099 | tree.firstToken(node), |
| 4100 | tree.lastToken(node), | 4100 | tree.lastToken(node), |
| 4101 | tree.nodeMainToken(node), | 4101 | node.mainToken(tree), |
| 4102 | ); | 4102 | ); |
| 4103 | } | 4103 | } |
| 4104 | 4104 |
lib/std/zig/AstGen.zig+177-176| ... | @@ -141,7 +141,7 @@ fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void { | ... | @@ -141,7 +141,7 @@ fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void { |
| 141 | astgen.extra.appendSliceAssumeCapacity(@ptrCast(refs)); | 141 | astgen.extra.appendSliceAssumeCapacity(@ptrCast(refs)); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { | 144 | pub fn generate(gpa: Allocator, tree: *const Ast) Allocator.Error!Zir { |
| 145 | assert(tree.mode == .zig); | 145 | assert(tree.mode == .zig); |
| 146 | 146 | ||
| 147 | var arena = std.heap.ArenaAllocator.init(gpa); | 147 | var arena = std.heap.ArenaAllocator.init(gpa); |
| ... | @@ -153,7 +153,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { | ... | @@ -153,7 +153,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 153 | var astgen: AstGen = .{ | 153 | var astgen: AstGen = .{ |
| 154 | .gpa = gpa, | 154 | .gpa = gpa, |
| 155 | .arena = arena.allocator(), | 155 | .arena = arena.allocator(), |
| 156 | .tree = &tree, | 156 | .tree = tree, |
| 157 | .nodes_need_rl = &nodes_need_rl, | 157 | .nodes_need_rl = &nodes_need_rl, |
| 158 | .src_hasher = undefined, // `structDeclInner` for the root struct will set this | 158 | .src_hasher = undefined, // `structDeclInner` for the root struct will set this |
| 159 | }; | 159 | }; |
| ... | @@ -440,7 +440,7 @@ fn reachableExprComptime( | ... | @@ -440,7 +440,7 @@ fn reachableExprComptime( |
| 440 | fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref { | 440 | fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref { |
| 441 | const astgen = gz.astgen; | 441 | const astgen = gz.astgen; |
| 442 | const tree = astgen.tree; | 442 | const tree = astgen.tree; |
| 443 | switch (tree.nodeTag(node)) { | 443 | switch (node.tag(tree)) { |
| 444 | .root => unreachable, | 444 | .root => unreachable, |
| 445 | .@"usingnamespace" => unreachable, | 445 | .@"usingnamespace" => unreachable, |
| 446 | .test_decl => unreachable, | 446 | .test_decl => unreachable, |
| ... | @@ -608,7 +608,7 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins | ... | @@ -608,7 +608,7 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins |
| 608 | .builtin_call_two, | 608 | .builtin_call_two, |
| 609 | .builtin_call_two_comma, | 609 | .builtin_call_two_comma, |
| 610 | => { | 610 | => { |
| 611 | const builtin_token = tree.nodeMainToken(node); | 611 | const builtin_token = node.mainToken(tree); |
| 612 | const builtin_name = tree.tokenSlice(builtin_token); | 612 | const builtin_name = tree.tokenSlice(builtin_token); |
| 613 | // If the builtin is an invalid name, we don't cause an error here; instead | 613 | // If the builtin is an invalid name, we don't cause an error here; instead |
| 614 | // let it pass, and the error will be "invalid builtin function" later. | 614 | // let it pass, and the error will be "invalid builtin function" later. |
| ... | @@ -646,7 +646,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -646,7 +646,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 646 | gz.anon_name_strategy = .anon; | 646 | gz.anon_name_strategy = .anon; |
| 647 | } | 647 | } |
| 648 | 648 | ||
| 649 | switch (tree.nodeTag(node)) { | 649 | switch (node.tag(tree)) { |
| 650 | .root => unreachable, // Top-level declaration. | 650 | .root => unreachable, // Top-level declaration. |
| 651 | .@"usingnamespace" => unreachable, // Top-level declaration. | 651 | .@"usingnamespace" => unreachable, // Top-level declaration. |
| 652 | .test_decl => unreachable, // Top-level declaration. | 652 | .test_decl => unreachable, // Top-level declaration. |
| ... | @@ -756,8 +756,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -756,8 +756,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 756 | }, | 756 | }, |
| 757 | 757 | ||
| 758 | // zig fmt: off | 758 | // zig fmt: off |
| 759 | .shl => return shiftOp(gz, scope, ri, node, tree.nodeData(node).node_and_node[0], tree.nodeData(node).node_and_node[1], .shl), | 759 | .shl => return shiftOp(gz, scope, ri, node, node.data(tree).node_and_node[0], node.data(tree).node_and_node[1], .shl), |
| 760 | .shr => return shiftOp(gz, scope, ri, node, tree.nodeData(node).node_and_node[0], tree.nodeData(node).node_and_node[1], .shr), | 760 | .shr => return shiftOp(gz, scope, ri, node, node.data(tree).node_and_node[0], node.data(tree).node_and_node[1], .shr), |
| 761 | 761 | ||
| 762 | .add => return simpleBinOp(gz, scope, ri, node, .add), | 762 | .add => return simpleBinOp(gz, scope, ri, node, .add), |
| 763 | .add_wrap => return simpleBinOp(gz, scope, ri, node, .addwrap), | 763 | .add_wrap => return simpleBinOp(gz, scope, ri, node, .addwrap), |
| ... | @@ -787,7 +787,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -787,7 +787,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 787 | // This syntax form does not currently use the result type in the language specification. | 787 | // This syntax form does not currently use the result type in the language specification. |
| 788 | // However, the result type can be used to emit more optimal code for large multiplications by | 788 | // However, the result type can be used to emit more optimal code for large multiplications by |
| 789 | // having Sema perform a coercion before the multiplication operation. | 789 | // having Sema perform a coercion before the multiplication operation. |
| 790 | const lhs_node, const rhs_node = tree.nodeData(node).node_and_node; | 790 | const lhs_node, const rhs_node = node.data(tree).node_and_node; |
| 791 | const result = try gz.addPlNode(.array_mul, node, Zir.Inst.ArrayMul{ | 791 | const result = try gz.addPlNode(.array_mul, node, Zir.Inst.ArrayMul{ |
| 792 | .res_ty = if (try ri.rl.resultType(gz, node)) |t| t else .none, | 792 | .res_ty = if (try ri.rl.resultType(gz, node)) |t| t else .none, |
| 793 | .lhs = try expr(gz, scope, .{ .rl = .none }, lhs_node), | 793 | .lhs = try expr(gz, scope, .{ .rl = .none }, lhs_node), |
| ... | @@ -802,7 +802,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -802,7 +802,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 802 | .merge_error_sets => .merge_error_sets, | 802 | .merge_error_sets => .merge_error_sets, |
| 803 | else => unreachable, | 803 | else => unreachable, |
| 804 | }; | 804 | }; |
| 805 | const lhs_node, const rhs_node = tree.nodeData(node).node_and_node; | 805 | const lhs_node, const rhs_node = node.data(tree).node_and_node; |
| 806 | const lhs = try reachableTypeExpr(gz, scope, lhs_node, node); | 806 | const lhs = try reachableTypeExpr(gz, scope, lhs_node, node); |
| 807 | const rhs = try reachableTypeExpr(gz, scope, rhs_node, node); | 807 | const rhs = try reachableTypeExpr(gz, scope, rhs_node, node); |
| 808 | const result = try gz.addPlNode(inst_tag, node, Zir.Inst.Bin{ .lhs = lhs, .rhs = rhs }); | 808 | const result = try gz.addPlNode(inst_tag, node, Zir.Inst.Bin{ .lhs = lhs, .rhs = rhs }); |
| ... | @@ -812,11 +812,11 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -812,11 +812,11 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 812 | .bool_and => return boolBinOp(gz, scope, ri, node, .bool_br_and), | 812 | .bool_and => return boolBinOp(gz, scope, ri, node, .bool_br_and), |
| 813 | .bool_or => return boolBinOp(gz, scope, ri, node, .bool_br_or), | 813 | .bool_or => return boolBinOp(gz, scope, ri, node, .bool_br_or), |
| 814 | 814 | ||
| 815 | .bool_not => return simpleUnOp(gz, scope, ri, node, coerced_bool_ri, tree.nodeData(node).node, .bool_not), | 815 | .bool_not => return simpleUnOp(gz, scope, ri, node, coerced_bool_ri, node.data(tree).node, .bool_not), |
| 816 | .bit_not => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, tree.nodeData(node).node, .bit_not), | 816 | .bit_not => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, node.data(tree).node, .bit_not), |
| 817 | 817 | ||
| 818 | .negation => return negation(gz, scope, ri, node), | 818 | .negation => return negation(gz, scope, ri, node), |
| 819 | .negation_wrap => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, tree.nodeData(node).node, .negate_wrap), | 819 | .negation_wrap => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, node.data(tree).node, .negate_wrap), |
| 820 | 820 | ||
| 821 | .identifier => return identifier(gz, scope, ri, node, null), | 821 | .identifier => return identifier(gz, scope, ri, node, null), |
| 822 | 822 | ||
| ... | @@ -875,8 +875,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -875,8 +875,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 875 | const else_node = if_full.ast.else_expr.unwrap() orelse break :no_switch_on_err; | 875 | const else_node = if_full.ast.else_expr.unwrap() orelse break :no_switch_on_err; |
| 876 | const full_switch = tree.fullSwitch(else_node) orelse break :no_switch_on_err; | 876 | const full_switch = tree.fullSwitch(else_node) orelse break :no_switch_on_err; |
| 877 | if (full_switch.label_token != null) break :no_switch_on_err; | 877 | if (full_switch.label_token != null) break :no_switch_on_err; |
| 878 | if (tree.nodeTag(full_switch.ast.condition) != .identifier) break :no_switch_on_err; | 878 | if (full_switch.ast.condition.tag(tree) != .identifier) break :no_switch_on_err; |
| 879 | if (!mem.eql(u8, tree.tokenSlice(error_token), tree.tokenSlice(tree.nodeMainToken(full_switch.ast.condition)))) break :no_switch_on_err; | 879 | if (!mem.eql(u8, tree.tokenSlice(error_token), tree.tokenSlice(full_switch.ast.condition.mainToken(tree)))) break :no_switch_on_err; |
| 880 | return switchExprErrUnion(gz, scope, ri.br(), node, .@"if"); | 880 | return switchExprErrUnion(gz, scope, ri.br(), node, .@"if"); |
| 881 | } | 881 | } |
| 882 | return ifExpr(gz, scope, ri.br(), node, if_full); | 882 | return ifExpr(gz, scope, ri.br(), node, if_full); |
| ... | @@ -895,7 +895,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -895,7 +895,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 895 | => { | 895 | => { |
| 896 | const full = tree.fullSlice(node).?; | 896 | const full = tree.fullSlice(node).?; |
| 897 | if (full.ast.end != .none and | 897 | if (full.ast.end != .none and |
| 898 | tree.nodeTag(full.ast.sliced) == .slice_open and | 898 | full.ast.sliced.tag(tree) == .slice_open and |
| 899 | nodeIsTriviallyZero(tree, full.ast.start)) | 899 | nodeIsTriviallyZero(tree, full.ast.start)) |
| 900 | { | 900 | { |
| 901 | const lhs_extra = tree.sliceOpen(full.ast.sliced).ast; | 901 | const lhs_extra = tree.sliceOpen(full.ast.sliced).ast; |
| ... | @@ -950,7 +950,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -950,7 +950,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 950 | }, | 950 | }, |
| 951 | 951 | ||
| 952 | .deref => { | 952 | .deref => { |
| 953 | const lhs = try expr(gz, scope, .{ .rl = .none }, tree.nodeData(node).node); | 953 | const lhs = try expr(gz, scope, .{ .rl = .none }, node.data(tree).node); |
| 954 | _ = try gz.addUnNode(.validate_deref, lhs, node); | 954 | _ = try gz.addUnNode(.validate_deref, lhs, node); |
| 955 | switch (ri.rl) { | 955 | switch (ri.rl) { |
| 956 | .ref, .ref_coerced_ty => return lhs, | 956 | .ref, .ref_coerced_ty => return lhs, |
| ... | @@ -965,17 +965,17 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -965,17 +965,17 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 965 | _ = try gz.addUnTok(.validate_ref_ty, res_ty_inst, tree.firstToken(node)); | 965 | _ = try gz.addUnTok(.validate_ref_ty, res_ty_inst, tree.firstToken(node)); |
| 966 | break :rl .{ .ref_coerced_ty = res_ty_inst }; | 966 | break :rl .{ .ref_coerced_ty = res_ty_inst }; |
| 967 | } else .ref; | 967 | } else .ref; |
| 968 | const result = try expr(gz, scope, .{ .rl = operand_rl }, tree.nodeData(node).node); | 968 | const result = try expr(gz, scope, .{ .rl = operand_rl }, node.data(tree).node); |
| 969 | return rvalue(gz, ri, result, node); | 969 | return rvalue(gz, ri, result, node); |
| 970 | }, | 970 | }, |
| 971 | .optional_type => { | 971 | .optional_type => { |
| 972 | const operand = try typeExpr(gz, scope, tree.nodeData(node).node); | 972 | const operand = try typeExpr(gz, scope, node.data(tree).node); |
| 973 | const result = try gz.addUnNode(.optional_type, operand, node); | 973 | const result = try gz.addUnNode(.optional_type, operand, node); |
| 974 | return rvalue(gz, ri, result, node); | 974 | return rvalue(gz, ri, result, node); |
| 975 | }, | 975 | }, |
| 976 | .unwrap_optional => switch (ri.rl) { | 976 | .unwrap_optional => switch (ri.rl) { |
| 977 | .ref, .ref_coerced_ty => { | 977 | .ref, .ref_coerced_ty => { |
| 978 | const lhs = try expr(gz, scope, .{ .rl = .ref }, tree.nodeData(node).node_and_token[0]); | 978 | const lhs = try expr(gz, scope, .{ .rl = .ref }, node.data(tree).node_and_token[0]); |
| 979 | 979 | ||
| 980 | const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); | 980 | const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); |
| 981 | try emitDbgStmt(gz, cursor); | 981 | try emitDbgStmt(gz, cursor); |
| ... | @@ -983,7 +983,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -983,7 +983,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 983 | return gz.addUnNode(.optional_payload_safe_ptr, lhs, node); | 983 | return gz.addUnNode(.optional_payload_safe_ptr, lhs, node); |
| 984 | }, | 984 | }, |
| 985 | else => { | 985 | else => { |
| 986 | const lhs = try expr(gz, scope, .{ .rl = .none }, tree.nodeData(node).node_and_token[0]); | 986 | const lhs = try expr(gz, scope, .{ .rl = .none }, node.data(tree).node_and_token[0]); |
| 987 | 987 | ||
| 988 | const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); | 988 | const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); |
| 989 | try emitDbgStmt(gz, cursor); | 989 | try emitDbgStmt(gz, cursor); |
| ... | @@ -1001,7 +1001,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -1001,7 +1001,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 1001 | return blockExpr(gz, scope, ri, node, statements, .normal); | 1001 | return blockExpr(gz, scope, ri, node, statements, .normal); |
| 1002 | }, | 1002 | }, |
| 1003 | .enum_literal => if (try ri.rl.resultType(gz, node)) |res_ty| { | 1003 | .enum_literal => if (try ri.rl.resultType(gz, node)) |res_ty| { |
| 1004 | const str_index = try astgen.identAsString(tree.nodeMainToken(node)); | 1004 | const str_index = try astgen.identAsString(node.mainToken(tree)); |
| 1005 | const res = try gz.addPlNode(.decl_literal, node, Zir.Inst.Field{ | 1005 | const res = try gz.addPlNode(.decl_literal, node, Zir.Inst.Field{ |
| 1006 | .lhs = res_ty, | 1006 | .lhs = res_ty, |
| 1007 | .field_name_start = str_index, | 1007 | .field_name_start = str_index, |
| ... | @@ -1011,8 +1011,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -1011,8 +1011,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 1011 | .ty, .coerced_ty => return res, // `decl_literal` does the coercion for us | 1011 | .ty, .coerced_ty => return res, // `decl_literal` does the coercion for us |
| 1012 | .ref_coerced_ty, .ptr, .inferred_ptr, .destructure => return rvalue(gz, ri, res, node), | 1012 | .ref_coerced_ty, .ptr, .inferred_ptr, .destructure => return rvalue(gz, ri, res, node), |
| 1013 | } | 1013 | } |
| 1014 | } else return simpleStrTok(gz, ri, tree.nodeMainToken(node), node, .enum_literal), | 1014 | } else return simpleStrTok(gz, ri, node.mainToken(tree), node, .enum_literal), |
| 1015 | .error_value => return simpleStrTok(gz, ri, tree.nodeMainToken(node) + 2, node, .error_value), | 1015 | .error_value => return simpleStrTok(gz, ri, node.mainToken(tree) + 2, node, .error_value), |
| 1016 | // TODO restore this when implementing https://github.com/ziglang/zig/issues/6025 | 1016 | // TODO restore this when implementing https://github.com/ziglang/zig/issues/6025 |
| 1017 | // .anyframe_literal => return rvalue(gz, ri, .anyframe_type, node), | 1017 | // .anyframe_literal => return rvalue(gz, ri, .anyframe_type, node), |
| 1018 | .anyframe_literal => { | 1018 | .anyframe_literal => { |
| ... | @@ -1020,22 +1020,22 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -1020,22 +1020,22 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 1020 | return rvalue(gz, ri, result, node); | 1020 | return rvalue(gz, ri, result, node); |
| 1021 | }, | 1021 | }, |
| 1022 | .anyframe_type => { | 1022 | .anyframe_type => { |
| 1023 | const return_type = try typeExpr(gz, scope, tree.nodeData(node).token_and_node[1]); | 1023 | const return_type = try typeExpr(gz, scope, node.data(tree).token_and_node[1]); |
| 1024 | const result = try gz.addUnNode(.anyframe_type, return_type, node); | 1024 | const result = try gz.addUnNode(.anyframe_type, return_type, node); |
| 1025 | return rvalue(gz, ri, result, node); | 1025 | return rvalue(gz, ri, result, node); |
| 1026 | }, | 1026 | }, |
| 1027 | .@"catch" => { | 1027 | .@"catch" => { |
| 1028 | const catch_token = tree.nodeMainToken(node); | 1028 | const catch_token = node.mainToken(tree); |
| 1029 | const payload_token: ?Ast.TokenIndex = if (tree.tokenTag(catch_token + 1) == .pipe) | 1029 | const payload_token: ?Ast.TokenIndex = if (tree.tokenTag(catch_token + 1) == .pipe) |
| 1030 | catch_token + 2 | 1030 | catch_token + 2 |
| 1031 | else | 1031 | else |
| 1032 | null; | 1032 | null; |
| 1033 | no_switch_on_err: { | 1033 | no_switch_on_err: { |
| 1034 | const capture_token = payload_token orelse break :no_switch_on_err; | 1034 | const capture_token = payload_token orelse break :no_switch_on_err; |
| 1035 | const full_switch = tree.fullSwitch(tree.nodeData(node).node_and_node[1]) orelse break :no_switch_on_err; | 1035 | const full_switch = tree.fullSwitch(node.data(tree).node_and_node[1]) orelse break :no_switch_on_err; |
| 1036 | if (full_switch.label_token != null) break :no_switch_on_err; | 1036 | if (full_switch.label_token != null) break :no_switch_on_err; |
| 1037 | if (tree.nodeTag(full_switch.ast.condition) != .identifier) break :no_switch_on_err; | 1037 | if (full_switch.ast.condition.tag(tree) != .identifier) break :no_switch_on_err; |
| 1038 | if (!mem.eql(u8, tree.tokenSlice(capture_token), tree.tokenSlice(tree.nodeMainToken(full_switch.ast.condition)))) break :no_switch_on_err; | 1038 | if (!mem.eql(u8, tree.tokenSlice(capture_token), tree.tokenSlice(full_switch.ast.condition.mainToken(tree)))) break :no_switch_on_err; |
| 1039 | return switchExprErrUnion(gz, scope, ri.br(), node, .@"catch"); | 1039 | return switchExprErrUnion(gz, scope, ri.br(), node, .@"catch"); |
| 1040 | } | 1040 | } |
| 1041 | switch (ri.rl) { | 1041 | switch (ri.rl) { |
| ... | @@ -1109,7 +1109,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -1109,7 +1109,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 1109 | 1109 | ||
| 1110 | .@"break" => return breakExpr(gz, scope, node), | 1110 | .@"break" => return breakExpr(gz, scope, node), |
| 1111 | .@"continue" => return continueExpr(gz, scope, node), | 1111 | .@"continue" => return continueExpr(gz, scope, node), |
| 1112 | .grouped_expression => return expr(gz, scope, ri, tree.nodeData(node).node_and_token[0]), | 1112 | .grouped_expression => return expr(gz, scope, ri, node.data(tree).node_and_token[0]), |
| 1113 | .array_type => return arrayType(gz, scope, ri, node), | 1113 | .array_type => return arrayType(gz, scope, ri, node), |
| 1114 | .array_type_sentinel => return arrayTypeSentinel(gz, scope, ri, node), | 1114 | .array_type_sentinel => return arrayTypeSentinel(gz, scope, ri, node), |
| 1115 | .char_literal => return charLiteral(gz, ri, node), | 1115 | .char_literal => return charLiteral(gz, ri, node), |
| ... | @@ -1123,7 +1123,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -1123,7 +1123,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 1123 | .@"await" => return awaitExpr(gz, scope, ri, node), | 1123 | .@"await" => return awaitExpr(gz, scope, ri, node), |
| 1124 | .@"resume" => return resumeExpr(gz, scope, ri, node), | 1124 | .@"resume" => return resumeExpr(gz, scope, ri, node), |
| 1125 | 1125 | ||
| 1126 | .@"try" => return tryExpr(gz, scope, ri, node, tree.nodeData(node).node), | 1126 | .@"try" => return tryExpr(gz, scope, ri, node, node.data(tree).node), |
| 1127 | 1127 | ||
| 1128 | .array_init_one, | 1128 | .array_init_one, |
| 1129 | .array_init_one_comma, | 1129 | .array_init_one_comma, |
| ... | @@ -1170,7 +1170,7 @@ fn nosuspendExpr( | ... | @@ -1170,7 +1170,7 @@ fn nosuspendExpr( |
| 1170 | ) InnerError!Zir.Inst.Ref { | 1170 | ) InnerError!Zir.Inst.Ref { |
| 1171 | const astgen = gz.astgen; | 1171 | const astgen = gz.astgen; |
| 1172 | const tree = astgen.tree; | 1172 | const tree = astgen.tree; |
| 1173 | const body_node = tree.nodeData(node).node; | 1173 | const body_node = node.data(tree).node; |
| 1174 | if (gz.nosuspend_node.unwrap()) |nosuspend_node| { | 1174 | if (gz.nosuspend_node.unwrap()) |nosuspend_node| { |
| 1175 | try astgen.appendErrorNodeNotes(node, "redundant nosuspend block", .{}, &[_]u32{ | 1175 | try astgen.appendErrorNodeNotes(node, "redundant nosuspend block", .{}, &[_]u32{ |
| 1176 | try astgen.errNoteNode(nosuspend_node, "other nosuspend block here", .{}), | 1176 | try astgen.errNoteNode(nosuspend_node, "other nosuspend block here", .{}), |
| ... | @@ -1189,7 +1189,7 @@ fn suspendExpr( | ... | @@ -1189,7 +1189,7 @@ fn suspendExpr( |
| 1189 | const astgen = gz.astgen; | 1189 | const astgen = gz.astgen; |
| 1190 | const gpa = astgen.gpa; | 1190 | const gpa = astgen.gpa; |
| 1191 | const tree = astgen.tree; | 1191 | const tree = astgen.tree; |
| 1192 | const body_node = tree.nodeData(node).node; | 1192 | const body_node = node.data(tree).node; |
| 1193 | 1193 | ||
| 1194 | if (gz.nosuspend_node.unwrap()) |nosuspend_node| { | 1194 | if (gz.nosuspend_node.unwrap()) |nosuspend_node| { |
| 1195 | return astgen.failNodeNotes(node, "suspend inside nosuspend block", .{}, &[_]u32{ | 1195 | return astgen.failNodeNotes(node, "suspend inside nosuspend block", .{}, &[_]u32{ |
| ... | @@ -1226,7 +1226,7 @@ fn awaitExpr( | ... | @@ -1226,7 +1226,7 @@ fn awaitExpr( |
| 1226 | ) InnerError!Zir.Inst.Ref { | 1226 | ) InnerError!Zir.Inst.Ref { |
| 1227 | const astgen = gz.astgen; | 1227 | const astgen = gz.astgen; |
| 1228 | const tree = astgen.tree; | 1228 | const tree = astgen.tree; |
| 1229 | const rhs_node = tree.nodeData(node).node; | 1229 | const rhs_node = node.data(tree).node; |
| 1230 | 1230 | ||
| 1231 | if (gz.suspend_node.unwrap()) |suspend_node| { | 1231 | if (gz.suspend_node.unwrap()) |suspend_node| { |
| 1232 | return astgen.failNodeNotes(node, "cannot await inside suspend block", .{}, &[_]u32{ | 1232 | return astgen.failNodeNotes(node, "cannot await inside suspend block", .{}, &[_]u32{ |
| ... | @@ -1253,7 +1253,7 @@ fn resumeExpr( | ... | @@ -1253,7 +1253,7 @@ fn resumeExpr( |
| 1253 | ) InnerError!Zir.Inst.Ref { | 1253 | ) InnerError!Zir.Inst.Ref { |
| 1254 | const astgen = gz.astgen; | 1254 | const astgen = gz.astgen; |
| 1255 | const tree = astgen.tree; | 1255 | const tree = astgen.tree; |
| 1256 | const rhs_node = tree.nodeData(node).node; | 1256 | const rhs_node = node.data(tree).node; |
| 1257 | const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node); | 1257 | const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node); |
| 1258 | const result = try gz.addUnNode(.@"resume", operand, node); | 1258 | const result = try gz.addUnNode(.@"resume", operand, node); |
| 1259 | return rvalue(gz, ri, result, node); | 1259 | return rvalue(gz, ri, result, node); |
| ... | @@ -1363,7 +1363,7 @@ fn fnProtoExprInner( | ... | @@ -1363,7 +1363,7 @@ fn fnProtoExprInner( |
| 1363 | const param_type = try fullBodyExpr(&param_gz, scope, coerced_type_ri, param_type_node, .normal); | 1363 | const param_type = try fullBodyExpr(&param_gz, scope, coerced_type_ri, param_type_node, .normal); |
| 1364 | const param_inst_expected: Zir.Inst.Index = @enumFromInt(astgen.instructions.len + 1); | 1364 | const param_inst_expected: Zir.Inst.Index = @enumFromInt(astgen.instructions.len + 1); |
| 1365 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); | 1365 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 1366 | const name_token = param.name_token orelse tree.nodeMainToken(param_type_node); | 1366 | const name_token = param.name_token orelse param_type_node.mainToken(tree); |
| 1367 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; | 1367 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; |
| 1368 | // We pass `prev_param_insts` as `&.{}` here because a function prototype can't refer to previous | 1368 | // We pass `prev_param_insts` as `&.{}` here because a function prototype can't refer to previous |
| 1369 | // arguments (we haven't set up scopes here). | 1369 | // arguments (we haven't set up scopes here). |
| ... | @@ -1437,8 +1437,8 @@ fn arrayInitExpr( | ... | @@ -1437,8 +1437,8 @@ fn arrayInitExpr( |
| 1437 | infer: { | 1437 | infer: { |
| 1438 | const array_type: Ast.full.ArrayType = tree.fullArrayType(type_expr) orelse break :infer; | 1438 | const array_type: Ast.full.ArrayType = tree.fullArrayType(type_expr) orelse break :infer; |
| 1439 | // This intentionally does not support `@"_"` syntax. | 1439 | // This intentionally does not support `@"_"` syntax. |
| 1440 | if (tree.nodeTag(array_type.ast.elem_count) == .identifier and | 1440 | if (array_type.ast.elem_count.tag(tree) == .identifier and |
| 1441 | mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(array_type.ast.elem_count)), "_")) | 1441 | mem.eql(u8, tree.tokenSlice(array_type.ast.elem_count.mainToken(tree)), "_")) |
| 1442 | { | 1442 | { |
| 1443 | const len_inst = try gz.addInt(array_init.ast.elements.len); | 1443 | const len_inst = try gz.addInt(array_init.ast.elements.len); |
| 1444 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); | 1444 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); |
| ... | @@ -1705,9 +1705,9 @@ fn structInitExpr( | ... | @@ -1705,9 +1705,9 @@ fn structInitExpr( |
| 1705 | } | 1705 | } |
| 1706 | break :array; | 1706 | break :array; |
| 1707 | }; | 1707 | }; |
| 1708 | const is_inferred_array_len = tree.nodeTag(array_type.ast.elem_count) == .identifier and | 1708 | const is_inferred_array_len = array_type.ast.elem_count.tag(tree) == .identifier and |
| 1709 | // This intentionally does not support `@"_"` syntax. | 1709 | // This intentionally does not support `@"_"` syntax. |
| 1710 | mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(array_type.ast.elem_count)), "_"); | 1710 | mem.eql(u8, tree.tokenSlice(array_type.ast.elem_count.mainToken(tree)), "_"); |
| 1711 | if (struct_init.ast.fields.len == 0) { | 1711 | if (struct_init.ast.fields.len == 0) { |
| 1712 | if (is_inferred_array_len) { | 1712 | if (is_inferred_array_len) { |
| 1713 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); | 1713 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); |
| ... | @@ -1987,7 +1987,7 @@ fn comptimeExpr2( | ... | @@ -1987,7 +1987,7 @@ fn comptimeExpr2( |
| 1987 | // no need to wrap it in a block. This is hard to determine in general, but we can identify a | 1987 | // no need to wrap it in a block. This is hard to determine in general, but we can identify a |
| 1988 | // common subset of trivially comptime expressions to take down the size of the ZIR a bit. | 1988 | // common subset of trivially comptime expressions to take down the size of the ZIR a bit. |
| 1989 | const tree = gz.astgen.tree; | 1989 | const tree = gz.astgen.tree; |
| 1990 | switch (tree.nodeTag(node)) { | 1990 | switch (node.tag(tree)) { |
| 1991 | .identifier => { | 1991 | .identifier => { |
| 1992 | // Many identifiers can be handled without a `block_comptime`, so `AstGen.identifier` has | 1992 | // Many identifiers can be handled without a `block_comptime`, so `AstGen.identifier` has |
| 1993 | // special handling for this case. | 1993 | // special handling for this case. |
| ... | @@ -2040,7 +2040,7 @@ fn comptimeExpr2( | ... | @@ -2040,7 +2040,7 @@ fn comptimeExpr2( |
| 2040 | // comptime block, because that would be silly! Note that we don't bother doing this for | 2040 | // comptime block, because that would be silly! Note that we don't bother doing this for |
| 2041 | // unlabelled blocks, since they don't generate blocks at comptime anyway (see `blockExpr`). | 2041 | // unlabelled blocks, since they don't generate blocks at comptime anyway (see `blockExpr`). |
| 2042 | .block_two, .block_two_semicolon, .block, .block_semicolon => { | 2042 | .block_two, .block_two_semicolon, .block, .block_semicolon => { |
| 2043 | const lbrace = tree.nodeMainToken(node); | 2043 | const lbrace = node.mainToken(tree); |
| 2044 | // Careful! We can't pass in the real result location here, since it may | 2044 | // Careful! We can't pass in the real result location here, since it may |
| 2045 | // refer to runtime memory. A runtime-to-comptime boundary has to remove | 2045 | // refer to runtime memory. A runtime-to-comptime boundary has to remove |
| 2046 | // result location information, compute the result, and copy it to the true | 2046 | // result location information, compute the result, and copy it to the true |
| ... | @@ -2103,7 +2103,7 @@ fn comptimeExprAst( | ... | @@ -2103,7 +2103,7 @@ fn comptimeExprAst( |
| 2103 | try astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{}); | 2103 | try astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{}); |
| 2104 | } | 2104 | } |
| 2105 | const tree = astgen.tree; | 2105 | const tree = astgen.tree; |
| 2106 | const body_node = tree.nodeData(node).node; | 2106 | const body_node = node.data(tree).node; |
| 2107 | return comptimeExpr2(gz, scope, ri, body_node, node, .comptime_keyword); | 2107 | return comptimeExpr2(gz, scope, ri, body_node, node, .comptime_keyword); |
| 2108 | } | 2108 | } |
| 2109 | 2109 | ||
| ... | @@ -2141,7 +2141,7 @@ fn restoreErrRetIndex( | ... | @@ -2141,7 +2141,7 @@ fn restoreErrRetIndex( |
| 2141 | fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref { | 2141 | fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref { |
| 2142 | const astgen = parent_gz.astgen; | 2142 | const astgen = parent_gz.astgen; |
| 2143 | const tree = astgen.tree; | 2143 | const tree = astgen.tree; |
| 2144 | const opt_break_label, const opt_rhs = tree.nodeData(node).opt_token_and_opt_node; | 2144 | const opt_break_label, const opt_rhs = node.data(tree).opt_token_and_opt_node; |
| 2145 | 2145 | ||
| 2146 | // Look for the label in the scope. | 2146 | // Look for the label in the scope. |
| 2147 | var scope = parent_scope; | 2147 | var scope = parent_scope; |
| ... | @@ -2237,7 +2237,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn | ... | @@ -2237,7 +2237,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn |
| 2237 | fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref { | 2237 | fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref { |
| 2238 | const astgen = parent_gz.astgen; | 2238 | const astgen = parent_gz.astgen; |
| 2239 | const tree = astgen.tree; | 2239 | const tree = astgen.tree; |
| 2240 | const opt_break_label, const opt_rhs = tree.nodeData(node).opt_token_and_opt_node; | 2240 | const opt_break_label, const opt_rhs = node.data(tree).opt_token_and_opt_node; |
| 2241 | 2241 | ||
| 2242 | if (opt_break_label == .none and opt_rhs != .none) { | 2242 | if (opt_break_label == .none and opt_rhs != .none) { |
| 2243 | return astgen.failNode(node, "cannot continue with operand without label", .{}); | 2243 | return astgen.failNode(node, "cannot continue with operand without label", .{}); |
| ... | @@ -2359,7 +2359,7 @@ fn fullBodyExpr( | ... | @@ -2359,7 +2359,7 @@ fn fullBodyExpr( |
| 2359 | const statements = tree.blockStatements(&stmt_buf, node) orelse | 2359 | const statements = tree.blockStatements(&stmt_buf, node) orelse |
| 2360 | return expr(gz, scope, ri, node); | 2360 | return expr(gz, scope, ri, node); |
| 2361 | 2361 | ||
| 2362 | const lbrace = tree.nodeMainToken(node); | 2362 | const lbrace = node.mainToken(tree); |
| 2363 | 2363 | ||
| 2364 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { | 2364 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { |
| 2365 | // Labeled blocks are tricky - forwarding result location information properly is non-trivial, | 2365 | // Labeled blocks are tricky - forwarding result location information properly is non-trivial, |
| ... | @@ -2387,7 +2387,7 @@ fn blockExpr( | ... | @@ -2387,7 +2387,7 @@ fn blockExpr( |
| 2387 | const astgen = gz.astgen; | 2387 | const astgen = gz.astgen; |
| 2388 | const tree = astgen.tree; | 2388 | const tree = astgen.tree; |
| 2389 | 2389 | ||
| 2390 | const lbrace = tree.nodeMainToken(block_node); | 2390 | const lbrace = block_node.mainToken(tree); |
| 2391 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { | 2391 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { |
| 2392 | return labeledBlockExpr(gz, scope, ri, block_node, statements, false, kind); | 2392 | return labeledBlockExpr(gz, scope, ri, block_node, statements, false, kind); |
| 2393 | } | 2393 | } |
| ... | @@ -2466,7 +2466,7 @@ fn labeledBlockExpr( | ... | @@ -2466,7 +2466,7 @@ fn labeledBlockExpr( |
| 2466 | const astgen = gz.astgen; | 2466 | const astgen = gz.astgen; |
| 2467 | const tree = astgen.tree; | 2467 | const tree = astgen.tree; |
| 2468 | 2468 | ||
| 2469 | const lbrace = tree.nodeMainToken(block_node); | 2469 | const lbrace = block_node.mainToken(tree); |
| 2470 | const label_token = lbrace - 2; | 2470 | const label_token = lbrace - 2; |
| 2471 | assert(tree.tokenTag(label_token) == .identifier); | 2471 | assert(tree.tokenTag(label_token) == .identifier); |
| 2472 | 2472 | ||
| ... | @@ -2559,7 +2559,7 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod | ... | @@ -2559,7 +2559,7 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod |
| 2559 | }; | 2559 | }; |
| 2560 | var inner_node = statement; | 2560 | var inner_node = statement; |
| 2561 | while (true) { | 2561 | while (true) { |
| 2562 | switch (tree.nodeTag(inner_node)) { | 2562 | switch (inner_node.tag(tree)) { |
| 2563 | // zig fmt: off | 2563 | // zig fmt: off |
| 2564 | .global_var_decl, | 2564 | .global_var_decl, |
| 2565 | .local_var_decl, | 2565 | .local_var_decl, |
| ... | @@ -2589,7 +2589,7 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod | ... | @@ -2589,7 +2589,7 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod |
| 2589 | .assign_mul_wrap => try assignOp(gz, scope, statement, .mulwrap), | 2589 | .assign_mul_wrap => try assignOp(gz, scope, statement, .mulwrap), |
| 2590 | 2590 | ||
| 2591 | .grouped_expression => { | 2591 | .grouped_expression => { |
| 2592 | inner_node = tree.nodeData(statement).node_and_token[0]; | 2592 | inner_node = statement.data(tree).node_and_token[0]; |
| 2593 | continue; | 2593 | continue; |
| 2594 | }, | 2594 | }, |
| 2595 | 2595 | ||
| ... | @@ -3122,7 +3122,7 @@ fn deferStmt( | ... | @@ -3122,7 +3122,7 @@ fn deferStmt( |
| 3122 | var local_val_scope: Scope.LocalVal = undefined; | 3122 | var local_val_scope: Scope.LocalVal = undefined; |
| 3123 | var opt_remapped_err_code: Zir.Inst.OptionalIndex = .none; | 3123 | var opt_remapped_err_code: Zir.Inst.OptionalIndex = .none; |
| 3124 | const sub_scope = if (scope_tag != .defer_error) &defer_gen.base else blk: { | 3124 | const sub_scope = if (scope_tag != .defer_error) &defer_gen.base else blk: { |
| 3125 | const payload_token = tree.nodeData(node).opt_token_and_node[0].unwrap() orelse break :blk &defer_gen.base; | 3125 | const payload_token = node.data(tree).opt_token_and_node[0].unwrap() orelse break :blk &defer_gen.base; |
| 3126 | const ident_name = try gz.astgen.identAsString(payload_token); | 3126 | const ident_name = try gz.astgen.identAsString(payload_token); |
| 3127 | if (std.mem.eql(u8, tree.tokenSlice(payload_token), "_")) { | 3127 | if (std.mem.eql(u8, tree.tokenSlice(payload_token), "_")) { |
| 3128 | try gz.astgen.appendErrorTok(payload_token, "discard of error capture; omit it instead", .{}); | 3128 | try gz.astgen.appendErrorTok(payload_token, "discard of error capture; omit it instead", .{}); |
| ... | @@ -3151,8 +3151,8 @@ fn deferStmt( | ... | @@ -3151,8 +3151,8 @@ fn deferStmt( |
| 3151 | break :blk &local_val_scope.base; | 3151 | break :blk &local_val_scope.base; |
| 3152 | }; | 3152 | }; |
| 3153 | const expr_node = switch (scope_tag) { | 3153 | const expr_node = switch (scope_tag) { |
| 3154 | .defer_normal => tree.nodeData(node).node, | 3154 | .defer_normal => node.data(tree).node, |
| 3155 | .defer_error => tree.nodeData(node).opt_token_and_node[1], | 3155 | .defer_error => node.data(tree).opt_token_and_node[1], |
| 3156 | else => unreachable, | 3156 | else => unreachable, |
| 3157 | }; | 3157 | }; |
| 3158 | _ = try unusedResultExpr(&defer_gen, sub_scope, expr_node); | 3158 | _ = try unusedResultExpr(&defer_gen, sub_scope, expr_node); |
| ... | @@ -3210,11 +3210,11 @@ fn varDecl( | ... | @@ -3210,11 +3210,11 @@ fn varDecl( |
| 3210 | }; | 3210 | }; |
| 3211 | 3211 | ||
| 3212 | if (var_decl.ast.addrspace_node.unwrap()) |addrspace_node| { | 3212 | if (var_decl.ast.addrspace_node.unwrap()) |addrspace_node| { |
| 3213 | return astgen.failTok(tree.nodeMainToken(addrspace_node), "cannot set address space of local variable '{s}'", .{ident_name_raw}); | 3213 | return astgen.failTok(addrspace_node.mainToken(tree), "cannot set address space of local variable '{s}'", .{ident_name_raw}); |
| 3214 | } | 3214 | } |
| 3215 | 3215 | ||
| 3216 | if (var_decl.ast.section_node.unwrap()) |section_node| { | 3216 | if (var_decl.ast.section_node.unwrap()) |section_node| { |
| 3217 | return astgen.failTok(tree.nodeMainToken(section_node), "cannot set section of local variable '{s}'", .{ident_name_raw}); | 3217 | return astgen.failTok(section_node.mainToken(tree), "cannot set section of local variable '{s}'", .{ident_name_raw}); |
| 3218 | } | 3218 | } |
| 3219 | 3219 | ||
| 3220 | const align_inst: Zir.Inst.Ref = if (var_decl.ast.align_node.unwrap()) |align_node| | 3220 | const align_inst: Zir.Inst.Ref = if (var_decl.ast.align_node.unwrap()) |align_node| |
| ... | @@ -3267,7 +3267,7 @@ fn varDecl( | ... | @@ -3267,7 +3267,7 @@ fn varDecl( |
| 3267 | } | 3267 | } |
| 3268 | 3268 | ||
| 3269 | const is_comptime = gz.is_comptime or | 3269 | const is_comptime = gz.is_comptime or |
| 3270 | tree.nodeTag(init_node) == .@"comptime"; | 3270 | init_node.tag(tree) == .@"comptime"; |
| 3271 | 3271 | ||
| 3272 | const init_rl: ResultInfo.Loc = if (var_decl.ast.type_node.unwrap()) |type_node| init_rl: { | 3272 | const init_rl: ResultInfo.Loc = if (var_decl.ast.type_node.unwrap()) |type_node| init_rl: { |
| 3273 | const type_inst = try typeExpr(gz, scope, type_node); | 3273 | const type_inst = try typeExpr(gz, scope, type_node); |
| ... | @@ -3430,10 +3430,10 @@ fn assign(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerError!voi | ... | @@ -3430,10 +3430,10 @@ fn assign(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerError!voi |
| 3430 | const astgen = gz.astgen; | 3430 | const astgen = gz.astgen; |
| 3431 | const tree = astgen.tree; | 3431 | const tree = astgen.tree; |
| 3432 | 3432 | ||
| 3433 | const lhs, const rhs = tree.nodeData(infix_node).node_and_node; | 3433 | const lhs, const rhs = infix_node.data(tree).node_and_node; |
| 3434 | if (tree.nodeTag(lhs) == .identifier) { | 3434 | if (lhs.tag(tree) == .identifier) { |
| 3435 | // This intentionally does not support `@"_"` syntax. | 3435 | // This intentionally does not support `@"_"` syntax. |
| 3436 | const ident_name = tree.tokenSlice(tree.nodeMainToken(lhs)); | 3436 | const ident_name = tree.tokenSlice(lhs.mainToken(tree)); |
| 3437 | if (mem.eql(u8, ident_name, "_")) { | 3437 | if (mem.eql(u8, ident_name, "_")) { |
| 3438 | _ = try expr(gz, scope, .{ .rl = .discard, .ctx = .assignment }, rhs); | 3438 | _ = try expr(gz, scope, .{ .rl = .discard, .ctx = .assignment }, rhs); |
| 3439 | return; | 3439 | return; |
| ... | @@ -3468,9 +3468,9 @@ fn assignDestructure(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerErro | ... | @@ -3468,9 +3468,9 @@ fn assignDestructure(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerErro |
| 3468 | 3468 | ||
| 3469 | const rl_components = try astgen.arena.alloc(ResultInfo.Loc.DestructureComponent, full.ast.variables.len); | 3469 | const rl_components = try astgen.arena.alloc(ResultInfo.Loc.DestructureComponent, full.ast.variables.len); |
| 3470 | for (rl_components, full.ast.variables) |*variable_rl, variable_node| { | 3470 | for (rl_components, full.ast.variables) |*variable_rl, variable_node| { |
| 3471 | if (tree.nodeTag(variable_node) == .identifier) { | 3471 | if (variable_node.tag(tree) == .identifier) { |
| 3472 | // This intentionally does not support `@"_"` syntax. | 3472 | // This intentionally does not support `@"_"` syntax. |
| 3473 | const ident_name = tree.tokenSlice(tree.nodeMainToken(variable_node)); | 3473 | const ident_name = tree.tokenSlice(variable_node.mainToken(tree)); |
| 3474 | if (mem.eql(u8, ident_name, "_")) { | 3474 | if (mem.eql(u8, ident_name, "_")) { |
| 3475 | variable_rl.* = .discard; | 3475 | variable_rl.* = .discard; |
| 3476 | continue; | 3476 | continue; |
| ... | @@ -3514,7 +3514,7 @@ fn assignDestructureMaybeDecls( | ... | @@ -3514,7 +3514,7 @@ fn assignDestructureMaybeDecls( |
| 3514 | } | 3514 | } |
| 3515 | 3515 | ||
| 3516 | const is_comptime = full.comptime_token != null or gz.is_comptime; | 3516 | const is_comptime = full.comptime_token != null or gz.is_comptime; |
| 3517 | const value_is_comptime = tree.nodeTag(full.ast.value_expr) == .@"comptime"; | 3517 | const value_is_comptime = full.ast.value_expr.tag(tree) == .@"comptime"; |
| 3518 | 3518 | ||
| 3519 | // When declaring consts via a destructure, we always use a result pointer. | 3519 | // When declaring consts via a destructure, we always use a result pointer. |
| 3520 | // This avoids the need to create tuple types, and is also likely easier to | 3520 | // This avoids the need to create tuple types, and is also likely easier to |
| ... | @@ -3527,10 +3527,10 @@ fn assignDestructureMaybeDecls( | ... | @@ -3527,10 +3527,10 @@ fn assignDestructureMaybeDecls( |
| 3527 | var any_non_const_variables = false; | 3527 | var any_non_const_variables = false; |
| 3528 | var any_lvalue_expr = false; | 3528 | var any_lvalue_expr = false; |
| 3529 | for (rl_components, full.ast.variables) |*variable_rl, variable_node| { | 3529 | for (rl_components, full.ast.variables) |*variable_rl, variable_node| { |
| 3530 | switch (tree.nodeTag(variable_node)) { | 3530 | switch (variable_node.tag(tree)) { |
| 3531 | .identifier => { | 3531 | .identifier => { |
| 3532 | // This intentionally does not support `@"_"` syntax. | 3532 | // This intentionally does not support `@"_"` syntax. |
| 3533 | const ident_name = tree.tokenSlice(tree.nodeMainToken(variable_node)); | 3533 | const ident_name = tree.tokenSlice(variable_node.mainToken(tree)); |
| 3534 | if (mem.eql(u8, ident_name, "_")) { | 3534 | if (mem.eql(u8, ident_name, "_")) { |
| 3535 | any_non_const_variables = true; | 3535 | any_non_const_variables = true; |
| 3536 | variable_rl.* = .discard; | 3536 | variable_rl.* = .discard; |
| ... | @@ -3549,10 +3549,10 @@ fn assignDestructureMaybeDecls( | ... | @@ -3549,10 +3549,10 @@ fn assignDestructureMaybeDecls( |
| 3549 | // We detect shadowing in the second pass over these, while we're creating scopes. | 3549 | // We detect shadowing in the second pass over these, while we're creating scopes. |
| 3550 | 3550 | ||
| 3551 | if (full_var_decl.ast.addrspace_node.unwrap()) |addrspace_node| { | 3551 | if (full_var_decl.ast.addrspace_node.unwrap()) |addrspace_node| { |
| 3552 | return astgen.failTok(tree.nodeMainToken(addrspace_node), "cannot set address space of local variable '{s}'", .{ident_name_raw}); | 3552 | return astgen.failTok(addrspace_node.mainToken(tree), "cannot set address space of local variable '{s}'", .{ident_name_raw}); |
| 3553 | } | 3553 | } |
| 3554 | if (full_var_decl.ast.section_node.unwrap()) |section_node| { | 3554 | if (full_var_decl.ast.section_node.unwrap()) |section_node| { |
| 3555 | return astgen.failTok(tree.nodeMainToken(section_node), "cannot set section of local variable '{s}'", .{ident_name_raw}); | 3555 | return astgen.failTok(section_node.mainToken(tree), "cannot set section of local variable '{s}'", .{ident_name_raw}); |
| 3556 | } | 3556 | } |
| 3557 | 3557 | ||
| 3558 | const is_const = switch (tree.tokenTag(full_var_decl.ast.mut_token)) { | 3558 | const is_const = switch (tree.tokenTag(full_var_decl.ast.mut_token)) { |
| ... | @@ -3641,7 +3641,7 @@ fn assignDestructureMaybeDecls( | ... | @@ -3641,7 +3641,7 @@ fn assignDestructureMaybeDecls( |
| 3641 | // evaluate the lvalues from within the possible block_comptime. | 3641 | // evaluate the lvalues from within the possible block_comptime. |
| 3642 | for (rl_components, full.ast.variables) |*variable_rl, variable_node| { | 3642 | for (rl_components, full.ast.variables) |*variable_rl, variable_node| { |
| 3643 | if (variable_rl.* != .typed_ptr) continue; | 3643 | if (variable_rl.* != .typed_ptr) continue; |
| 3644 | switch (tree.nodeTag(variable_node)) { | 3644 | switch (variable_node.tag(tree)) { |
| 3645 | .global_var_decl, .local_var_decl, .simple_var_decl, .aligned_var_decl => continue, | 3645 | .global_var_decl, .local_var_decl, .simple_var_decl, .aligned_var_decl => continue, |
| 3646 | else => {}, | 3646 | else => {}, |
| 3647 | } | 3647 | } |
| ... | @@ -3670,7 +3670,7 @@ fn assignDestructureMaybeDecls( | ... | @@ -3670,7 +3670,7 @@ fn assignDestructureMaybeDecls( |
| 3670 | // If there were any `const` decls, make the pointer constant. | 3670 | // If there were any `const` decls, make the pointer constant. |
| 3671 | var cur_scope = scope; | 3671 | var cur_scope = scope; |
| 3672 | for (rl_components, full.ast.variables) |variable_rl, variable_node| { | 3672 | for (rl_components, full.ast.variables) |variable_rl, variable_node| { |
| 3673 | switch (tree.nodeTag(variable_node)) { | 3673 | switch (variable_node.tag(tree)) { |
| 3674 | .local_var_decl, .simple_var_decl, .aligned_var_decl => {}, | 3674 | .local_var_decl, .simple_var_decl, .aligned_var_decl => {}, |
| 3675 | else => continue, // We were mutating an existing lvalue - nothing to do | 3675 | else => continue, // We were mutating an existing lvalue - nothing to do |
| 3676 | } | 3676 | } |
| ... | @@ -3732,7 +3732,7 @@ fn assignOp( | ... | @@ -3732,7 +3732,7 @@ fn assignOp( |
| 3732 | const astgen = gz.astgen; | 3732 | const astgen = gz.astgen; |
| 3733 | const tree = astgen.tree; | 3733 | const tree = astgen.tree; |
| 3734 | 3734 | ||
| 3735 | const lhs_node, const rhs_node = tree.nodeData(infix_node).node_and_node; | 3735 | const lhs_node, const rhs_node = infix_node.data(tree).node_and_node; |
| 3736 | const lhs_ptr = try lvalExpr(gz, scope, lhs_node); | 3736 | const lhs_ptr = try lvalExpr(gz, scope, lhs_node); |
| 3737 | 3737 | ||
| 3738 | const cursor = switch (op_inst_tag) { | 3738 | const cursor = switch (op_inst_tag) { |
| ... | @@ -3787,7 +3787,7 @@ fn assignShift( | ... | @@ -3787,7 +3787,7 @@ fn assignShift( |
| 3787 | const astgen = gz.astgen; | 3787 | const astgen = gz.astgen; |
| 3788 | const tree = astgen.tree; | 3788 | const tree = astgen.tree; |
| 3789 | 3789 | ||
| 3790 | const lhs_node, const rhs_node = tree.nodeData(infix_node).node_and_node; | 3790 | const lhs_node, const rhs_node = infix_node.data(tree).node_and_node; |
| 3791 | const lhs_ptr = try lvalExpr(gz, scope, lhs_node); | 3791 | const lhs_ptr = try lvalExpr(gz, scope, lhs_node); |
| 3792 | const lhs = try gz.addUnNode(.load, lhs_ptr, infix_node); | 3792 | const lhs = try gz.addUnNode(.load, lhs_ptr, infix_node); |
| 3793 | const rhs_type = try gz.addUnNode(.typeof_log2_int_type, lhs, infix_node); | 3793 | const rhs_type = try gz.addUnNode(.typeof_log2_int_type, lhs, infix_node); |
| ... | @@ -3808,7 +3808,7 @@ fn assignShiftSat(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerE | ... | @@ -3808,7 +3808,7 @@ fn assignShiftSat(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerE |
| 3808 | const astgen = gz.astgen; | 3808 | const astgen = gz.astgen; |
| 3809 | const tree = astgen.tree; | 3809 | const tree = astgen.tree; |
| 3810 | 3810 | ||
| 3811 | const lhs_node, const rhs_node = tree.nodeData(infix_node).node_and_node; | 3811 | const lhs_node, const rhs_node = infix_node.data(tree).node_and_node; |
| 3812 | const lhs_ptr = try lvalExpr(gz, scope, lhs_node); | 3812 | const lhs_ptr = try lvalExpr(gz, scope, lhs_node); |
| 3813 | const lhs = try gz.addUnNode(.load, lhs_ptr, infix_node); | 3813 | const lhs = try gz.addUnNode(.load, lhs_ptr, infix_node); |
| 3814 | // Saturating shift-left allows any integer type for both the LHS and RHS. | 3814 | // Saturating shift-left allows any integer type for both the LHS and RHS. |
| ... | @@ -3940,9 +3940,9 @@ fn arrayType(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) ! | ... | @@ -3940,9 +3940,9 @@ fn arrayType(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) ! |
| 3940 | const astgen = gz.astgen; | 3940 | const astgen = gz.astgen; |
| 3941 | const tree = astgen.tree; | 3941 | const tree = astgen.tree; |
| 3942 | 3942 | ||
| 3943 | const len_node, const elem_type_node = tree.nodeData(node).node_and_node; | 3943 | const len_node, const elem_type_node = node.data(tree).node_and_node; |
| 3944 | if (tree.nodeTag(len_node) == .identifier and | 3944 | if (len_node.tag(tree) == .identifier and |
| 3945 | mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(len_node)), "_")) | 3945 | mem.eql(u8, tree.tokenSlice(len_node.mainToken(tree)), "_")) |
| 3946 | { | 3946 | { |
| 3947 | return astgen.failNode(len_node, "unable to infer array size", .{}); | 3947 | return astgen.failNode(len_node, "unable to infer array size", .{}); |
| 3948 | } | 3948 | } |
| ... | @@ -3960,11 +3960,11 @@ fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node. | ... | @@ -3960,11 +3960,11 @@ fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node. |
| 3960 | const astgen = gz.astgen; | 3960 | const astgen = gz.astgen; |
| 3961 | const tree = astgen.tree; | 3961 | const tree = astgen.tree; |
| 3962 | 3962 | ||
| 3963 | const len_node, const extra_index = tree.nodeData(node).node_and_extra; | 3963 | const len_node, const extra_index = node.data(tree).node_and_extra; |
| 3964 | const extra = tree.extraData(extra_index, Ast.Node.ArrayTypeSentinel); | 3964 | const extra = tree.extraData(extra_index, Ast.Node.ArrayTypeSentinel); |
| 3965 | 3965 | ||
| 3966 | if (tree.nodeTag(len_node) == .identifier and | 3966 | if (len_node.tag(tree) == .identifier and |
| 3967 | mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(len_node)), "_")) | 3967 | mem.eql(u8, tree.tokenSlice(len_node.mainToken(tree)), "_")) |
| 3968 | { | 3968 | { |
| 3969 | return astgen.failNode(len_node, "unable to infer array size", .{}); | 3969 | return astgen.failNode(len_node, "unable to infer array size", .{}); |
| 3970 | } | 3970 | } |
| ... | @@ -4288,8 +4288,8 @@ fn fnDeclInner( | ... | @@ -4288,8 +4288,8 @@ fn fnDeclInner( |
| 4288 | } else { | 4288 | } else { |
| 4289 | const type_expr = param.type_expr.?; | 4289 | const type_expr = param.type_expr.?; |
| 4290 | ambiguous: { | 4290 | ambiguous: { |
| 4291 | if (tree.nodeTag(type_expr) != .identifier) break :ambiguous; | 4291 | if (type_expr.tag(tree) != .identifier) break :ambiguous; |
| 4292 | const main_token = tree.nodeMainToken(type_expr); | 4292 | const main_token = type_expr.mainToken(tree); |
| 4293 | const identifier_str = tree.tokenSlice(main_token); | 4293 | const identifier_str = tree.tokenSlice(main_token); |
| 4294 | if (isPrimitive(identifier_str)) break :ambiguous; | 4294 | if (isPrimitive(identifier_str)) break :ambiguous; |
| 4295 | return astgen.failNodeNotes( | 4295 | return astgen.failNodeNotes( |
| ... | @@ -4331,7 +4331,7 @@ fn fnDeclInner( | ... | @@ -4331,7 +4331,7 @@ fn fnDeclInner( |
| 4331 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); | 4331 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 4332 | const param_type_is_generic = any_param_used; | 4332 | const param_type_is_generic = any_param_used; |
| 4333 | 4333 | ||
| 4334 | const name_token = param.name_token orelse tree.nodeMainToken(param_type_node); | 4334 | const name_token = param.name_token orelse param_type_node.mainToken(tree); |
| 4335 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; | 4335 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; |
| 4336 | const param_inst = try decl_gz.addParam(&param_gz, param_insts.items, param_type_is_generic, tag, name_token, param_name); | 4336 | const param_inst = try decl_gz.addParam(&param_gz, param_insts.items, param_type_is_generic, tag, name_token, param_name); |
| 4337 | assert(param_inst_expected == param_inst); | 4337 | assert(param_inst_expected == param_inst); |
| ... | @@ -4428,7 +4428,7 @@ fn fnDeclInner( | ... | @@ -4428,7 +4428,7 @@ fn fnDeclInner( |
| 4428 | // Leave `astgen.src_hasher` unmodified; this will be used for hashing | 4428 | // Leave `astgen.src_hasher` unmodified; this will be used for hashing |
| 4429 | // the *whole* function declaration, including its body. | 4429 | // the *whole* function declaration, including its body. |
| 4430 | var proto_hasher = astgen.src_hasher; | 4430 | var proto_hasher = astgen.src_hasher; |
| 4431 | const proto_node = tree.nodeData(decl_node).node_and_node[0]; | 4431 | const proto_node = decl_node.data(tree).node_and_node[0]; |
| 4432 | proto_hasher.update(tree.getNodeSource(proto_node)); | 4432 | proto_hasher.update(tree.getNodeSource(proto_node)); |
| 4433 | var proto_hash: std.zig.SrcHash = undefined; | 4433 | var proto_hash: std.zig.SrcHash = undefined; |
| 4434 | proto_hasher.final(&proto_hash); | 4434 | proto_hasher.final(&proto_hash); |
| ... | @@ -4643,7 +4643,7 @@ fn comptimeDecl( | ... | @@ -4643,7 +4643,7 @@ fn comptimeDecl( |
| 4643 | node: Ast.Node.Index, | 4643 | node: Ast.Node.Index, |
| 4644 | ) InnerError!void { | 4644 | ) InnerError!void { |
| 4645 | const tree = astgen.tree; | 4645 | const tree = astgen.tree; |
| 4646 | const body_node = tree.nodeData(node).node; | 4646 | const body_node = node.data(tree).node; |
| 4647 | 4647 | ||
| 4648 | const old_hasher = astgen.src_hasher; | 4648 | const old_hasher = astgen.src_hasher; |
| 4649 | defer astgen.src_hasher = old_hasher; | 4649 | defer astgen.src_hasher = old_hasher; |
| ... | @@ -4713,8 +4713,8 @@ fn usingnamespaceDecl( | ... | @@ -4713,8 +4713,8 @@ fn usingnamespaceDecl( |
| 4713 | astgen.src_hasher.update(tree.getNodeSource(node)); | 4713 | astgen.src_hasher.update(tree.getNodeSource(node)); |
| 4714 | astgen.src_hasher.update(std.mem.asBytes(&astgen.source_column)); | 4714 | astgen.src_hasher.update(std.mem.asBytes(&astgen.source_column)); |
| 4715 | 4715 | ||
| 4716 | const type_expr = tree.nodeData(node).node; | 4716 | const type_expr = node.data(tree).node; |
| 4717 | const is_pub = tree.isTokenPrecededByTags(tree.nodeMainToken(node), &.{.keyword_pub}); | 4717 | const is_pub = tree.isTokenPrecededByTags(node.mainToken(tree), &.{.keyword_pub}); |
| 4718 | 4718 | ||
| 4719 | // Up top so the ZIR instruction index marks the start range of this | 4719 | // Up top so the ZIR instruction index marks the start range of this |
| 4720 | // top-level declaration. | 4720 | // top-level declaration. |
| ... | @@ -4769,7 +4769,7 @@ fn testDecl( | ... | @@ -4769,7 +4769,7 @@ fn testDecl( |
| 4769 | node: Ast.Node.Index, | 4769 | node: Ast.Node.Index, |
| 4770 | ) InnerError!void { | 4770 | ) InnerError!void { |
| 4771 | const tree = astgen.tree; | 4771 | const tree = astgen.tree; |
| 4772 | _, const body_node = tree.nodeData(node).opt_token_and_node; | 4772 | _, const body_node = node.data(tree).opt_token_and_node; |
| 4773 | 4773 | ||
| 4774 | const old_hasher = astgen.src_hasher; | 4774 | const old_hasher = astgen.src_hasher; |
| 4775 | defer astgen.src_hasher = old_hasher; | 4775 | defer astgen.src_hasher = old_hasher; |
| ... | @@ -4801,7 +4801,7 @@ fn testDecl( | ... | @@ -4801,7 +4801,7 @@ fn testDecl( |
| 4801 | 4801 | ||
| 4802 | const decl_column = astgen.source_column; | 4802 | const decl_column = astgen.source_column; |
| 4803 | 4803 | ||
| 4804 | const test_token = tree.nodeMainToken(node); | 4804 | const test_token = node.mainToken(tree); |
| 4805 | 4805 | ||
| 4806 | const test_name_token = test_token + 1; | 4806 | const test_name_token = test_token + 1; |
| 4807 | const test_name: Zir.NullTerminatedString = switch (tree.tokenTag(test_name_token)) { | 4807 | const test_name: Zir.NullTerminatedString = switch (tree.tokenTag(test_name_token)) { |
| ... | @@ -5275,7 +5275,7 @@ fn tupleDecl( | ... | @@ -5275,7 +5275,7 @@ fn tupleDecl( |
| 5275 | 5275 | ||
| 5276 | for (container_decl.ast.members) |member_node| { | 5276 | for (container_decl.ast.members) |member_node| { |
| 5277 | const field = tree.fullContainerField(member_node) orelse { | 5277 | const field = tree.fullContainerField(member_node) orelse { |
| 5278 | const tuple_member = for (container_decl.ast.members) |maybe_tuple| switch (tree.nodeTag(maybe_tuple)) { | 5278 | const tuple_member = for (container_decl.ast.members) |maybe_tuple| switch (maybe_tuple.tag(tree)) { |
| 5279 | .container_field_init, | 5279 | .container_field_init, |
| 5280 | .container_field_align, | 5280 | .container_field_align, |
| 5281 | .container_field, | 5281 | .container_field, |
| ... | @@ -5845,7 +5845,7 @@ fn containerMember( | ... | @@ -5845,7 +5845,7 @@ fn containerMember( |
| 5845 | ) InnerError!ContainerMemberResult { | 5845 | ) InnerError!ContainerMemberResult { |
| 5846 | const astgen = gz.astgen; | 5846 | const astgen = gz.astgen; |
| 5847 | const tree = astgen.tree; | 5847 | const tree = astgen.tree; |
| 5848 | switch (tree.nodeTag(member_node)) { | 5848 | switch (member_node.tag(tree)) { |
| 5849 | .container_field_init, | 5849 | .container_field_init, |
| 5850 | .container_field_align, | 5850 | .container_field_align, |
| 5851 | .container_field, | 5851 | .container_field, |
| ... | @@ -5860,8 +5860,8 @@ fn containerMember( | ... | @@ -5860,8 +5860,8 @@ fn containerMember( |
| 5860 | var buf: [1]Ast.Node.Index = undefined; | 5860 | var buf: [1]Ast.Node.Index = undefined; |
| 5861 | const full = tree.fullFnProto(&buf, member_node).?; | 5861 | const full = tree.fullFnProto(&buf, member_node).?; |
| 5862 | 5862 | ||
| 5863 | const body: Ast.Node.OptionalIndex = if (tree.nodeTag(member_node) == .fn_decl) | 5863 | const body: Ast.Node.OptionalIndex = if (member_node.tag(tree) == .fn_decl) |
| 5864 | tree.nodeData(member_node).node_and_node[1].toOptional() | 5864 | member_node.data(tree).node_and_node[1].toOptional() |
| 5865 | else | 5865 | else |
| 5866 | .none; | 5866 | .none; |
| 5867 | 5867 | ||
| ... | @@ -5934,7 +5934,7 @@ fn containerMember( | ... | @@ -5934,7 +5934,7 @@ fn containerMember( |
| 5934 | .@"usingnamespace", | 5934 | .@"usingnamespace", |
| 5935 | .empty, | 5935 | .empty, |
| 5936 | member_node, | 5936 | member_node, |
| 5937 | tree.isTokenPrecededByTags(tree.nodeMainToken(member_node), &.{.keyword_pub}), | 5937 | tree.isTokenPrecededByTags(member_node.mainToken(tree), &.{.keyword_pub}), |
| 5938 | ); | 5938 | ); |
| 5939 | }, | 5939 | }, |
| 5940 | }; | 5940 | }; |
| ... | @@ -5975,7 +5975,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi | ... | @@ -5975,7 +5975,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi |
| 5975 | var idents: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.TokenIndex) = .empty; | 5975 | var idents: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.TokenIndex) = .empty; |
| 5976 | defer idents.deinit(gpa); | 5976 | defer idents.deinit(gpa); |
| 5977 | 5977 | ||
| 5978 | const lbrace, const rbrace = tree.nodeData(node).token_and_token; | 5978 | const lbrace, const rbrace = node.data(tree).token_and_token; |
| 5979 | for (lbrace + 1..rbrace) |i| { | 5979 | for (lbrace + 1..rbrace) |i| { |
| 5980 | const tok_i: Ast.TokenIndex = @intCast(i); | 5980 | const tok_i: Ast.TokenIndex = @intCast(i); |
| 5981 | switch (tree.tokenTag(tok_i)) { | 5981 | switch (tree.tokenTag(tok_i)) { |
| ... | @@ -6103,7 +6103,7 @@ fn orelseCatchExpr( | ... | @@ -6103,7 +6103,7 @@ fn orelseCatchExpr( |
| 6103 | const astgen = parent_gz.astgen; | 6103 | const astgen = parent_gz.astgen; |
| 6104 | const tree = astgen.tree; | 6104 | const tree = astgen.tree; |
| 6105 | 6105 | ||
| 6106 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 6106 | const lhs, const rhs = node.data(tree).node_and_node; |
| 6107 | 6107 | ||
| 6108 | const need_rl = astgen.nodes_need_rl.contains(node); | 6108 | const need_rl = astgen.nodes_need_rl.contains(node); |
| 6109 | const block_ri: ResultInfo = if (need_rl) ri else .{ | 6109 | const block_ri: ResultInfo = if (need_rl) ri else .{ |
| ... | @@ -6238,7 +6238,7 @@ fn addFieldAccess( | ... | @@ -6238,7 +6238,7 @@ fn addFieldAccess( |
| 6238 | const astgen = gz.astgen; | 6238 | const astgen = gz.astgen; |
| 6239 | const tree = astgen.tree; | 6239 | const tree = astgen.tree; |
| 6240 | 6240 | ||
| 6241 | const object_node, const field_ident = tree.nodeData(node).node_and_token; | 6241 | const object_node, const field_ident = node.data(tree).node_and_token; |
| 6242 | const str_index = try astgen.identAsString(field_ident); | 6242 | const str_index = try astgen.identAsString(field_ident); |
| 6243 | const lhs = try expr(gz, scope, lhs_ri, object_node); | 6243 | const lhs = try expr(gz, scope, lhs_ri, object_node); |
| 6244 | 6244 | ||
| ... | @@ -6260,7 +6260,7 @@ fn arrayAccess( | ... | @@ -6260,7 +6260,7 @@ fn arrayAccess( |
| 6260 | const tree = gz.astgen.tree; | 6260 | const tree = gz.astgen.tree; |
| 6261 | switch (ri.rl) { | 6261 | switch (ri.rl) { |
| 6262 | .ref, .ref_coerced_ty => { | 6262 | .ref, .ref_coerced_ty => { |
| 6263 | const lhs_node, const rhs_node = tree.nodeData(node).node_and_node; | 6263 | const lhs_node, const rhs_node = node.data(tree).node_and_node; |
| 6264 | const lhs = try expr(gz, scope, .{ .rl = .ref }, lhs_node); | 6264 | const lhs = try expr(gz, scope, .{ .rl = .ref }, lhs_node); |
| 6265 | 6265 | ||
| 6266 | const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); | 6266 | const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); |
| ... | @@ -6271,7 +6271,7 @@ fn arrayAccess( | ... | @@ -6271,7 +6271,7 @@ fn arrayAccess( |
| 6271 | return gz.addPlNode(.elem_ptr_node, node, Zir.Inst.Bin{ .lhs = lhs, .rhs = rhs }); | 6271 | return gz.addPlNode(.elem_ptr_node, node, Zir.Inst.Bin{ .lhs = lhs, .rhs = rhs }); |
| 6272 | }, | 6272 | }, |
| 6273 | else => { | 6273 | else => { |
| 6274 | const lhs_node, const rhs_node = tree.nodeData(node).node_and_node; | 6274 | const lhs_node, const rhs_node = node.data(tree).node_and_node; |
| 6275 | const lhs = try expr(gz, scope, .{ .rl = .none }, lhs_node); | 6275 | const lhs = try expr(gz, scope, .{ .rl = .none }, lhs_node); |
| 6276 | 6276 | ||
| 6277 | const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); | 6277 | const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); |
| ... | @@ -6294,12 +6294,12 @@ fn simpleBinOp( | ... | @@ -6294,12 +6294,12 @@ fn simpleBinOp( |
| 6294 | const astgen = gz.astgen; | 6294 | const astgen = gz.astgen; |
| 6295 | const tree = astgen.tree; | 6295 | const tree = astgen.tree; |
| 6296 | 6296 | ||
| 6297 | const lhs_node, const rhs_node = tree.nodeData(node).node_and_node; | 6297 | const lhs_node, const rhs_node = node.data(tree).node_and_node; |
| 6298 | 6298 | ||
| 6299 | if (op_inst_tag == .cmp_neq or op_inst_tag == .cmp_eq) { | 6299 | if (op_inst_tag == .cmp_neq or op_inst_tag == .cmp_eq) { |
| 6300 | const str = if (op_inst_tag == .cmp_eq) "==" else "!="; | 6300 | const str = if (op_inst_tag == .cmp_eq) "==" else "!="; |
| 6301 | if (tree.nodeTag(lhs_node) == .string_literal or | 6301 | if (lhs_node.tag(tree) == .string_literal or |
| 6302 | tree.nodeTag(rhs_node) == .string_literal) | 6302 | rhs_node.tag(tree) == .string_literal) |
| 6303 | return astgen.failNode(node, "cannot compare strings with {s}", .{str}); | 6303 | return astgen.failNode(node, "cannot compare strings with {s}", .{str}); |
| 6304 | } | 6304 | } |
| 6305 | 6305 | ||
| ... | @@ -6343,7 +6343,7 @@ fn boolBinOp( | ... | @@ -6343,7 +6343,7 @@ fn boolBinOp( |
| 6343 | const astgen = gz.astgen; | 6343 | const astgen = gz.astgen; |
| 6344 | const tree = astgen.tree; | 6344 | const tree = astgen.tree; |
| 6345 | 6345 | ||
| 6346 | const lhs_node, const rhs_node = tree.nodeData(node).node_and_node; | 6346 | const lhs_node, const rhs_node = node.data(tree).node_and_node; |
| 6347 | const lhs = try expr(gz, scope, coerced_bool_ri, lhs_node); | 6347 | const lhs = try expr(gz, scope, coerced_bool_ri, lhs_node); |
| 6348 | const bool_br = (try gz.addPlNodePayloadIndex(zir_tag, node, undefined)).toIndex().?; | 6348 | const bool_br = (try gz.addPlNodePayloadIndex(zir_tag, node, undefined)).toIndex().?; |
| 6349 | 6349 | ||
| ... | @@ -6951,11 +6951,11 @@ fn forExpr( | ... | @@ -6951,11 +6951,11 @@ fn forExpr( |
| 6951 | capture_token = ident_tok + 2; | 6951 | capture_token = ident_tok + 2; |
| 6952 | 6952 | ||
| 6953 | try emitDbgNode(parent_gz, input); | 6953 | try emitDbgNode(parent_gz, input); |
| 6954 | if (tree.nodeTag(input) == .for_range) { | 6954 | if (input.tag(tree) == .for_range) { |
| 6955 | if (capture_is_ref) { | 6955 | if (capture_is_ref) { |
| 6956 | return astgen.failTok(ident_tok, "cannot capture reference to range", .{}); | 6956 | return astgen.failTok(ident_tok, "cannot capture reference to range", .{}); |
| 6957 | } | 6957 | } |
| 6958 | const start_node, const end_node = tree.nodeData(input).node_and_opt_node; | 6958 | const start_node, const end_node = input.data(tree).node_and_opt_node; |
| 6959 | const start_val = try expr(parent_gz, scope, .{ .rl = .{ .ty = .usize_type } }, start_node); | 6959 | const start_val = try expr(parent_gz, scope, .{ .rl = .{ .ty = .usize_type } }, start_node); |
| 6960 | 6960 | ||
| 6961 | const end_val = if (end_node.unwrap()) |end| | 6961 | const end_val = if (end_node.unwrap()) |end| |
| ... | @@ -7064,7 +7064,7 @@ fn forExpr( | ... | @@ -7064,7 +7064,7 @@ fn forExpr( |
| 7064 | try astgen.detectLocalShadowing(capture_sub_scope, name_str_index, ident_tok, capture_name, .capture); | 7064 | try astgen.detectLocalShadowing(capture_sub_scope, name_str_index, ident_tok, capture_name, .capture); |
| 7065 | 7065 | ||
| 7066 | const capture_inst = inst: { | 7066 | const capture_inst = inst: { |
| 7067 | const is_counter = tree.nodeTag(input) == .for_range; | 7067 | const is_counter = input.tag(tree) == .for_range; |
| 7068 | 7068 | ||
| 7069 | if (indexable_ref == .none) { | 7069 | if (indexable_ref == .none) { |
| 7070 | // Special case: the main index can be used directly. | 7070 | // Special case: the main index can be used directly. |
| ... | @@ -7204,9 +7204,9 @@ fn switchExprErrUnion( | ... | @@ -7204,9 +7204,9 @@ fn switchExprErrUnion( |
| 7204 | 7204 | ||
| 7205 | const switch_node, const operand_node, const error_payload = switch (node_ty) { | 7205 | const switch_node, const operand_node, const error_payload = switch (node_ty) { |
| 7206 | .@"catch" => .{ | 7206 | .@"catch" => .{ |
| 7207 | tree.nodeData(catch_or_if_node).node_and_node[1], | 7207 | catch_or_if_node.data(tree).node_and_node[1], |
| 7208 | tree.nodeData(catch_or_if_node).node_and_node[0], | 7208 | catch_or_if_node.data(tree).node_and_node[0], |
| 7209 | tree.nodeMainToken(catch_or_if_node) + 2, | 7209 | catch_or_if_node.mainToken(tree) + 2, |
| 7210 | }, | 7210 | }, |
| 7211 | .@"if" => .{ | 7211 | .@"if" => .{ |
| 7212 | if_full.ast.else_expr.unwrap().?, | 7212 | if_full.ast.else_expr.unwrap().?, |
| ... | @@ -7266,8 +7266,8 @@ fn switchExprErrUnion( | ... | @@ -7266,8 +7266,8 @@ fn switchExprErrUnion( |
| 7266 | else_src = case_src; | 7266 | else_src = case_src; |
| 7267 | continue; | 7267 | continue; |
| 7268 | } else if (case.ast.values.len == 1 and | 7268 | } else if (case.ast.values.len == 1 and |
| 7269 | tree.nodeTag(case.ast.values[0]) == .identifier and | 7269 | case.ast.values[0].tag(tree) == .identifier and |
| 7270 | mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(case.ast.values[0])), "_")) | 7270 | mem.eql(u8, tree.tokenSlice(case.ast.values[0].mainToken(tree)), "_")) |
| 7271 | { | 7271 | { |
| 7272 | const case_src = case.ast.arrow_token - 1; | 7272 | const case_src = case.ast.arrow_token - 1; |
| 7273 | return astgen.failTokNotes( | 7273 | return astgen.failTokNotes( |
| ... | @@ -7285,11 +7285,11 @@ fn switchExprErrUnion( | ... | @@ -7285,11 +7285,11 @@ fn switchExprErrUnion( |
| 7285 | } | 7285 | } |
| 7286 | 7286 | ||
| 7287 | for (case.ast.values) |val| { | 7287 | for (case.ast.values) |val| { |
| 7288 | if (tree.nodeTag(val) == .string_literal) | 7288 | if (val.tag(tree) == .string_literal) |
| 7289 | return astgen.failNode(val, "cannot switch on strings", .{}); | 7289 | return astgen.failNode(val, "cannot switch on strings", .{}); |
| 7290 | } | 7290 | } |
| 7291 | 7291 | ||
| 7292 | if (case.ast.values.len == 1 and tree.nodeTag(case.ast.values[0]) != .switch_range) { | 7292 | if (case.ast.values.len == 1 and case.ast.values[0].tag(tree) != .switch_range) { |
| 7293 | scalar_cases_len += 1; | 7293 | scalar_cases_len += 1; |
| 7294 | } else { | 7294 | } else { |
| 7295 | multi_cases_len += 1; | 7295 | multi_cases_len += 1; |
| ... | @@ -7486,7 +7486,7 @@ fn switchExprErrUnion( | ... | @@ -7486,7 +7486,7 @@ fn switchExprErrUnion( |
| 7486 | const case = tree.fullSwitchCase(case_node).?; | 7486 | const case = tree.fullSwitchCase(case_node).?; |
| 7487 | 7487 | ||
| 7488 | const is_multi_case = case.ast.values.len > 1 or | 7488 | const is_multi_case = case.ast.values.len > 1 or |
| 7489 | (case.ast.values.len == 1 and tree.nodeTag(case.ast.values[0]) == .switch_range); | 7489 | (case.ast.values.len == 1 and case.ast.values[0].tag(tree) == .switch_range); |
| 7490 | 7490 | ||
| 7491 | var dbg_var_name: Zir.NullTerminatedString = .empty; | 7491 | var dbg_var_name: Zir.NullTerminatedString = .empty; |
| 7492 | var dbg_var_inst: Zir.Inst.Ref = undefined; | 7492 | var dbg_var_inst: Zir.Inst.Ref = undefined; |
| ... | @@ -7540,7 +7540,7 @@ fn switchExprErrUnion( | ... | @@ -7540,7 +7540,7 @@ fn switchExprErrUnion( |
| 7540 | // items | 7540 | // items |
| 7541 | var items_len: u32 = 0; | 7541 | var items_len: u32 = 0; |
| 7542 | for (case.ast.values) |item_node| { | 7542 | for (case.ast.values) |item_node| { |
| 7543 | if (tree.nodeTag(item_node) == .switch_range) continue; | 7543 | if (item_node.tag(tree) == .switch_range) continue; |
| 7544 | items_len += 1; | 7544 | items_len += 1; |
| 7545 | 7545 | ||
| 7546 | const item_inst = try comptimeExpr(parent_gz, scope, item_ri, item_node, .switch_item); | 7546 | const item_inst = try comptimeExpr(parent_gz, scope, item_ri, item_node, .switch_item); |
| ... | @@ -7550,10 +7550,10 @@ fn switchExprErrUnion( | ... | @@ -7550,10 +7550,10 @@ fn switchExprErrUnion( |
| 7550 | // ranges | 7550 | // ranges |
| 7551 | var ranges_len: u32 = 0; | 7551 | var ranges_len: u32 = 0; |
| 7552 | for (case.ast.values) |range| { | 7552 | for (case.ast.values) |range| { |
| 7553 | if (tree.nodeTag(range) != .switch_range) continue; | 7553 | if (range.tag(tree) != .switch_range) continue; |
| 7554 | ranges_len += 1; | 7554 | ranges_len += 1; |
| 7555 | 7555 | ||
| 7556 | const first_node, const last_node = tree.nodeData(range).node_and_node; | 7556 | const first_node, const last_node = range.data(tree).node_and_node; |
| 7557 | const first = try comptimeExpr(parent_gz, scope, item_ri, first_node, .switch_item); | 7557 | const first = try comptimeExpr(parent_gz, scope, item_ri, first_node, .switch_item); |
| 7558 | const last = try comptimeExpr(parent_gz, scope, item_ri, last_node, .switch_item); | 7558 | const last = try comptimeExpr(parent_gz, scope, item_ri, last_node, .switch_item); |
| 7559 | try payloads.appendSlice(gpa, &[_]u32{ | 7559 | try payloads.appendSlice(gpa, &[_]u32{ |
| ... | @@ -7788,8 +7788,8 @@ fn switchExpr( | ... | @@ -7788,8 +7788,8 @@ fn switchExpr( |
| 7788 | else_src = case_src; | 7788 | else_src = case_src; |
| 7789 | continue; | 7789 | continue; |
| 7790 | } else if (case.ast.values.len == 1 and | 7790 | } else if (case.ast.values.len == 1 and |
| 7791 | tree.nodeTag(case.ast.values[0]) == .identifier and | 7791 | case.ast.values[0].tag(tree) == .identifier and |
| 7792 | mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(case.ast.values[0])), "_")) | 7792 | mem.eql(u8, tree.tokenSlice(case.ast.values[0].mainToken(tree)), "_")) |
| 7793 | { | 7793 | { |
| 7794 | const case_src = case.ast.arrow_token - 1; | 7794 | const case_src = case.ast.arrow_token - 1; |
| 7795 | if (underscore_src) |src| { | 7795 | if (underscore_src) |src| { |
| ... | @@ -7834,11 +7834,11 @@ fn switchExpr( | ... | @@ -7834,11 +7834,11 @@ fn switchExpr( |
| 7834 | } | 7834 | } |
| 7835 | 7835 | ||
| 7836 | for (case.ast.values) |val| { | 7836 | for (case.ast.values) |val| { |
| 7837 | if (tree.nodeTag(val) == .string_literal) | 7837 | if (val.tag(tree) == .string_literal) |
| 7838 | return astgen.failNode(val, "cannot switch on strings", .{}); | 7838 | return astgen.failNode(val, "cannot switch on strings", .{}); |
| 7839 | } | 7839 | } |
| 7840 | 7840 | ||
| 7841 | if (case.ast.values.len == 1 and tree.nodeTag(case.ast.values[0]) != .switch_range) { | 7841 | if (case.ast.values.len == 1 and case.ast.values[0].tag(tree) != .switch_range) { |
| 7842 | scalar_cases_len += 1; | 7842 | scalar_cases_len += 1; |
| 7843 | } else { | 7843 | } else { |
| 7844 | multi_cases_len += 1; | 7844 | multi_cases_len += 1; |
| ... | @@ -7927,7 +7927,7 @@ fn switchExpr( | ... | @@ -7927,7 +7927,7 @@ fn switchExpr( |
| 7927 | const case = tree.fullSwitchCase(case_node).?; | 7927 | const case = tree.fullSwitchCase(case_node).?; |
| 7928 | 7928 | ||
| 7929 | const is_multi_case = case.ast.values.len > 1 or | 7929 | const is_multi_case = case.ast.values.len > 1 or |
| 7930 | (case.ast.values.len == 1 and tree.nodeTag(case.ast.values[0]) == .switch_range); | 7930 | (case.ast.values.len == 1 and case.ast.values[0].tag(tree) == .switch_range); |
| 7931 | 7931 | ||
| 7932 | var dbg_var_name: Zir.NullTerminatedString = .empty; | 7932 | var dbg_var_name: Zir.NullTerminatedString = .empty; |
| 7933 | var dbg_var_inst: Zir.Inst.Ref = undefined; | 7933 | var dbg_var_inst: Zir.Inst.Ref = undefined; |
| ... | @@ -8007,7 +8007,7 @@ fn switchExpr( | ... | @@ -8007,7 +8007,7 @@ fn switchExpr( |
| 8007 | // items | 8007 | // items |
| 8008 | var items_len: u32 = 0; | 8008 | var items_len: u32 = 0; |
| 8009 | for (case.ast.values) |item_node| { | 8009 | for (case.ast.values) |item_node| { |
| 8010 | if (tree.nodeTag(item_node) == .switch_range) continue; | 8010 | if (item_node.tag(tree) == .switch_range) continue; |
| 8011 | items_len += 1; | 8011 | items_len += 1; |
| 8012 | 8012 | ||
| 8013 | const item_inst = try comptimeExpr(parent_gz, scope, item_ri, item_node, .switch_item); | 8013 | const item_inst = try comptimeExpr(parent_gz, scope, item_ri, item_node, .switch_item); |
| ... | @@ -8017,10 +8017,10 @@ fn switchExpr( | ... | @@ -8017,10 +8017,10 @@ fn switchExpr( |
| 8017 | // ranges | 8017 | // ranges |
| 8018 | var ranges_len: u32 = 0; | 8018 | var ranges_len: u32 = 0; |
| 8019 | for (case.ast.values) |range| { | 8019 | for (case.ast.values) |range| { |
| 8020 | if (tree.nodeTag(range) != .switch_range) continue; | 8020 | if (range.tag(tree) != .switch_range) continue; |
| 8021 | ranges_len += 1; | 8021 | ranges_len += 1; |
| 8022 | 8022 | ||
| 8023 | const first_node, const last_node = tree.nodeData(range).node_and_node; | 8023 | const first_node, const last_node = range.data(tree).node_and_node; |
| 8024 | const first = try comptimeExpr(parent_gz, scope, item_ri, first_node, .switch_item); | 8024 | const first = try comptimeExpr(parent_gz, scope, item_ri, first_node, .switch_item); |
| 8025 | const last = try comptimeExpr(parent_gz, scope, item_ri, last_node, .switch_item); | 8025 | const last = try comptimeExpr(parent_gz, scope, item_ri, last_node, .switch_item); |
| 8026 | try payloads.appendSlice(gpa, &[_]u32{ | 8026 | try payloads.appendSlice(gpa, &[_]u32{ |
| ... | @@ -8170,7 +8170,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref | ... | @@ -8170,7 +8170,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 8170 | 8170 | ||
| 8171 | const defer_outer = &astgen.fn_block.?.base; | 8171 | const defer_outer = &astgen.fn_block.?.base; |
| 8172 | 8172 | ||
| 8173 | const operand_node = tree.nodeData(node).opt_node.unwrap() orelse { | 8173 | const operand_node = node.data(tree).opt_node.unwrap() orelse { |
| 8174 | // Returning a void value; skip error defers. | 8174 | // Returning a void value; skip error defers. |
| 8175 | try genDefers(gz, defer_outer, scope, .normal_only); | 8175 | try genDefers(gz, defer_outer, scope, .normal_only); |
| 8176 | 8176 | ||
| ... | @@ -8181,10 +8181,10 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref | ... | @@ -8181,10 +8181,10 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 8181 | return Zir.Inst.Ref.unreachable_value; | 8181 | return Zir.Inst.Ref.unreachable_value; |
| 8182 | }; | 8182 | }; |
| 8183 | 8183 | ||
| 8184 | if (tree.nodeTag(operand_node) == .error_value) { | 8184 | if (operand_node.tag(tree) == .error_value) { |
| 8185 | // Hot path for `return error.Foo`. This bypasses result location logic as well as logic | 8185 | // Hot path for `return error.Foo`. This bypasses result location logic as well as logic |
| 8186 | // for detecting whether to add something to the function's inferred error set. | 8186 | // for detecting whether to add something to the function's inferred error set. |
| 8187 | const ident_token = tree.nodeMainToken(operand_node) + 2; | 8187 | const ident_token = operand_node.mainToken(tree) + 2; |
| 8188 | const err_name_str_index = try astgen.identAsString(ident_token); | 8188 | const err_name_str_index = try astgen.identAsString(ident_token); |
| 8189 | const defer_counts = countDefers(defer_outer, scope); | 8189 | const defer_counts = countDefers(defer_outer, scope); |
| 8190 | if (!defer_counts.need_err_code) { | 8190 | if (!defer_counts.need_err_code) { |
| ... | @@ -8316,7 +8316,7 @@ fn identifier( | ... | @@ -8316,7 +8316,7 @@ fn identifier( |
| 8316 | const astgen = gz.astgen; | 8316 | const astgen = gz.astgen; |
| 8317 | const tree = astgen.tree; | 8317 | const tree = astgen.tree; |
| 8318 | 8318 | ||
| 8319 | const ident_token = tree.nodeMainToken(ident); | 8319 | const ident_token = ident.mainToken(tree); |
| 8320 | const ident_name_raw = tree.tokenSlice(ident_token); | 8320 | const ident_name_raw = tree.tokenSlice(ident_token); |
| 8321 | if (mem.eql(u8, ident_name_raw, "_")) { | 8321 | if (mem.eql(u8, ident_name_raw, "_")) { |
| 8322 | return astgen.failNode(ident, "'_' used as an identifier without @\"_\" syntax", .{}); | 8322 | return astgen.failNode(ident, "'_' used as an identifier without @\"_\" syntax", .{}); |
| ... | @@ -8657,7 +8657,7 @@ fn stringLiteral( | ... | @@ -8657,7 +8657,7 @@ fn stringLiteral( |
| 8657 | ) InnerError!Zir.Inst.Ref { | 8657 | ) InnerError!Zir.Inst.Ref { |
| 8658 | const astgen = gz.astgen; | 8658 | const astgen = gz.astgen; |
| 8659 | const tree = astgen.tree; | 8659 | const tree = astgen.tree; |
| 8660 | const str_lit_token = tree.nodeMainToken(node); | 8660 | const str_lit_token = node.mainToken(tree); |
| 8661 | const str = try astgen.strLitAsString(str_lit_token); | 8661 | const str = try astgen.strLitAsString(str_lit_token); |
| 8662 | const result = try gz.add(.{ | 8662 | const result = try gz.add(.{ |
| 8663 | .tag = .str, | 8663 | .tag = .str, |
| ... | @@ -8689,7 +8689,7 @@ fn multilineStringLiteral( | ... | @@ -8689,7 +8689,7 @@ fn multilineStringLiteral( |
| 8689 | fn charLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zir.Inst.Ref { | 8689 | fn charLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zir.Inst.Ref { |
| 8690 | const astgen = gz.astgen; | 8690 | const astgen = gz.astgen; |
| 8691 | const tree = astgen.tree; | 8691 | const tree = astgen.tree; |
| 8692 | const main_token = tree.nodeMainToken(node); | 8692 | const main_token = node.mainToken(tree); |
| 8693 | const slice = tree.tokenSlice(main_token); | 8693 | const slice = tree.tokenSlice(main_token); |
| 8694 | 8694 | ||
| 8695 | switch (std.zig.parseCharLiteral(slice)) { | 8695 | switch (std.zig.parseCharLiteral(slice)) { |
| ... | @@ -8706,7 +8706,7 @@ const Sign = enum { negative, positive }; | ... | @@ -8706,7 +8706,7 @@ const Sign = enum { negative, positive }; |
| 8706 | fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node: Ast.Node.Index, sign: Sign) InnerError!Zir.Inst.Ref { | 8706 | fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node: Ast.Node.Index, sign: Sign) InnerError!Zir.Inst.Ref { |
| 8707 | const astgen = gz.astgen; | 8707 | const astgen = gz.astgen; |
| 8708 | const tree = astgen.tree; | 8708 | const tree = astgen.tree; |
| 8709 | const num_token = tree.nodeMainToken(node); | 8709 | const num_token = node.mainToken(tree); |
| 8710 | const bytes = tree.tokenSlice(num_token); | 8710 | const bytes = tree.tokenSlice(num_token); |
| 8711 | 8711 | ||
| 8712 | const result: Zir.Inst.Ref = switch (std.zig.parseNumberLiteral(bytes)) { | 8712 | const result: Zir.Inst.Ref = switch (std.zig.parseNumberLiteral(bytes)) { |
| ... | @@ -8826,10 +8826,10 @@ fn asmExpr( | ... | @@ -8826,10 +8826,10 @@ fn asmExpr( |
| 8826 | const tree = astgen.tree; | 8826 | const tree = astgen.tree; |
| 8827 | 8827 | ||
| 8828 | const TagAndTmpl = struct { tag: Zir.Inst.Extended, tmpl: Zir.NullTerminatedString }; | 8828 | const TagAndTmpl = struct { tag: Zir.Inst.Extended, tmpl: Zir.NullTerminatedString }; |
| 8829 | const tag_and_tmpl: TagAndTmpl = switch (tree.nodeTag(full.ast.template)) { | 8829 | const tag_and_tmpl: TagAndTmpl = switch (full.ast.template.tag(tree)) { |
| 8830 | .string_literal => .{ | 8830 | .string_literal => .{ |
| 8831 | .tag = .@"asm", | 8831 | .tag = .@"asm", |
| 8832 | .tmpl = (try astgen.strLitAsString(tree.nodeMainToken(full.ast.template))).index, | 8832 | .tmpl = (try astgen.strLitAsString(full.ast.template.mainToken(tree))).index, |
| 8833 | }, | 8833 | }, |
| 8834 | .multiline_string_literal => .{ | 8834 | .multiline_string_literal => .{ |
| 8835 | .tag = .@"asm", | 8835 | .tag = .@"asm", |
| ... | @@ -8864,7 +8864,7 @@ fn asmExpr( | ... | @@ -8864,7 +8864,7 @@ fn asmExpr( |
| 8864 | var output_type_bits: u32 = 0; | 8864 | var output_type_bits: u32 = 0; |
| 8865 | 8865 | ||
| 8866 | for (full.outputs, 0..) |output_node, i| { | 8866 | for (full.outputs, 0..) |output_node, i| { |
| 8867 | const symbolic_name = tree.nodeMainToken(output_node); | 8867 | const symbolic_name = output_node.mainToken(tree); |
| 8868 | const name = try astgen.identAsString(symbolic_name); | 8868 | const name = try astgen.identAsString(symbolic_name); |
| 8869 | const constraint_token = symbolic_name + 2; | 8869 | const constraint_token = symbolic_name + 2; |
| 8870 | const constraint = (try astgen.strLitAsString(constraint_token)).index; | 8870 | const constraint = (try astgen.strLitAsString(constraint_token)).index; |
| ... | @@ -8874,7 +8874,7 @@ fn asmExpr( | ... | @@ -8874,7 +8874,7 @@ fn asmExpr( |
| 8874 | return astgen.failNode(output_node, "inline assembly allows up to one output value", .{}); | 8874 | return astgen.failNode(output_node, "inline assembly allows up to one output value", .{}); |
| 8875 | } | 8875 | } |
| 8876 | output_type_bits |= @as(u32, 1) << @intCast(i); | 8876 | output_type_bits |= @as(u32, 1) << @intCast(i); |
| 8877 | const out_type_node = tree.nodeData(output_node).opt_node_and_token[0].unwrap().?; | 8877 | const out_type_node = output_node.data(tree).opt_node_and_token[0].unwrap().?; |
| 8878 | const out_type_inst = try typeExpr(gz, scope, out_type_node); | 8878 | const out_type_inst = try typeExpr(gz, scope, out_type_node); |
| 8879 | outputs[i] = .{ | 8879 | outputs[i] = .{ |
| 8880 | .name = name, | 8880 | .name = name, |
| ... | @@ -8901,11 +8901,11 @@ fn asmExpr( | ... | @@ -8901,11 +8901,11 @@ fn asmExpr( |
| 8901 | const inputs = inputs_buffer[0..full.inputs.len]; | 8901 | const inputs = inputs_buffer[0..full.inputs.len]; |
| 8902 | 8902 | ||
| 8903 | for (full.inputs, 0..) |input_node, i| { | 8903 | for (full.inputs, 0..) |input_node, i| { |
| 8904 | const symbolic_name = tree.nodeMainToken(input_node); | 8904 | const symbolic_name = input_node.mainToken(tree); |
| 8905 | const name = try astgen.identAsString(symbolic_name); | 8905 | const name = try astgen.identAsString(symbolic_name); |
| 8906 | const constraint_token = symbolic_name + 2; | 8906 | const constraint_token = symbolic_name + 2; |
| 8907 | const constraint = (try astgen.strLitAsString(constraint_token)).index; | 8907 | const constraint = (try astgen.strLitAsString(constraint_token)).index; |
| 8908 | const operand = try expr(gz, scope, .{ .rl = .none }, tree.nodeData(input_node).node_and_token[0]); | 8908 | const operand = try expr(gz, scope, .{ .rl = .none }, input_node.data(tree).node_and_token[0]); |
| 8909 | inputs[i] = .{ | 8909 | inputs[i] = .{ |
| 8910 | .name = name, | 8910 | .name = name, |
| 8911 | .constraint = constraint, | 8911 | .constraint = constraint, |
| ... | @@ -9029,11 +9029,11 @@ fn ptrCast( | ... | @@ -9029,11 +9029,11 @@ fn ptrCast( |
| 9029 | // to handle `builtin_call_two`. | 9029 | // to handle `builtin_call_two`. |
| 9030 | var node = root_node; | 9030 | var node = root_node; |
| 9031 | while (true) { | 9031 | while (true) { |
| 9032 | switch (tree.nodeTag(node)) { | 9032 | switch (node.tag(tree)) { |
| 9033 | .builtin_call_two, .builtin_call_two_comma => {}, | 9033 | .builtin_call_two, .builtin_call_two_comma => {}, |
| 9034 | .grouped_expression => { | 9034 | .grouped_expression => { |
| 9035 | // Handle the chaining even with redundant parentheses | 9035 | // Handle the chaining even with redundant parentheses |
| 9036 | node = tree.nodeData(node).node_and_token[0]; | 9036 | node = node.data(tree).node_and_token[0]; |
| 9037 | continue; | 9037 | continue; |
| 9038 | }, | 9038 | }, |
| 9039 | else => break, | 9039 | else => break, |
| ... | @@ -9045,7 +9045,7 @@ fn ptrCast( | ... | @@ -9045,7 +9045,7 @@ fn ptrCast( |
| 9045 | 9045 | ||
| 9046 | if (args.len == 0) break; // 0 args | 9046 | if (args.len == 0) break; // 0 args |
| 9047 | 9047 | ||
| 9048 | const builtin_token = tree.nodeMainToken(node); | 9048 | const builtin_token = node.mainToken(tree); |
| 9049 | const builtin_name = tree.tokenSlice(builtin_token); | 9049 | const builtin_name = tree.tokenSlice(builtin_token); |
| 9050 | const info = BuiltinFn.list.get(builtin_name) orelse break; | 9050 | const info = BuiltinFn.list.get(builtin_name) orelse break; |
| 9051 | if (args.len == 1) { | 9051 | if (args.len == 1) { |
| ... | @@ -9246,7 +9246,7 @@ fn builtinCall( | ... | @@ -9246,7 +9246,7 @@ fn builtinCall( |
| 9246 | const astgen = gz.astgen; | 9246 | const astgen = gz.astgen; |
| 9247 | const tree = astgen.tree; | 9247 | const tree = astgen.tree; |
| 9248 | 9248 | ||
| 9249 | const builtin_token = tree.nodeMainToken(node); | 9249 | const builtin_token = node.mainToken(tree); |
| 9250 | const builtin_name = tree.tokenSlice(builtin_token); | 9250 | const builtin_name = tree.tokenSlice(builtin_token); |
| 9251 | 9251 | ||
| 9252 | // We handle the different builtins manually because they have different semantics depending | 9252 | // We handle the different builtins manually because they have different semantics depending |
| ... | @@ -9289,11 +9289,11 @@ fn builtinCall( | ... | @@ -9289,11 +9289,11 @@ fn builtinCall( |
| 9289 | .import => { | 9289 | .import => { |
| 9290 | const operand_node = params[0]; | 9290 | const operand_node = params[0]; |
| 9291 | 9291 | ||
| 9292 | if (tree.nodeTag(operand_node) != .string_literal) { | 9292 | if (operand_node.tag(tree) != .string_literal) { |
| 9293 | // Spec reference: https://github.com/ziglang/zig/issues/2206 | 9293 | // Spec reference: https://github.com/ziglang/zig/issues/2206 |
| 9294 | return astgen.failNode(operand_node, "@import operand must be a string literal", .{}); | 9294 | return astgen.failNode(operand_node, "@import operand must be a string literal", .{}); |
| 9295 | } | 9295 | } |
| 9296 | const str_lit_token = tree.nodeMainToken(operand_node); | 9296 | const str_lit_token = operand_node.mainToken(tree); |
| 9297 | const str = try astgen.strLitAsString(str_lit_token); | 9297 | const str = try astgen.strLitAsString(str_lit_token); |
| 9298 | const str_slice = astgen.string_bytes.items[@intFromEnum(str.index)..][0..str.len]; | 9298 | const str_slice = astgen.string_bytes.items[@intFromEnum(str.index)..][0..str.len]; |
| 9299 | if (mem.indexOfScalar(u8, str_slice, 0) != null) { | 9299 | if (mem.indexOfScalar(u8, str_slice, 0) != null) { |
| ... | @@ -9919,8 +9919,8 @@ fn negation( | ... | @@ -9919,8 +9919,8 @@ fn negation( |
| 9919 | 9919 | ||
| 9920 | // Check for float literal as the sub-expression because we want to preserve | 9920 | // Check for float literal as the sub-expression because we want to preserve |
| 9921 | // its negativity rather than having it go through comptime subtraction. | 9921 | // its negativity rather than having it go through comptime subtraction. |
| 9922 | const operand_node = tree.nodeData(node).node; | 9922 | const operand_node = node.data(tree).node; |
| 9923 | if (tree.nodeTag(operand_node) == .number_literal) { | 9923 | if (operand_node.tag(tree) == .number_literal) { |
| 9924 | return numberLiteral(gz, ri, operand_node, node, .negative); | 9924 | return numberLiteral(gz, ri, operand_node, node, .negative); |
| 9925 | } | 9925 | } |
| 9926 | 9926 | ||
| ... | @@ -10034,9 +10034,10 @@ fn shiftOp( | ... | @@ -10034,9 +10034,10 @@ fn shiftOp( |
| 10034 | rhs_node: Ast.Node.Index, | 10034 | rhs_node: Ast.Node.Index, |
| 10035 | tag: Zir.Inst.Tag, | 10035 | tag: Zir.Inst.Tag, |
| 10036 | ) InnerError!Zir.Inst.Ref { | 10036 | ) InnerError!Zir.Inst.Ref { |
| 10037 | const tree = gz.astgen.tree; | ||
| 10037 | const lhs = try expr(gz, scope, .{ .rl = .none }, lhs_node); | 10038 | const lhs = try expr(gz, scope, .{ .rl = .none }, lhs_node); |
| 10038 | 10039 | ||
| 10039 | const cursor = switch (gz.astgen.tree.nodeTag(node)) { | 10040 | const cursor = switch (node.tag(tree)) { |
| 10040 | .shl, .shr => maybeAdvanceSourceCursorToMainToken(gz, node), | 10041 | .shl, .shr => maybeAdvanceSourceCursorToMainToken(gz, node), |
| 10041 | else => undefined, | 10042 | else => undefined, |
| 10042 | }; | 10043 | }; |
| ... | @@ -10044,7 +10045,7 @@ fn shiftOp( | ... | @@ -10044,7 +10045,7 @@ fn shiftOp( |
| 10044 | const log2_int_type = try gz.addUnNode(.typeof_log2_int_type, lhs, lhs_node); | 10045 | const log2_int_type = try gz.addUnNode(.typeof_log2_int_type, lhs, lhs_node); |
| 10045 | const rhs = try expr(gz, scope, .{ .rl = .{ .ty = log2_int_type }, .ctx = .shift_op }, rhs_node); | 10046 | const rhs = try expr(gz, scope, .{ .rl = .{ .ty = log2_int_type }, .ctx = .shift_op }, rhs_node); |
| 10046 | 10047 | ||
| 10047 | switch (gz.astgen.tree.nodeTag(node)) { | 10048 | switch (node.tag(tree)) { |
| 10048 | .shl, .shr => try emitDbgStmt(gz, cursor), | 10049 | .shl, .shr => try emitDbgStmt(gz, cursor), |
| 10049 | else => undefined, | 10050 | else => undefined, |
| 10050 | } | 10051 | } |
| ... | @@ -10248,10 +10249,10 @@ fn calleeExpr( | ... | @@ -10248,10 +10249,10 @@ fn calleeExpr( |
| 10248 | const astgen = gz.astgen; | 10249 | const astgen = gz.astgen; |
| 10249 | const tree = astgen.tree; | 10250 | const tree = astgen.tree; |
| 10250 | 10251 | ||
| 10251 | const tag = tree.nodeTag(node); | 10252 | const tag = node.tag(tree); |
| 10252 | switch (tag) { | 10253 | switch (tag) { |
| 10253 | .field_access => { | 10254 | .field_access => { |
| 10254 | const object_node, const field_ident = tree.nodeData(node).node_and_token; | 10255 | const object_node, const field_ident = node.data(tree).node_and_token; |
| 10255 | const str_index = try astgen.identAsString(field_ident); | 10256 | const str_index = try astgen.identAsString(field_ident); |
| 10256 | // Capture the object by reference so we can promote it to an | 10257 | // Capture the object by reference so we can promote it to an |
| 10257 | // address in Sema if needed. | 10258 | // address in Sema if needed. |
| ... | @@ -10276,7 +10277,7 @@ fn calleeExpr( | ... | @@ -10276,7 +10277,7 @@ fn calleeExpr( |
| 10276 | // Decl literal call syntax, e.g. | 10277 | // Decl literal call syntax, e.g. |
| 10277 | // `const foo: T = .init();` | 10278 | // `const foo: T = .init();` |
| 10278 | // Look up `init` in `T`, but don't try and coerce it. | 10279 | // Look up `init` in `T`, but don't try and coerce it. |
| 10279 | const str_index = try astgen.identAsString(tree.nodeMainToken(node)); | 10280 | const str_index = try astgen.identAsString(node.mainToken(tree)); |
| 10280 | const callee = try gz.addPlNode(.decl_literal_no_coerce, node, Zir.Inst.Field{ | 10281 | const callee = try gz.addPlNode(.decl_literal_no_coerce, node, Zir.Inst.Field{ |
| 10281 | .lhs = res_ty, | 10282 | .lhs = res_ty, |
| 10282 | .field_name_start = str_index, | 10283 | .field_name_start = str_index, |
| ... | @@ -10348,9 +10349,9 @@ comptime { | ... | @@ -10348,9 +10349,9 @@ comptime { |
| 10348 | } | 10349 | } |
| 10349 | 10350 | ||
| 10350 | fn nodeIsTriviallyZero(tree: *const Ast, node: Ast.Node.Index) bool { | 10351 | fn nodeIsTriviallyZero(tree: *const Ast, node: Ast.Node.Index) bool { |
| 10351 | switch (tree.nodeTag(node)) { | 10352 | switch (node.tag(tree)) { |
| 10352 | .number_literal => { | 10353 | .number_literal => { |
| 10353 | const ident = tree.nodeMainToken(node); | 10354 | const ident = node.mainToken(tree); |
| 10354 | return switch (std.zig.parseNumberLiteral(tree.tokenSlice(ident))) { | 10355 | return switch (std.zig.parseNumberLiteral(tree.tokenSlice(ident))) { |
| 10355 | .int => |number| switch (number) { | 10356 | .int => |number| switch (number) { |
| 10356 | 0 => true, | 10357 | 0 => true, |
| ... | @@ -10366,7 +10367,7 @@ fn nodeIsTriviallyZero(tree: *const Ast, node: Ast.Node.Index) bool { | ... | @@ -10366,7 +10367,7 @@ fn nodeIsTriviallyZero(tree: *const Ast, node: Ast.Node.Index) bool { |
| 10366 | fn nodeMayAppendToErrorTrace(tree: *const Ast, start_node: Ast.Node.Index) bool { | 10367 | fn nodeMayAppendToErrorTrace(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 10367 | var node = start_node; | 10368 | var node = start_node; |
| 10368 | while (true) { | 10369 | while (true) { |
| 10369 | switch (tree.nodeTag(node)) { | 10370 | switch (node.tag(tree)) { |
| 10370 | // These don't have the opportunity to call any runtime functions. | 10371 | // These don't have the opportunity to call any runtime functions. |
| 10371 | .error_value, | 10372 | .error_value, |
| 10372 | .identifier, | 10373 | .identifier, |
| ... | @@ -10376,10 +10377,10 @@ fn nodeMayAppendToErrorTrace(tree: *const Ast, start_node: Ast.Node.Index) bool | ... | @@ -10376,10 +10377,10 @@ fn nodeMayAppendToErrorTrace(tree: *const Ast, start_node: Ast.Node.Index) bool |
| 10376 | // Forward the question to the LHS sub-expression. | 10377 | // Forward the question to the LHS sub-expression. |
| 10377 | .@"try", | 10378 | .@"try", |
| 10378 | .@"nosuspend", | 10379 | .@"nosuspend", |
| 10379 | => node = tree.nodeData(node).node, | 10380 | => node = node.data(tree).node, |
| 10380 | .grouped_expression, | 10381 | .grouped_expression, |
| 10381 | .unwrap_optional, | 10382 | .unwrap_optional, |
| 10382 | => node = tree.nodeData(node).node_and_token[0], | 10383 | => node = node.data(tree).node_and_token[0], |
| 10383 | 10384 | ||
| 10384 | // Anything that does not eval to an error is guaranteed to pop any | 10385 | // Anything that does not eval to an error is guaranteed to pop any |
| 10385 | // additions to the error trace, so it effectively does not append. | 10386 | // additions to the error trace, so it effectively does not append. |
| ... | @@ -10391,7 +10392,7 @@ fn nodeMayAppendToErrorTrace(tree: *const Ast, start_node: Ast.Node.Index) bool | ... | @@ -10391,7 +10392,7 @@ fn nodeMayAppendToErrorTrace(tree: *const Ast, start_node: Ast.Node.Index) bool |
| 10391 | fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.EvalToError { | 10392 | fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.EvalToError { |
| 10392 | var node = start_node; | 10393 | var node = start_node; |
| 10393 | while (true) { | 10394 | while (true) { |
| 10394 | switch (tree.nodeTag(node)) { | 10395 | switch (node.tag(tree)) { |
| 10395 | .root, | 10396 | .root, |
| 10396 | .@"usingnamespace", | 10397 | .@"usingnamespace", |
| 10397 | .test_decl, | 10398 | .test_decl, |
| ... | @@ -10558,10 +10559,10 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev | ... | @@ -10558,10 +10559,10 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 10558 | .@"await", | 10559 | .@"await", |
| 10559 | .@"comptime", | 10560 | .@"comptime", |
| 10560 | .@"nosuspend", | 10561 | .@"nosuspend", |
| 10561 | => node = tree.nodeData(node).node, | 10562 | => node = node.data(tree).node, |
| 10562 | .grouped_expression, | 10563 | .grouped_expression, |
| 10563 | .unwrap_optional, | 10564 | .unwrap_optional, |
| 10564 | => node = tree.nodeData(node).node_and_token[0], | 10565 | => node = node.data(tree).node_and_token[0], |
| 10565 | 10566 | ||
| 10566 | // LHS sub-expression may still be an error under the outer optional or error union | 10567 | // LHS sub-expression may still be an error under the outer optional or error union |
| 10567 | .@"catch", | 10568 | .@"catch", |
| ... | @@ -10573,7 +10574,7 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev | ... | @@ -10573,7 +10574,7 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 10573 | .block, | 10574 | .block, |
| 10574 | .block_semicolon, | 10575 | .block_semicolon, |
| 10575 | => { | 10576 | => { |
| 10576 | const lbrace = tree.nodeMainToken(node); | 10577 | const lbrace = node.mainToken(tree); |
| 10577 | if (tree.tokenTag(lbrace - 1) == .colon) { | 10578 | if (tree.tokenTag(lbrace - 1) == .colon) { |
| 10578 | // Labeled blocks may need a memory location to forward | 10579 | // Labeled blocks may need a memory location to forward |
| 10579 | // to their break statements. | 10580 | // to their break statements. |
| ... | @@ -10588,7 +10589,7 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev | ... | @@ -10588,7 +10589,7 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 10588 | .builtin_call_two, | 10589 | .builtin_call_two, |
| 10589 | .builtin_call_two_comma, | 10590 | .builtin_call_two_comma, |
| 10590 | => { | 10591 | => { |
| 10591 | const builtin_token = tree.nodeMainToken(node); | 10592 | const builtin_token = node.mainToken(tree); |
| 10592 | const builtin_name = tree.tokenSlice(builtin_token); | 10593 | const builtin_name = tree.tokenSlice(builtin_token); |
| 10593 | // If the builtin is an invalid name, we don't cause an error here; instead | 10594 | // If the builtin is an invalid name, we don't cause an error here; instead |
| 10594 | // let it pass, and the error will be "invalid builtin function" later. | 10595 | // let it pass, and the error will be "invalid builtin function" later. |
| ... | @@ -10604,7 +10605,7 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev | ... | @@ -10604,7 +10605,7 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 10604 | fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.Index) bool { | 10605 | fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 10605 | var node = start_node; | 10606 | var node = start_node; |
| 10606 | while (true) { | 10607 | while (true) { |
| 10607 | switch (tree.nodeTag(node)) { | 10608 | switch (node.tag(tree)) { |
| 10608 | .root, | 10609 | .root, |
| 10609 | .@"usingnamespace", | 10610 | .@"usingnamespace", |
| 10610 | .test_decl, | 10611 | .test_decl, |
| ... | @@ -10771,10 +10772,10 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In | ... | @@ -10771,10 +10772,10 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In |
| 10771 | .@"await", | 10772 | .@"await", |
| 10772 | .@"comptime", | 10773 | .@"comptime", |
| 10773 | .@"nosuspend", | 10774 | .@"nosuspend", |
| 10774 | => node = tree.nodeData(node).node, | 10775 | => node = node.data(tree).node, |
| 10775 | .grouped_expression, | 10776 | .grouped_expression, |
| 10776 | .unwrap_optional, | 10777 | .unwrap_optional, |
| 10777 | => node = tree.nodeData(node).node_and_token[0], | 10778 | => node = node.data(tree).node_and_token[0], |
| 10778 | 10779 | ||
| 10779 | .ptr_type_aligned, | 10780 | .ptr_type_aligned, |
| 10780 | .ptr_type_sentinel, | 10781 | .ptr_type_sentinel, |
| ... | @@ -10786,7 +10787,7 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In | ... | @@ -10786,7 +10787,7 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In |
| 10786 | => return true, | 10787 | => return true, |
| 10787 | 10788 | ||
| 10788 | .identifier => { | 10789 | .identifier => { |
| 10789 | const ident_bytes = tree.tokenSlice(tree.nodeMainToken(node)); | 10790 | const ident_bytes = tree.tokenSlice(node.mainToken(tree)); |
| 10790 | if (primitive_instrs.get(ident_bytes)) |primitive| switch (primitive) { | 10791 | if (primitive_instrs.get(ident_bytes)) |primitive| switch (primitive) { |
| 10791 | .anyerror_type, | 10792 | .anyerror_type, |
| 10792 | .anyframe_type, | 10793 | .anyframe_type, |
| ... | @@ -10848,7 +10849,7 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In | ... | @@ -10848,7 +10849,7 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In |
| 10848 | fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { | 10849 | fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 10849 | var node = start_node; | 10850 | var node = start_node; |
| 10850 | while (true) { | 10851 | while (true) { |
| 10851 | switch (tree.nodeTag(node)) { | 10852 | switch (node.tag(tree)) { |
| 10852 | .root, | 10853 | .root, |
| 10853 | .@"usingnamespace", | 10854 | .@"usingnamespace", |
| 10854 | .test_decl, | 10855 | .test_decl, |
| ... | @@ -11024,13 +11025,13 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { | ... | @@ -11024,13 +11025,13 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 11024 | .@"await", | 11025 | .@"await", |
| 11025 | .@"comptime", | 11026 | .@"comptime", |
| 11026 | .@"nosuspend", | 11027 | .@"nosuspend", |
| 11027 | => node = tree.nodeData(node).node, | 11028 | => node = node.data(tree).node, |
| 11028 | .grouped_expression, | 11029 | .grouped_expression, |
| 11029 | .unwrap_optional, | 11030 | .unwrap_optional, |
| 11030 | => node = tree.nodeData(node).node_and_token[0], | 11031 | => node = node.data(tree).node_and_token[0], |
| 11031 | 11032 | ||
| 11032 | .identifier => { | 11033 | .identifier => { |
| 11033 | const ident_bytes = tree.tokenSlice(tree.nodeMainToken(node)); | 11034 | const ident_bytes = tree.tokenSlice(node.mainToken(tree)); |
| 11034 | if (primitive_instrs.get(ident_bytes)) |primitive| switch (primitive) { | 11035 | if (primitive_instrs.get(ident_bytes)) |primitive| switch (primitive) { |
| 11035 | .anyerror_type, | 11036 | .anyerror_type, |
| 11036 | .anyframe_type, | 11037 | .anyframe_type, |
| ... | @@ -11089,7 +11090,7 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { | ... | @@ -11089,7 +11090,7 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 11089 | 11090 | ||
| 11090 | /// Returns `true` if the node uses `gz.anon_name_strategy`. | 11091 | /// Returns `true` if the node uses `gz.anon_name_strategy`. |
| 11091 | fn nodeUsesAnonNameStrategy(tree: *const Ast, node: Ast.Node.Index) bool { | 11092 | fn nodeUsesAnonNameStrategy(tree: *const Ast, node: Ast.Node.Index) bool { |
| 11092 | switch (tree.nodeTag(node)) { | 11093 | switch (node.tag(tree)) { |
| 11093 | .container_decl, | 11094 | .container_decl, |
| 11094 | .container_decl_trailing, | 11095 | .container_decl_trailing, |
| 11095 | .container_decl_two, | 11096 | .container_decl_two, |
| ... | @@ -11104,7 +11105,7 @@ fn nodeUsesAnonNameStrategy(tree: *const Ast, node: Ast.Node.Index) bool { | ... | @@ -11104,7 +11105,7 @@ fn nodeUsesAnonNameStrategy(tree: *const Ast, node: Ast.Node.Index) bool { |
| 11104 | .tagged_union_enum_tag_trailing, | 11105 | .tagged_union_enum_tag_trailing, |
| 11105 | => return true, | 11106 | => return true, |
| 11106 | .builtin_call_two, .builtin_call_two_comma, .builtin_call, .builtin_call_comma => { | 11107 | .builtin_call_two, .builtin_call_two_comma, .builtin_call, .builtin_call_comma => { |
| 11107 | const builtin_token = tree.nodeMainToken(node); | 11108 | const builtin_token = node.mainToken(tree); |
| 11108 | const builtin_name = tree.tokenSlice(builtin_token); | 11109 | const builtin_name = tree.tokenSlice(builtin_token); |
| 11109 | return std.mem.eql(u8, builtin_name, "@Type"); | 11110 | return std.mem.eql(u8, builtin_name, "@Type"); |
| 11110 | }, | 11111 | }, |
| ... | @@ -11660,7 +11661,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice { | ... | @@ -11660,7 +11661,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice { |
| 11660 | fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice { | 11661 | fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice { |
| 11661 | const tree = astgen.tree; | 11662 | const tree = astgen.tree; |
| 11662 | 11663 | ||
| 11663 | const start, const end = tree.nodeData(node).token_and_token; | 11664 | const start, const end = node.data(tree).token_and_token; |
| 11664 | 11665 | ||
| 11665 | const gpa = astgen.gpa; | 11666 | const gpa = astgen.gpa; |
| 11666 | const string_bytes = &astgen.string_bytes; | 11667 | const string_bytes = &astgen.string_bytes; |
| ... | @@ -12155,9 +12156,9 @@ const GenZir = struct { | ... | @@ -12155,9 +12156,9 @@ const GenZir = struct { |
| 12155 | const src_locs_and_hash: []const u32 = if (args.body_gz != null) src_locs_and_hash: { | 12156 | const src_locs_and_hash: []const u32 = if (args.body_gz != null) src_locs_and_hash: { |
| 12156 | const tree = astgen.tree; | 12157 | const tree = astgen.tree; |
| 12157 | const fn_decl = args.src_node; | 12158 | const fn_decl = args.src_node; |
| 12158 | const block = switch (tree.nodeTag(fn_decl)) { | 12159 | const block = switch (fn_decl.tag(tree)) { |
| 12159 | .fn_decl => tree.nodeData(fn_decl).node_and_node[1], | 12160 | .fn_decl => fn_decl.data(tree).node_and_node[1], |
| 12160 | .test_decl => tree.nodeData(fn_decl).opt_token_and_node[1], | 12161 | .test_decl => fn_decl.data(tree).opt_token_and_node[1], |
| 12161 | else => unreachable, | 12162 | else => unreachable, |
| 12162 | }; | 12163 | }; |
| 12163 | const rbrace_start = tree.tokenStart(tree.lastToken(block)); | 12164 | const rbrace_start = tree.tokenStart(tree.lastToken(block)); |
| ... | @@ -13399,7 +13400,7 @@ fn maybeAdvanceSourceCursorToMainToken(gz: *GenZir, node: Ast.Node.Index) LineCo | ... | @@ -13399,7 +13400,7 @@ fn maybeAdvanceSourceCursorToMainToken(gz: *GenZir, node: Ast.Node.Index) LineCo |
| 13399 | if (gz.is_comptime) return .{ gz.astgen.source_line - gz.decl_line, gz.astgen.source_column }; | 13400 | if (gz.is_comptime) return .{ gz.astgen.source_line - gz.decl_line, gz.astgen.source_column }; |
| 13400 | 13401 | ||
| 13401 | const tree = gz.astgen.tree; | 13402 | const tree = gz.astgen.tree; |
| 13402 | const node_start = tree.tokenStart(tree.nodeMainToken(node)); | 13403 | const node_start = tree.tokenStart(node.mainToken(tree)); |
| 13403 | gz.astgen.advanceSourceCursor(node_start); | 13404 | gz.astgen.advanceSourceCursor(node_start); |
| 13404 | 13405 | ||
| 13405 | return .{ gz.astgen.source_line - gz.decl_line, gz.astgen.source_column }; | 13406 | return .{ gz.astgen.source_line - gz.decl_line, gz.astgen.source_column }; |
| ... | @@ -13492,7 +13493,7 @@ fn scanContainer( | ... | @@ -13492,7 +13493,7 @@ fn scanContainer( |
| 13492 | var decl_count: u32 = 0; | 13493 | var decl_count: u32 = 0; |
| 13493 | for (members) |member_node| { | 13494 | for (members) |member_node| { |
| 13494 | const Kind = enum { decl, field }; | 13495 | const Kind = enum { decl, field }; |
| 13495 | const kind: Kind, const name_token = switch (tree.nodeTag(member_node)) { | 13496 | const kind: Kind, const name_token = switch (member_node.tag(tree)) { |
| 13496 | .container_field_init, | 13497 | .container_field_init, |
| 13497 | .container_field_align, | 13498 | .container_field_align, |
| 13498 | .container_field, | 13499 | .container_field, |
| ... | @@ -13512,7 +13513,7 @@ fn scanContainer( | ... | @@ -13512,7 +13513,7 @@ fn scanContainer( |
| 13512 | .aligned_var_decl, | 13513 | .aligned_var_decl, |
| 13513 | => blk: { | 13514 | => blk: { |
| 13514 | decl_count += 1; | 13515 | decl_count += 1; |
| 13515 | break :blk .{ .decl, tree.nodeMainToken(member_node) + 1 }; | 13516 | break :blk .{ .decl, member_node.mainToken(tree) + 1 }; |
| 13516 | }, | 13517 | }, |
| 13517 | 13518 | ||
| 13518 | .fn_proto_simple, | 13519 | .fn_proto_simple, |
| ... | @@ -13522,7 +13523,7 @@ fn scanContainer( | ... | @@ -13522,7 +13523,7 @@ fn scanContainer( |
| 13522 | .fn_decl, | 13523 | .fn_decl, |
| 13523 | => blk: { | 13524 | => blk: { |
| 13524 | decl_count += 1; | 13525 | decl_count += 1; |
| 13525 | const ident = tree.nodeMainToken(member_node) + 1; | 13526 | const ident = member_node.mainToken(tree) + 1; |
| 13526 | if (tree.tokenTag(ident) != .identifier) { | 13527 | if (tree.tokenTag(ident) != .identifier) { |
| 13527 | try astgen.appendErrorNode(member_node, "missing function name", .{}); | 13528 | try astgen.appendErrorNode(member_node, "missing function name", .{}); |
| 13528 | any_invalid_declarations = true; | 13529 | any_invalid_declarations = true; |
| ... | @@ -13540,7 +13541,7 @@ fn scanContainer( | ... | @@ -13540,7 +13541,7 @@ fn scanContainer( |
| 13540 | decl_count += 1; | 13541 | decl_count += 1; |
| 13541 | // We don't want shadowing detection here, and test names work a bit differently, so | 13542 | // We don't want shadowing detection here, and test names work a bit differently, so |
| 13542 | // we must do the redeclaration detection ourselves. | 13543 | // we must do the redeclaration detection ourselves. |
| 13543 | const test_name_token = tree.nodeMainToken(member_node) + 1; | 13544 | const test_name_token = member_node.mainToken(tree) + 1; |
| 13544 | const new_ent: NameEntry = .{ | 13545 | const new_ent: NameEntry = .{ |
| 13545 | .tok = test_name_token, | 13546 | .tok = test_name_token, |
| 13546 | .next = null, | 13547 | .next = null, |
lib/std/zig/AstRlAnnotate.zig+44-44| ... | @@ -61,11 +61,11 @@ const Block = struct { | ... | @@ -61,11 +61,11 @@ const Block = struct { |
| 61 | consumes_res_ptr: bool, | 61 | consumes_res_ptr: bool, |
| 62 | }; | 62 | }; |
| 63 | 63 | ||
| 64 | pub fn annotate(gpa: Allocator, arena: Allocator, tree: Ast) Allocator.Error!RlNeededSet { | 64 | pub fn annotate(gpa: Allocator, arena: Allocator, tree: *const Ast) Allocator.Error!RlNeededSet { |
| 65 | var astrl: AstRlAnnotate = .{ | 65 | var astrl: AstRlAnnotate = .{ |
| 66 | .gpa = gpa, | 66 | .gpa = gpa, |
| 67 | .arena = arena, | 67 | .arena = arena, |
| 68 | .tree = &tree, | 68 | .tree = tree, |
| 69 | }; | 69 | }; |
| 70 | defer astrl.deinit(gpa); | 70 | defer astrl.deinit(gpa); |
| 71 | 71 | ||
| ... | @@ -129,7 +129,7 @@ fn containerDecl( | ... | @@ -129,7 +129,7 @@ fn containerDecl( |
| 129 | /// Returns true if `rl` provides a result pointer and the expression consumes it. | 129 | /// Returns true if `rl` provides a result pointer and the expression consumes it. |
| 130 | fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultInfo) Allocator.Error!bool { | 130 | fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultInfo) Allocator.Error!bool { |
| 131 | const tree = astrl.tree; | 131 | const tree = astrl.tree; |
| 132 | switch (tree.nodeTag(node)) { | 132 | switch (node.tag(tree)) { |
| 133 | .root, | 133 | .root, |
| 134 | .switch_case_one, | 134 | .switch_case_one, |
| 135 | .switch_case_inline_one, | 135 | .switch_case_inline_one, |
| ... | @@ -142,11 +142,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -142,11 +142,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 142 | => unreachable, | 142 | => unreachable, |
| 143 | 143 | ||
| 144 | .@"errdefer" => { | 144 | .@"errdefer" => { |
| 145 | _ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none); | 145 | _ = try astrl.expr(node.data(tree).opt_token_and_node[1], block, ResultInfo.none); |
| 146 | return false; | 146 | return false; |
| 147 | }, | 147 | }, |
| 148 | .@"defer" => { | 148 | .@"defer" => { |
| 149 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); | 149 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.none); |
| 150 | return false; | 150 | return false; |
| 151 | }, | 151 | }, |
| 152 | 152 | ||
| ... | @@ -166,11 +166,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -166,11 +166,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 166 | return false; | 166 | return false; |
| 167 | }, | 167 | }, |
| 168 | .@"usingnamespace" => { | 168 | .@"usingnamespace" => { |
| 169 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only); | 169 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.type_only); |
| 170 | return false; | 170 | return false; |
| 171 | }, | 171 | }, |
| 172 | .test_decl => { | 172 | .test_decl => { |
| 173 | _ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none); | 173 | _ = try astrl.expr(node.data(tree).opt_token_and_node[1], block, ResultInfo.none); |
| 174 | return false; | 174 | return false; |
| 175 | }, | 175 | }, |
| 176 | .global_var_decl, | 176 | .global_var_decl, |
| ... | @@ -214,7 +214,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -214,7 +214,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 214 | return false; | 214 | return false; |
| 215 | }, | 215 | }, |
| 216 | .assign => { | 216 | .assign => { |
| 217 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 217 | const lhs, const rhs = node.data(tree).node_and_node; |
| 218 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 218 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 219 | _ = try astrl.expr(rhs, block, ResultInfo.typed_ptr); | 219 | _ = try astrl.expr(rhs, block, ResultInfo.typed_ptr); |
| 220 | return false; | 220 | return false; |
| ... | @@ -237,13 +237,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -237,13 +237,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 237 | .assign_mul_wrap, | 237 | .assign_mul_wrap, |
| 238 | .assign_mul_sat, | 238 | .assign_mul_sat, |
| 239 | => { | 239 | => { |
| 240 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 240 | const lhs, const rhs = node.data(tree).node_and_node; |
| 241 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 241 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 242 | _ = try astrl.expr(rhs, block, ResultInfo.none); | 242 | _ = try astrl.expr(rhs, block, ResultInfo.none); |
| 243 | return false; | 243 | return false; |
| 244 | }, | 244 | }, |
| 245 | .shl, .shr => { | 245 | .shl, .shr => { |
| 246 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 246 | const lhs, const rhs = node.data(tree).node_and_node; |
| 247 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 247 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 248 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); | 248 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); |
| 249 | return false; | 249 | return false; |
| ... | @@ -271,20 +271,20 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -271,20 +271,20 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 271 | .less_or_equal, | 271 | .less_or_equal, |
| 272 | .array_cat, | 272 | .array_cat, |
| 273 | => { | 273 | => { |
| 274 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 274 | const lhs, const rhs = node.data(tree).node_and_node; |
| 275 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 275 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 276 | _ = try astrl.expr(rhs, block, ResultInfo.none); | 276 | _ = try astrl.expr(rhs, block, ResultInfo.none); |
| 277 | return false; | 277 | return false; |
| 278 | }, | 278 | }, |
| 279 | 279 | ||
| 280 | .array_mult => { | 280 | .array_mult => { |
| 281 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 281 | const lhs, const rhs = node.data(tree).node_and_node; |
| 282 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 282 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 283 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); | 283 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); |
| 284 | return false; | 284 | return false; |
| 285 | }, | 285 | }, |
| 286 | .error_union, .merge_error_sets => { | 286 | .error_union, .merge_error_sets => { |
| 287 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 287 | const lhs, const rhs = node.data(tree).node_and_node; |
| 288 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 288 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 289 | _ = try astrl.expr(rhs, block, ResultInfo.none); | 289 | _ = try astrl.expr(rhs, block, ResultInfo.none); |
| 290 | return false; | 290 | return false; |
| ... | @@ -292,17 +292,17 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -292,17 +292,17 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 292 | .bool_and, | 292 | .bool_and, |
| 293 | .bool_or, | 293 | .bool_or, |
| 294 | => { | 294 | => { |
| 295 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 295 | const lhs, const rhs = node.data(tree).node_and_node; |
| 296 | _ = try astrl.expr(lhs, block, ResultInfo.type_only); | 296 | _ = try astrl.expr(lhs, block, ResultInfo.type_only); |
| 297 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); | 297 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); |
| 298 | return false; | 298 | return false; |
| 299 | }, | 299 | }, |
| 300 | .bool_not => { | 300 | .bool_not => { |
| 301 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only); | 301 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.type_only); |
| 302 | return false; | 302 | return false; |
| 303 | }, | 303 | }, |
| 304 | .bit_not, .negation, .negation_wrap => { | 304 | .bit_not, .negation, .negation_wrap => { |
| 305 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); | 305 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.none); |
| 306 | return false; | 306 | return false; |
| 307 | }, | 307 | }, |
| 308 | 308 | ||
| ... | @@ -347,7 +347,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -347,7 +347,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 347 | for (full.ast.params) |param_node| { | 347 | for (full.ast.params) |param_node| { |
| 348 | _ = try astrl.expr(param_node, block, ResultInfo.type_only); | 348 | _ = try astrl.expr(param_node, block, ResultInfo.type_only); |
| 349 | } | 349 | } |
| 350 | return switch (tree.nodeTag(node)) { | 350 | return switch (node.tag(tree)) { |
| 351 | .call_one, | 351 | .call_one, |
| 352 | .call_one_comma, | 352 | .call_one_comma, |
| 353 | .call, | 353 | .call, |
| ... | @@ -363,7 +363,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -363,7 +363,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 363 | }, | 363 | }, |
| 364 | 364 | ||
| 365 | .@"return" => { | 365 | .@"return" => { |
| 366 | if (tree.nodeData(node).opt_node.unwrap()) |lhs| { | 366 | if (node.data(tree).opt_node.unwrap()) |lhs| { |
| 367 | const ret_val_consumes_rl = try astrl.expr(lhs, block, ResultInfo.typed_ptr); | 367 | const ret_val_consumes_rl = try astrl.expr(lhs, block, ResultInfo.typed_ptr); |
| 368 | if (ret_val_consumes_rl) { | 368 | if (ret_val_consumes_rl) { |
| 369 | try astrl.nodes_need_rl.putNoClobber(astrl.gpa, node, {}); | 369 | try astrl.nodes_need_rl.putNoClobber(astrl.gpa, node, {}); |
| ... | @@ -373,7 +373,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -373,7 +373,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 373 | }, | 373 | }, |
| 374 | 374 | ||
| 375 | .field_access => { | 375 | .field_access => { |
| 376 | const lhs, _ = tree.nodeData(node).node_and_token; | 376 | const lhs, _ = node.data(tree).node_and_token; |
| 377 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 377 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 378 | return false; | 378 | return false; |
| 379 | }, | 379 | }, |
| ... | @@ -436,8 +436,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -436,8 +436,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 436 | break :label try astrl.identString(label_token); | 436 | break :label try astrl.identString(label_token); |
| 437 | } else null; | 437 | } else null; |
| 438 | for (full.ast.inputs) |input| { | 438 | for (full.ast.inputs) |input| { |
| 439 | if (tree.nodeTag(input) == .for_range) { | 439 | if (input.tag(tree) == .for_range) { |
| 440 | const lhs, const opt_rhs = tree.nodeData(input).node_and_opt_node; | 440 | const lhs, const opt_rhs = input.data(tree).node_and_opt_node; |
| 441 | _ = try astrl.expr(lhs, block, ResultInfo.type_only); | 441 | _ = try astrl.expr(lhs, block, ResultInfo.type_only); |
| 442 | if (opt_rhs.unwrap()) |rhs| { | 442 | if (opt_rhs.unwrap()) |rhs| { |
| 443 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); | 443 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); |
| ... | @@ -466,13 +466,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -466,13 +466,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 466 | }, | 466 | }, |
| 467 | 467 | ||
| 468 | .slice_open => { | 468 | .slice_open => { |
| 469 | const sliced, const start = tree.nodeData(node).node_and_node; | 469 | const sliced, const start = node.data(tree).node_and_node; |
| 470 | _ = try astrl.expr(sliced, block, ResultInfo.none); | 470 | _ = try astrl.expr(sliced, block, ResultInfo.none); |
| 471 | _ = try astrl.expr(start, block, ResultInfo.type_only); | 471 | _ = try astrl.expr(start, block, ResultInfo.type_only); |
| 472 | return false; | 472 | return false; |
| 473 | }, | 473 | }, |
| 474 | .slice => { | 474 | .slice => { |
| 475 | const sliced, const extra_index = tree.nodeData(node).node_and_extra; | 475 | const sliced, const extra_index = node.data(tree).node_and_extra; |
| 476 | const extra = tree.extraData(extra_index, Ast.Node.Slice); | 476 | const extra = tree.extraData(extra_index, Ast.Node.Slice); |
| 477 | _ = try astrl.expr(sliced, block, ResultInfo.none); | 477 | _ = try astrl.expr(sliced, block, ResultInfo.none); |
| 478 | _ = try astrl.expr(extra.start, block, ResultInfo.type_only); | 478 | _ = try astrl.expr(extra.start, block, ResultInfo.type_only); |
| ... | @@ -480,7 +480,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -480,7 +480,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 480 | return false; | 480 | return false; |
| 481 | }, | 481 | }, |
| 482 | .slice_sentinel => { | 482 | .slice_sentinel => { |
| 483 | const sliced, const extra_index = tree.nodeData(node).node_and_extra; | 483 | const sliced, const extra_index = node.data(tree).node_and_extra; |
| 484 | const extra = tree.extraData(extra_index, Ast.Node.SliceSentinel); | 484 | const extra = tree.extraData(extra_index, Ast.Node.SliceSentinel); |
| 485 | _ = try astrl.expr(sliced, block, ResultInfo.none); | 485 | _ = try astrl.expr(sliced, block, ResultInfo.none); |
| 486 | _ = try astrl.expr(extra.start, block, ResultInfo.type_only); | 486 | _ = try astrl.expr(extra.start, block, ResultInfo.type_only); |
| ... | @@ -491,24 +491,24 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -491,24 +491,24 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 491 | return false; | 491 | return false; |
| 492 | }, | 492 | }, |
| 493 | .deref => { | 493 | .deref => { |
| 494 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); | 494 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.none); |
| 495 | return false; | 495 | return false; |
| 496 | }, | 496 | }, |
| 497 | .address_of => { | 497 | .address_of => { |
| 498 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); | 498 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.none); |
| 499 | return false; | 499 | return false; |
| 500 | }, | 500 | }, |
| 501 | .optional_type => { | 501 | .optional_type => { |
| 502 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only); | 502 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.type_only); |
| 503 | return false; | 503 | return false; |
| 504 | }, | 504 | }, |
| 505 | .@"try", | 505 | .@"try", |
| 506 | .@"await", | 506 | .@"await", |
| 507 | .@"nosuspend", | 507 | .@"nosuspend", |
| 508 | => return astrl.expr(tree.nodeData(node).node, block, ri), | 508 | => return astrl.expr(node.data(tree).node, block, ri), |
| 509 | .grouped_expression, | 509 | .grouped_expression, |
| 510 | .unwrap_optional, | 510 | .unwrap_optional, |
| 511 | => return astrl.expr(tree.nodeData(node).node_and_token[0], block, ri), | 511 | => return astrl.expr(node.data(tree).node_and_token[0], block, ri), |
| 512 | 512 | ||
| 513 | .block_two, | 513 | .block_two, |
| 514 | .block_two_semicolon, | 514 | .block_two_semicolon, |
| ... | @@ -520,12 +520,12 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -520,12 +520,12 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 520 | return astrl.blockExpr(block, ri, node, statements); | 520 | return astrl.blockExpr(block, ri, node, statements); |
| 521 | }, | 521 | }, |
| 522 | .anyframe_type => { | 522 | .anyframe_type => { |
| 523 | _, const child_type = tree.nodeData(node).token_and_node; | 523 | _, const child_type = node.data(tree).token_and_node; |
| 524 | _ = try astrl.expr(child_type, block, ResultInfo.type_only); | 524 | _ = try astrl.expr(child_type, block, ResultInfo.type_only); |
| 525 | return false; | 525 | return false; |
| 526 | }, | 526 | }, |
| 527 | .@"catch", .@"orelse" => { | 527 | .@"catch", .@"orelse" => { |
| 528 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 528 | const lhs, const rhs = node.data(tree).node_and_node; |
| 529 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 529 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 530 | const rhs_consumes_rl = try astrl.expr(rhs, block, ri); | 530 | const rhs_consumes_rl = try astrl.expr(rhs, block, ri); |
| 531 | if (rhs_consumes_rl) { | 531 | if (rhs_consumes_rl) { |
| ... | @@ -577,7 +577,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -577,7 +577,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 577 | }, | 577 | }, |
| 578 | 578 | ||
| 579 | .@"break" => { | 579 | .@"break" => { |
| 580 | const opt_label, const opt_rhs = tree.nodeData(node).opt_token_and_opt_node; | 580 | const opt_label, const opt_rhs = node.data(tree).opt_token_and_opt_node; |
| 581 | const rhs = opt_rhs.unwrap() orelse { | 581 | const rhs = opt_rhs.unwrap() orelse { |
| 582 | // Breaks with void are not interesting | 582 | // Breaks with void are not interesting |
| 583 | return false; | 583 | return false; |
| ... | @@ -609,13 +609,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -609,13 +609,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 609 | }, | 609 | }, |
| 610 | 610 | ||
| 611 | .array_type => { | 611 | .array_type => { |
| 612 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 612 | const lhs, const rhs = node.data(tree).node_and_node; |
| 613 | _ = try astrl.expr(lhs, block, ResultInfo.type_only); | 613 | _ = try astrl.expr(lhs, block, ResultInfo.type_only); |
| 614 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); | 614 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); |
| 615 | return false; | 615 | return false; |
| 616 | }, | 616 | }, |
| 617 | .array_type_sentinel => { | 617 | .array_type_sentinel => { |
| 618 | const len_expr, const extra_index = tree.nodeData(node).node_and_extra; | 618 | const len_expr, const extra_index = node.data(tree).node_and_extra; |
| 619 | const extra = tree.extraData(extra_index, Ast.Node.ArrayTypeSentinel); | 619 | const extra = tree.extraData(extra_index, Ast.Node.ArrayTypeSentinel); |
| 620 | _ = try astrl.expr(len_expr, block, ResultInfo.type_only); | 620 | _ = try astrl.expr(len_expr, block, ResultInfo.type_only); |
| 621 | _ = try astrl.expr(extra.elem_type, block, ResultInfo.type_only); | 621 | _ = try astrl.expr(extra.elem_type, block, ResultInfo.type_only); |
| ... | @@ -623,7 +623,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -623,7 +623,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 623 | return false; | 623 | return false; |
| 624 | }, | 624 | }, |
| 625 | .array_access => { | 625 | .array_access => { |
| 626 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 626 | const lhs, const rhs = node.data(tree).node_and_node; |
| 627 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 627 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 628 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); | 628 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); |
| 629 | return false; | 629 | return false; |
| ... | @@ -631,11 +631,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -631,11 +631,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 631 | .@"comptime" => { | 631 | .@"comptime" => { |
| 632 | // AstGen will emit an error if the scope is already comptime, so we can assume it is | 632 | // AstGen will emit an error if the scope is already comptime, so we can assume it is |
| 633 | // not. This means the result location is not forwarded. | 633 | // not. This means the result location is not forwarded. |
| 634 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); | 634 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.none); |
| 635 | return false; | 635 | return false; |
| 636 | }, | 636 | }, |
| 637 | .@"switch", .switch_comma => { | 637 | .@"switch", .switch_comma => { |
| 638 | const operand_node, const extra_index = tree.nodeData(node).node_and_extra; | 638 | const operand_node, const extra_index = node.data(tree).node_and_extra; |
| 639 | const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index); | 639 | const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index); |
| 640 | 640 | ||
| 641 | _ = try astrl.expr(operand_node, block, ResultInfo.none); | 641 | _ = try astrl.expr(operand_node, block, ResultInfo.none); |
| ... | @@ -644,8 +644,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -644,8 +644,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 644 | for (case_nodes) |case_node| { | 644 | for (case_nodes) |case_node| { |
| 645 | const case = tree.fullSwitchCase(case_node).?; | 645 | const case = tree.fullSwitchCase(case_node).?; |
| 646 | for (case.ast.values) |item_node| { | 646 | for (case.ast.values) |item_node| { |
| 647 | if (tree.nodeTag(item_node) == .switch_range) { | 647 | if (item_node.tag(tree) == .switch_range) { |
| 648 | const lhs, const rhs = tree.nodeData(item_node).node_and_node; | 648 | const lhs, const rhs = item_node.data(tree).node_and_node; |
| 649 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 649 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
| 650 | _ = try astrl.expr(rhs, block, ResultInfo.none); | 650 | _ = try astrl.expr(rhs, block, ResultInfo.none); |
| 651 | } else { | 651 | } else { |
| ... | @@ -662,11 +662,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -662,11 +662,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 662 | return any_prong_consumed_rl; | 662 | return any_prong_consumed_rl; |
| 663 | }, | 663 | }, |
| 664 | .@"suspend" => { | 664 | .@"suspend" => { |
| 665 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); | 665 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.none); |
| 666 | return false; | 666 | return false; |
| 667 | }, | 667 | }, |
| 668 | .@"resume" => { | 668 | .@"resume" => { |
| 669 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); | 669 | _ = try astrl.expr(node.data(tree).node, block, ResultInfo.none); |
| 670 | return false; | 670 | return false; |
| 671 | }, | 671 | }, |
| 672 | 672 | ||
| ... | @@ -752,7 +752,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -752,7 +752,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 752 | => |tag| { | 752 | => |tag| { |
| 753 | var buf: [1]Ast.Node.Index = undefined; | 753 | var buf: [1]Ast.Node.Index = undefined; |
| 754 | const full = tree.fullFnProto(&buf, node).?; | 754 | const full = tree.fullFnProto(&buf, node).?; |
| 755 | const body_node = if (tag == .fn_decl) tree.nodeData(node).node_and_node[1].toOptional() else .none; | 755 | const body_node = if (tag == .fn_decl) node.data(tree).node_and_node[1].toOptional() else .none; |
| 756 | { | 756 | { |
| 757 | var it = full.iterate(tree); | 757 | var it = full.iterate(tree); |
| 758 | while (it.next()) |param| { | 758 | while (it.next()) |param| { |
| ... | @@ -800,7 +800,7 @@ fn identString(astrl: *AstRlAnnotate, token: Ast.TokenIndex) ![]const u8 { | ... | @@ -800,7 +800,7 @@ fn identString(astrl: *AstRlAnnotate, token: Ast.TokenIndex) ![]const u8 { |
| 800 | fn blockExpr(astrl: *AstRlAnnotate, parent_block: ?*Block, ri: ResultInfo, node: Ast.Node.Index, statements: []const Ast.Node.Index) !bool { | 800 | fn blockExpr(astrl: *AstRlAnnotate, parent_block: ?*Block, ri: ResultInfo, node: Ast.Node.Index, statements: []const Ast.Node.Index) !bool { |
| 801 | const tree = astrl.tree; | 801 | const tree = astrl.tree; |
| 802 | 802 | ||
| 803 | const lbrace = tree.nodeMainToken(node); | 803 | const lbrace = node.mainToken(tree); |
| 804 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { | 804 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { |
| 805 | // Labeled block | 805 | // Labeled block |
| 806 | var new_block: Block = .{ | 806 | var new_block: Block = .{ |
| ... | @@ -830,7 +830,7 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast. | ... | @@ -830,7 +830,7 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast. |
| 830 | _ = ri; // Currently, no builtin consumes its result location. | 830 | _ = ri; // Currently, no builtin consumes its result location. |
| 831 | 831 | ||
| 832 | const tree = astrl.tree; | 832 | const tree = astrl.tree; |
| 833 | const builtin_token = tree.nodeMainToken(node); | 833 | const builtin_token = node.mainToken(tree); |
| 834 | const builtin_name = tree.tokenSlice(builtin_token); | 834 | const builtin_name = tree.tokenSlice(builtin_token); |
| 835 | const info = BuiltinFn.list.get(builtin_name) orelse return false; | 835 | const info = BuiltinFn.list.get(builtin_name) orelse return false; |
| 836 | if (info.param_count) |expected| { | 836 | if (info.param_count) |expected| { |
lib/std/zig/ZonGen.zig+28-28| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | //! Ingests an `Ast` and produces a `Zoir`. | 1 | //! Ingests an `Ast` and produces a `Zoir`. |
| 2 | 2 | ||
| 3 | gpa: Allocator, | 3 | gpa: Allocator, |
| 4 | tree: Ast, | 4 | tree: *const Ast, |
| 5 | 5 | ||
| 6 | options: Options, | 6 | options: Options, |
| 7 | 7 | ||
| ... | @@ -22,7 +22,7 @@ pub const Options = struct { | ... | @@ -22,7 +22,7 @@ pub const Options = struct { |
| 22 | parse_str_lits: bool = true, | 22 | parse_str_lits: bool = true, |
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | pub fn generate(gpa: Allocator, tree: Ast, options: Options) Allocator.Error!Zoir { | 25 | pub fn generate(gpa: Allocator, tree: *const Ast, options: Options) Allocator.Error!Zoir { |
| 26 | assert(tree.mode == .zon); | 26 | assert(tree.mode == .zon); |
| 27 | 27 | ||
| 28 | var zg: ZonGen = .{ | 28 | var zg: ZonGen = .{ |
| ... | @@ -98,7 +98,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator | ... | @@ -98,7 +98,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 98 | const gpa = zg.gpa; | 98 | const gpa = zg.gpa; |
| 99 | const tree = zg.tree; | 99 | const tree = zg.tree; |
| 100 | 100 | ||
| 101 | switch (tree.nodeTag(node)) { | 101 | switch (node.tag(tree)) { |
| 102 | .root => unreachable, | 102 | .root => unreachable, |
| 103 | .@"usingnamespace" => unreachable, | 103 | .@"usingnamespace" => unreachable, |
| 104 | .test_decl => unreachable, | 104 | .test_decl => unreachable, |
| ... | @@ -170,7 +170,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator | ... | @@ -170,7 +170,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 170 | .bool_not, | 170 | .bool_not, |
| 171 | .bit_not, | 171 | .bit_not, |
| 172 | .negation_wrap, | 172 | .negation_wrap, |
| 173 | => try zg.addErrorTok(tree.nodeMainToken(node), "operator '{s}' is not allowed in ZON", .{tree.tokenSlice(tree.nodeMainToken(node))}), | 173 | => try zg.addErrorTok(node.mainToken(tree), "operator '{s}' is not allowed in ZON", .{tree.tokenSlice(node.mainToken(tree))}), |
| 174 | 174 | ||
| 175 | .error_union, | 175 | .error_union, |
| 176 | .merge_error_sets, | 176 | .merge_error_sets, |
| ... | @@ -248,8 +248,8 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator | ... | @@ -248,8 +248,8 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 248 | .slice_sentinel, | 248 | .slice_sentinel, |
| 249 | => try zg.addErrorNode(node, "slice operator is not allowed in ZON", .{}), | 249 | => try zg.addErrorNode(node, "slice operator is not allowed in ZON", .{}), |
| 250 | 250 | ||
| 251 | .deref, .address_of => try zg.addErrorTok(tree.nodeMainToken(node), "pointers are not available in ZON", .{}), | 251 | .deref, .address_of => try zg.addErrorTok(node.mainToken(tree), "pointers are not available in ZON", .{}), |
| 252 | .unwrap_optional => try zg.addErrorTok(tree.nodeMainToken(node), "optionals are not available in ZON", .{}), | 252 | .unwrap_optional => try zg.addErrorTok(node.mainToken(tree), "optionals are not available in ZON", .{}), |
| 253 | .error_value => try zg.addErrorNode(node, "errors are not available in ZON", .{}), | 253 | .error_value => try zg.addErrorNode(node, "errors are not available in ZON", .{}), |
| 254 | 254 | ||
| 255 | .array_access => try zg.addErrorNode(node, "array indexing is not allowed in ZON", .{}), | 255 | .array_access => try zg.addErrorNode(node, "array indexing is not allowed in ZON", .{}), |
| ... | @@ -294,18 +294,18 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator | ... | @@ -294,18 +294,18 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 294 | }, | 294 | }, |
| 295 | 295 | ||
| 296 | .grouped_expression => { | 296 | .grouped_expression => { |
| 297 | try zg.addErrorTokNotes(tree.nodeMainToken(node), "expression grouping is not allowed in ZON", .{}, &.{ | 297 | try zg.addErrorTokNotes(node.mainToken(tree), "expression grouping is not allowed in ZON", .{}, &.{ |
| 298 | try zg.errNoteTok(tree.nodeMainToken(node), "these parentheses are always redundant", .{}), | 298 | try zg.errNoteTok(node.mainToken(tree), "these parentheses are always redundant", .{}), |
| 299 | }); | 299 | }); |
| 300 | return zg.expr(tree.nodeData(node).node_and_token[0], dest_node); | 300 | return zg.expr(node.data(tree).node_and_token[0], dest_node); |
| 301 | }, | 301 | }, |
| 302 | 302 | ||
| 303 | .negation => { | 303 | .negation => { |
| 304 | const child_node = tree.nodeData(node).node; | 304 | const child_node = node.data(tree).node; |
| 305 | switch (tree.nodeTag(child_node)) { | 305 | switch (child_node.tag(tree)) { |
| 306 | .number_literal => return zg.numberLiteral(child_node, node, dest_node, .negative), | 306 | .number_literal => return zg.numberLiteral(child_node, node, dest_node, .negative), |
| 307 | .identifier => { | 307 | .identifier => { |
| 308 | const child_ident = tree.tokenSlice(tree.nodeMainToken(child_node)); | 308 | const child_ident = tree.tokenSlice(child_node.mainToken(tree)); |
| 309 | if (mem.eql(u8, child_ident, "inf")) { | 309 | if (mem.eql(u8, child_ident, "inf")) { |
| 310 | zg.setNode(dest_node, .{ | 310 | zg.setNode(dest_node, .{ |
| 311 | .tag = .neg_inf, | 311 | .tag = .neg_inf, |
| ... | @@ -317,7 +317,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator | ... | @@ -317,7 +317,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 317 | }, | 317 | }, |
| 318 | else => {}, | 318 | else => {}, |
| 319 | } | 319 | } |
| 320 | try zg.addErrorTok(tree.nodeMainToken(node), "expected number or 'inf' after '-'", .{}); | 320 | try zg.addErrorTok(node.mainToken(tree), "expected number or 'inf' after '-'", .{}); |
| 321 | }, | 321 | }, |
| 322 | .number_literal => try zg.numberLiteral(node, node, dest_node, .positive), | 322 | .number_literal => try zg.numberLiteral(node, node, dest_node, .positive), |
| 323 | .char_literal => try zg.charLiteral(node, dest_node), | 323 | .char_literal => try zg.charLiteral(node, dest_node), |
| ... | @@ -325,7 +325,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator | ... | @@ -325,7 +325,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 325 | .identifier => try zg.identifier(node, dest_node), | 325 | .identifier => try zg.identifier(node, dest_node), |
| 326 | 326 | ||
| 327 | .enum_literal => { | 327 | .enum_literal => { |
| 328 | const str_index = zg.identAsString(tree.nodeMainToken(node)) catch |err| switch (err) { | 328 | const str_index = zg.identAsString(node.mainToken(tree)) catch |err| switch (err) { |
| 329 | error.BadString => undefined, // doesn't matter, there's an error | 329 | error.BadString => undefined, // doesn't matter, there's an error |
| 330 | error.OutOfMemory => |e| return e, | 330 | error.OutOfMemory => |e| return e, |
| 331 | }; | 331 | }; |
| ... | @@ -486,17 +486,17 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) !u32 { | ... | @@ -486,17 +486,17 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) !u32 { |
| 486 | } | 486 | } |
| 487 | 487 | ||
| 488 | /// Estimates the size of a string node without parsing it. | 488 | /// Estimates the size of a string node without parsing it. |
| 489 | pub fn strLitSizeHint(tree: Ast, node: Ast.Node.Index) usize { | 489 | pub fn strLitSizeHint(tree: *const Ast, node: Ast.Node.Index) usize { |
| 490 | switch (tree.nodeTag(node)) { | 490 | switch (node.tag(tree)) { |
| 491 | // Parsed string literals are typically around the size of the raw strings. | 491 | // Parsed string literals are typically around the size of the raw strings. |
| 492 | .string_literal => { | 492 | .string_literal => { |
| 493 | const token = tree.nodeMainToken(node); | 493 | const token = node.mainToken(tree); |
| 494 | const raw_string = tree.tokenSlice(token); | 494 | const raw_string = tree.tokenSlice(token); |
| 495 | return raw_string.len; | 495 | return raw_string.len; |
| 496 | }, | 496 | }, |
| 497 | // Multiline string literal lengths can be computed exactly. | 497 | // Multiline string literal lengths can be computed exactly. |
| 498 | .multiline_string_literal => { | 498 | .multiline_string_literal => { |
| 499 | const first_tok, const last_tok = tree.nodeData(node).token_and_token; | 499 | const first_tok, const last_tok = node.data(tree).token_and_token; |
| 500 | 500 | ||
| 501 | var size = tree.tokenSlice(first_tok)[2..].len; | 501 | var size = tree.tokenSlice(first_tok)[2..].len; |
| 502 | for (first_tok + 1..last_tok + 1) |tok_idx| { | 502 | for (first_tok + 1..last_tok + 1) |tok_idx| { |
| ... | @@ -511,18 +511,18 @@ pub fn strLitSizeHint(tree: Ast, node: Ast.Node.Index) usize { | ... | @@ -511,18 +511,18 @@ pub fn strLitSizeHint(tree: Ast, node: Ast.Node.Index) usize { |
| 511 | 511 | ||
| 512 | /// Parses the given node as a string literal. | 512 | /// Parses the given node as a string literal. |
| 513 | pub fn parseStrLit( | 513 | pub fn parseStrLit( |
| 514 | tree: Ast, | 514 | tree: *const Ast, |
| 515 | node: Ast.Node.Index, | 515 | node: Ast.Node.Index, |
| 516 | writer: anytype, | 516 | writer: anytype, |
| 517 | ) error{OutOfMemory}!std.zig.string_literal.Result { | 517 | ) error{OutOfMemory}!std.zig.string_literal.Result { |
| 518 | switch (tree.nodeTag(node)) { | 518 | switch (node.tag(tree)) { |
| 519 | .string_literal => { | 519 | .string_literal => { |
| 520 | const token = tree.nodeMainToken(node); | 520 | const token = node.mainToken(tree); |
| 521 | const raw_string = tree.tokenSlice(token); | 521 | const raw_string = tree.tokenSlice(token); |
| 522 | return std.zig.string_literal.parseWrite(writer, raw_string); | 522 | return std.zig.string_literal.parseWrite(writer, raw_string); |
| 523 | }, | 523 | }, |
| 524 | .multiline_string_literal => { | 524 | .multiline_string_literal => { |
| 525 | const first_tok, const last_tok = tree.nodeData(node).token_and_token; | 525 | const first_tok, const last_tok = node.data(tree).token_and_token; |
| 526 | 526 | ||
| 527 | // First line: do not append a newline. | 527 | // First line: do not append a newline. |
| 528 | { | 528 | { |
| ... | @@ -560,7 +560,7 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) !StringLiteralResult { | ... | @@ -560,7 +560,7 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) !StringLiteralResult { |
| 560 | switch (try parseStrLit(zg.tree, str_node, zg.string_bytes.writer(zg.gpa))) { | 560 | switch (try parseStrLit(zg.tree, str_node, zg.string_bytes.writer(zg.gpa))) { |
| 561 | .success => {}, | 561 | .success => {}, |
| 562 | .failure => |err| { | 562 | .failure => |err| { |
| 563 | const token = zg.tree.nodeMainToken(str_node); | 563 | const token = str_node.mainToken(zg.tree); |
| 564 | const raw_string = zg.tree.tokenSlice(token); | 564 | const raw_string = zg.tree.tokenSlice(token); |
| 565 | try zg.lowerStrLitError(err, token, raw_string, 0); | 565 | try zg.lowerStrLitError(err, token, raw_string, 0); |
| 566 | return error.BadString; | 566 | return error.BadString; |
| ... | @@ -608,7 +608,7 @@ fn identAsString(zg: *ZonGen, ident_token: Ast.TokenIndex) !Zoir.NullTerminatedS | ... | @@ -608,7 +608,7 @@ fn identAsString(zg: *ZonGen, ident_token: Ast.TokenIndex) !Zoir.NullTerminatedS |
| 608 | 608 | ||
| 609 | fn numberLiteral(zg: *ZonGen, num_node: Ast.Node.Index, src_node: Ast.Node.Index, dest_node: Zoir.Node.Index, sign: enum { negative, positive }) !void { | 609 | fn numberLiteral(zg: *ZonGen, num_node: Ast.Node.Index, src_node: Ast.Node.Index, dest_node: Zoir.Node.Index, sign: enum { negative, positive }) !void { |
| 610 | const tree = zg.tree; | 610 | const tree = zg.tree; |
| 611 | const num_token = tree.nodeMainToken(num_node); | 611 | const num_token = num_node.mainToken(tree); |
| 612 | const num_bytes = tree.tokenSlice(num_token); | 612 | const num_bytes = tree.tokenSlice(num_token); |
| 613 | 613 | ||
| 614 | switch (std.zig.parseNumberLiteral(num_bytes)) { | 614 | switch (std.zig.parseNumberLiteral(num_bytes)) { |
| ... | @@ -712,8 +712,8 @@ fn setBigIntLiteralNode(zg: *ZonGen, dest_node: Zoir.Node.Index, src_node: Ast.N | ... | @@ -712,8 +712,8 @@ fn setBigIntLiteralNode(zg: *ZonGen, dest_node: Zoir.Node.Index, src_node: Ast.N |
| 712 | 712 | ||
| 713 | fn charLiteral(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !void { | 713 | fn charLiteral(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !void { |
| 714 | const tree = zg.tree; | 714 | const tree = zg.tree; |
| 715 | assert(tree.nodeTag(node) == .char_literal); | 715 | assert(node.tag(tree) == .char_literal); |
| 716 | const main_token = tree.nodeMainToken(node); | 716 | const main_token = node.mainToken(tree); |
| 717 | const slice = tree.tokenSlice(main_token); | 717 | const slice = tree.tokenSlice(main_token); |
| 718 | switch (std.zig.parseCharLiteral(slice)) { | 718 | switch (std.zig.parseCharLiteral(slice)) { |
| 719 | .success => |codepoint| zg.setNode(dest_node, .{ | 719 | .success => |codepoint| zg.setNode(dest_node, .{ |
| ... | @@ -727,8 +727,8 @@ fn charLiteral(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !v | ... | @@ -727,8 +727,8 @@ fn charLiteral(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !v |
| 727 | 727 | ||
| 728 | fn identifier(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !void { | 728 | fn identifier(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !void { |
| 729 | const tree = zg.tree; | 729 | const tree = zg.tree; |
| 730 | assert(tree.nodeTag(node) == .identifier); | 730 | assert(node.tag(tree) == .identifier); |
| 731 | const main_token = tree.nodeMainToken(node); | 731 | const main_token = node.mainToken(tree); |
| 732 | const ident = tree.tokenSlice(main_token); | 732 | const ident = tree.tokenSlice(main_token); |
| 733 | 733 | ||
| 734 | const tag: Zoir.Node.Repr.Tag = t: { | 734 | const tag: Zoir.Node.Repr.Tag = t: { |
lib/std/zig/render.zig+90-90| ... | @@ -75,11 +75,11 @@ pub const Fixups = struct { | ... | @@ -75,11 +75,11 @@ pub const Fixups = struct { |
| 75 | const Render = struct { | 75 | const Render = struct { |
| 76 | gpa: Allocator, | 76 | gpa: Allocator, |
| 77 | ais: *Ais, | 77 | ais: *Ais, |
| 78 | tree: Ast, | 78 | tree: *const Ast, |
| 79 | fixups: Fixups, | 79 | fixups: Fixups, |
| 80 | }; | 80 | }; |
| 81 | 81 | ||
| 82 | pub fn renderTree(buffer: *std.ArrayList(u8), tree: Ast, fixups: Fixups) Error!void { | 82 | pub fn renderTree(buffer: *std.ArrayList(u8), tree: *const Ast, fixups: Fixups) Error!void { |
| 83 | assert(tree.errors.len == 0); // Cannot render an invalid tree. | 83 | assert(tree.errors.len == 0); // Cannot render an invalid tree. |
| 84 | var auto_indenting_stream = Ais.init(buffer, indent_delta); | 84 | var auto_indenting_stream = Ais.init(buffer, indent_delta); |
| 85 | defer auto_indenting_stream.deinit(); | 85 | defer auto_indenting_stream.deinit(); |
| ... | @@ -144,13 +144,13 @@ fn renderMember( | ... | @@ -144,13 +144,13 @@ fn renderMember( |
| 144 | const ais = r.ais; | 144 | const ais = r.ais; |
| 145 | if (r.fixups.omit_nodes.contains(decl)) return; | 145 | if (r.fixups.omit_nodes.contains(decl)) return; |
| 146 | try renderDocComments(r, tree.firstToken(decl)); | 146 | try renderDocComments(r, tree.firstToken(decl)); |
| 147 | switch (tree.nodeTag(decl)) { | 147 | switch (decl.tag(tree)) { |
| 148 | .fn_decl => { | 148 | .fn_decl => { |
| 149 | // Some examples: | 149 | // Some examples: |
| 150 | // pub extern "foo" fn ... | 150 | // pub extern "foo" fn ... |
| 151 | // export fn ... | 151 | // export fn ... |
| 152 | const fn_proto, const body_node = tree.nodeData(decl).node_and_node; | 152 | const fn_proto, const body_node = decl.data(tree).node_and_node; |
| 153 | const fn_token = tree.nodeMainToken(fn_proto); | 153 | const fn_token = fn_proto.mainToken(tree); |
| 154 | // Go back to the first token we should render here. | 154 | // Go back to the first token we should render here. |
| 155 | var i = fn_token; | 155 | var i = fn_token; |
| 156 | while (i > 0) { | 156 | while (i > 0) { |
| ... | @@ -174,18 +174,18 @@ fn renderMember( | ... | @@ -174,18 +174,18 @@ fn renderMember( |
| 174 | while (i < fn_token) : (i += 1) { | 174 | while (i < fn_token) : (i += 1) { |
| 175 | try renderToken(r, i, .space); | 175 | try renderToken(r, i, .space); |
| 176 | } | 176 | } |
| 177 | switch (tree.nodeTag(fn_proto)) { | 177 | switch (fn_proto.tag(tree)) { |
| 178 | .fn_proto_one, .fn_proto => { | 178 | .fn_proto_one, .fn_proto => { |
| 179 | var buf: [1]Ast.Node.Index = undefined; | 179 | var buf: [1]Ast.Node.Index = undefined; |
| 180 | const opt_callconv_expr = if (tree.nodeTag(fn_proto) == .fn_proto_one) | 180 | const opt_callconv_expr = if (fn_proto.tag(tree) == .fn_proto_one) |
| 181 | tree.fnProtoOne(&buf, fn_proto).ast.callconv_expr | 181 | tree.fnProtoOne(&buf, fn_proto).ast.callconv_expr |
| 182 | else | 182 | else |
| 183 | tree.fnProto(fn_proto).ast.callconv_expr; | 183 | tree.fnProto(fn_proto).ast.callconv_expr; |
| 184 | 184 | ||
| 185 | // Keep in sync with logic in `renderFnProto`. Search this file for the marker PROMOTE_CALLCONV_INLINE | 185 | // Keep in sync with logic in `renderFnProto`. Search this file for the marker PROMOTE_CALLCONV_INLINE |
| 186 | if (opt_callconv_expr.unwrap()) |callconv_expr| { | 186 | if (opt_callconv_expr.unwrap()) |callconv_expr| { |
| 187 | if (tree.nodeTag(callconv_expr) == .enum_literal) { | 187 | if (callconv_expr.tag(tree) == .enum_literal) { |
| 188 | if (mem.eql(u8, "@\"inline\"", tree.tokenSlice(tree.nodeMainToken(callconv_expr)))) { | 188 | if (mem.eql(u8, "@\"inline\"", tree.tokenSlice(callconv_expr.mainToken(tree)))) { |
| 189 | try ais.writer().writeAll("inline "); | 189 | try ais.writer().writeAll("inline "); |
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| ... | @@ -197,7 +197,7 @@ fn renderMember( | ... | @@ -197,7 +197,7 @@ fn renderMember( |
| 197 | try renderExpression(r, fn_proto, .space); | 197 | try renderExpression(r, fn_proto, .space); |
| 198 | if (r.fixups.gut_functions.contains(decl)) { | 198 | if (r.fixups.gut_functions.contains(decl)) { |
| 199 | try ais.pushIndent(.normal); | 199 | try ais.pushIndent(.normal); |
| 200 | const lbrace = tree.nodeMainToken(body_node); | 200 | const lbrace = body_node.mainToken(tree); |
| 201 | try renderToken(r, lbrace, .newline); | 201 | try renderToken(r, lbrace, .newline); |
| 202 | try discardAllParams(r, fn_proto); | 202 | try discardAllParams(r, fn_proto); |
| 203 | try ais.writer().writeAll("@trap();"); | 203 | try ais.writer().writeAll("@trap();"); |
| ... | @@ -206,12 +206,12 @@ fn renderMember( | ... | @@ -206,12 +206,12 @@ fn renderMember( |
| 206 | try renderToken(r, tree.lastToken(body_node), space); // rbrace | 206 | try renderToken(r, tree.lastToken(body_node), space); // rbrace |
| 207 | } else if (r.fixups.unused_var_decls.count() != 0) { | 207 | } else if (r.fixups.unused_var_decls.count() != 0) { |
| 208 | try ais.pushIndent(.normal); | 208 | try ais.pushIndent(.normal); |
| 209 | const lbrace = tree.nodeMainToken(body_node); | 209 | const lbrace = body_node.mainToken(tree); |
| 210 | try renderToken(r, lbrace, .newline); | 210 | try renderToken(r, lbrace, .newline); |
| 211 | 211 | ||
| 212 | var fn_proto_buf: [1]Ast.Node.Index = undefined; | 212 | var fn_proto_buf: [1]Ast.Node.Index = undefined; |
| 213 | const full_fn_proto = tree.fullFnProto(&fn_proto_buf, fn_proto).?; | 213 | const full_fn_proto = tree.fullFnProto(&fn_proto_buf, fn_proto).?; |
| 214 | var it = full_fn_proto.iterate(&tree); | 214 | var it = full_fn_proto.iterate(tree); |
| 215 | while (it.next()) |param| { | 215 | while (it.next()) |param| { |
| 216 | const name_ident = param.name_token.?; | 216 | const name_ident = param.name_token.?; |
| 217 | assert(tree.tokenTag(name_ident) == .identifier); | 217 | assert(tree.tokenTag(name_ident) == .identifier); |
| ... | @@ -236,7 +236,7 @@ fn renderMember( | ... | @@ -236,7 +236,7 @@ fn renderMember( |
| 236 | => { | 236 | => { |
| 237 | // Extern function prototypes are parsed as these tags. | 237 | // Extern function prototypes are parsed as these tags. |
| 238 | // Go back to the first token we should render here. | 238 | // Go back to the first token we should render here. |
| 239 | const fn_token = tree.nodeMainToken(decl); | 239 | const fn_token = decl.mainToken(tree); |
| 240 | var i = fn_token; | 240 | var i = fn_token; |
| 241 | while (i > 0) { | 241 | while (i > 0) { |
| 242 | i -= 1; | 242 | i -= 1; |
| ... | @@ -263,8 +263,8 @@ fn renderMember( | ... | @@ -263,8 +263,8 @@ fn renderMember( |
| 263 | }, | 263 | }, |
| 264 | 264 | ||
| 265 | .@"usingnamespace" => { | 265 | .@"usingnamespace" => { |
| 266 | const main_token = tree.nodeMainToken(decl); | 266 | const main_token = decl.mainToken(tree); |
| 267 | const expr = tree.nodeData(decl).node; | 267 | const expr = decl.data(tree).node; |
| 268 | if (tree.isTokenPrecededByTags(main_token, &.{.keyword_pub})) { | 268 | if (tree.isTokenPrecededByTags(main_token, &.{.keyword_pub})) { |
| 269 | try renderToken(r, main_token - 1, .space); // pub | 269 | try renderToken(r, main_token - 1, .space); // pub |
| 270 | } | 270 | } |
| ... | @@ -284,8 +284,8 @@ fn renderMember( | ... | @@ -284,8 +284,8 @@ fn renderMember( |
| 284 | }, | 284 | }, |
| 285 | 285 | ||
| 286 | .test_decl => { | 286 | .test_decl => { |
| 287 | const test_token = tree.nodeMainToken(decl); | 287 | const test_token = decl.mainToken(tree); |
| 288 | const opt_name_token, const block_node = tree.nodeData(decl).opt_token_and_node; | 288 | const opt_name_token, const block_node = decl.data(tree).opt_token_and_node; |
| 289 | try renderToken(r, test_token, .space); | 289 | try renderToken(r, test_token, .space); |
| 290 | if (opt_name_token.unwrap()) |name_token| { | 290 | if (opt_name_token.unwrap()) |name_token| { |
| 291 | switch (tree.tokenTag(name_token)) { | 291 | switch (tree.tokenTag(name_token)) { |
| ... | @@ -329,9 +329,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -329,9 +329,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 329 | } else if (r.fixups.replace_nodes_with_node.get(node)) |replacement| { | 329 | } else if (r.fixups.replace_nodes_with_node.get(node)) |replacement| { |
| 330 | return renderExpression(r, replacement, space); | 330 | return renderExpression(r, replacement, space); |
| 331 | } | 331 | } |
| 332 | switch (tree.nodeTag(node)) { | 332 | switch (node.tag(tree)) { |
| 333 | .identifier => { | 333 | .identifier => { |
| 334 | const token_index = tree.nodeMainToken(node); | 334 | const token_index = node.mainToken(tree); |
| 335 | return renderIdentifier(r, token_index, space, .preserve_when_shadowing); | 335 | return renderIdentifier(r, token_index, space, .preserve_when_shadowing); |
| 336 | }, | 336 | }, |
| 337 | 337 | ||
| ... | @@ -340,12 +340,12 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -340,12 +340,12 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 340 | .unreachable_literal, | 340 | .unreachable_literal, |
| 341 | .anyframe_literal, | 341 | .anyframe_literal, |
| 342 | .string_literal, | 342 | .string_literal, |
| 343 | => return renderToken(r, tree.nodeMainToken(node), space), | 343 | => return renderToken(r, node.mainToken(tree), space), |
| 344 | 344 | ||
| 345 | .multiline_string_literal => { | 345 | .multiline_string_literal => { |
| 346 | try ais.maybeInsertNewline(); | 346 | try ais.maybeInsertNewline(); |
| 347 | 347 | ||
| 348 | const first_tok, const last_tok = tree.nodeData(node).token_and_token; | 348 | const first_tok, const last_tok = node.data(tree).token_and_token; |
| 349 | for (first_tok..last_tok + 1) |i| { | 349 | for (first_tok..last_tok + 1) |i| { |
| 350 | try renderToken(r, @intCast(i), .newline); | 350 | try renderToken(r, @intCast(i), .newline); |
| 351 | } | 351 | } |
| ... | @@ -372,7 +372,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -372,7 +372,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 372 | }, | 372 | }, |
| 373 | 373 | ||
| 374 | .error_value => { | 374 | .error_value => { |
| 375 | const main_token = tree.nodeMainToken(node); | 375 | const main_token = node.mainToken(tree); |
| 376 | try renderToken(r, main_token, .none); | 376 | try renderToken(r, main_token, .none); |
| 377 | try renderToken(r, main_token + 1, .none); | 377 | try renderToken(r, main_token + 1, .none); |
| 378 | return renderIdentifier(r, main_token + 2, space, .eagerly_unquote); | 378 | return renderIdentifier(r, main_token + 2, space, .eagerly_unquote); |
| ... | @@ -389,8 +389,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -389,8 +389,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 389 | }, | 389 | }, |
| 390 | 390 | ||
| 391 | .@"errdefer" => { | 391 | .@"errdefer" => { |
| 392 | const defer_token = tree.nodeMainToken(node); | 392 | const defer_token = node.mainToken(tree); |
| 393 | const maybe_payload_token, const expr = tree.nodeData(node).opt_token_and_node; | 393 | const maybe_payload_token, const expr = node.data(tree).opt_token_and_node; |
| 394 | 394 | ||
| 395 | try renderToken(r, defer_token, .space); | 395 | try renderToken(r, defer_token, .space); |
| 396 | if (maybe_payload_token.unwrap()) |payload_token| { | 396 | if (maybe_payload_token.unwrap()) |payload_token| { |
| ... | @@ -406,15 +406,15 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -406,15 +406,15 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 406 | .@"nosuspend", | 406 | .@"nosuspend", |
| 407 | .@"suspend", | 407 | .@"suspend", |
| 408 | => { | 408 | => { |
| 409 | const main_token = tree.nodeMainToken(node); | 409 | const main_token = node.mainToken(tree); |
| 410 | const item = tree.nodeData(node).node; | 410 | const item = node.data(tree).node; |
| 411 | try renderToken(r, main_token, .space); | 411 | try renderToken(r, main_token, .space); |
| 412 | return renderExpression(r, item, space); | 412 | return renderExpression(r, item, space); |
| 413 | }, | 413 | }, |
| 414 | 414 | ||
| 415 | .@"catch" => { | 415 | .@"catch" => { |
| 416 | const main_token = tree.nodeMainToken(node); | 416 | const main_token = node.mainToken(tree); |
| 417 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 417 | const lhs, const rhs = node.data(tree).node_and_node; |
| 418 | const fallback_first = tree.firstToken(rhs); | 418 | const fallback_first = tree.firstToken(rhs); |
| 419 | 419 | ||
| 420 | const same_line = tree.tokensOnSameLine(main_token, fallback_first); | 420 | const same_line = tree.tokensOnSameLine(main_token, fallback_first); |
| ... | @@ -437,7 +437,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -437,7 +437,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 437 | }, | 437 | }, |
| 438 | 438 | ||
| 439 | .field_access => { | 439 | .field_access => { |
| 440 | const lhs, const name_token = tree.nodeData(node).node_and_token; | 440 | const lhs, const name_token = node.data(tree).node_and_token; |
| 441 | const dot_token = name_token - 1; | 441 | const dot_token = name_token - 1; |
| 442 | 442 | ||
| 443 | try ais.pushIndent(.field_access); | 443 | try ais.pushIndent(.field_access); |
| ... | @@ -458,19 +458,19 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -458,19 +458,19 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 458 | .error_union, | 458 | .error_union, |
| 459 | .switch_range, | 459 | .switch_range, |
| 460 | => { | 460 | => { |
| 461 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 461 | const lhs, const rhs = node.data(tree).node_and_node; |
| 462 | try renderExpression(r, lhs, .none); | 462 | try renderExpression(r, lhs, .none); |
| 463 | try renderToken(r, tree.nodeMainToken(node), .none); | 463 | try renderToken(r, node.mainToken(tree), .none); |
| 464 | return renderExpression(r, rhs, space); | 464 | return renderExpression(r, rhs, space); |
| 465 | }, | 465 | }, |
| 466 | .for_range => { | 466 | .for_range => { |
| 467 | const start, const opt_end = tree.nodeData(node).node_and_opt_node; | 467 | const start, const opt_end = node.data(tree).node_and_opt_node; |
| 468 | try renderExpression(r, start, .none); | 468 | try renderExpression(r, start, .none); |
| 469 | if (opt_end.unwrap()) |end| { | 469 | if (opt_end.unwrap()) |end| { |
| 470 | try renderToken(r, tree.nodeMainToken(node), .none); | 470 | try renderToken(r, node.mainToken(tree), .none); |
| 471 | return renderExpression(r, end, space); | 471 | return renderExpression(r, end, space); |
| 472 | } else { | 472 | } else { |
| 473 | return renderToken(r, tree.nodeMainToken(node), space); | 473 | return renderToken(r, node.mainToken(tree), space); |
| 474 | } | 474 | } |
| 475 | }, | 475 | }, |
| 476 | 476 | ||
| ... | @@ -493,9 +493,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -493,9 +493,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 493 | .assign_mul_wrap, | 493 | .assign_mul_wrap, |
| 494 | .assign_mul_sat, | 494 | .assign_mul_sat, |
| 495 | => { | 495 | => { |
| 496 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 496 | const lhs, const rhs = node.data(tree).node_and_node; |
| 497 | try renderExpression(r, lhs, .space); | 497 | try renderExpression(r, lhs, .space); |
| 498 | const op_token = tree.nodeMainToken(node); | 498 | const op_token = node.mainToken(tree); |
| 499 | try ais.pushIndent(.after_equals); | 499 | try ais.pushIndent(.after_equals); |
| 500 | if (tree.tokensOnSameLine(op_token, op_token + 1)) { | 500 | if (tree.tokensOnSameLine(op_token, op_token + 1)) { |
| 501 | try renderToken(r, op_token, .space); | 501 | try renderToken(r, op_token, .space); |
| ... | @@ -536,9 +536,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -536,9 +536,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 536 | .sub_sat, | 536 | .sub_sat, |
| 537 | .@"orelse", | 537 | .@"orelse", |
| 538 | => { | 538 | => { |
| 539 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 539 | const lhs, const rhs = node.data(tree).node_and_node; |
| 540 | try renderExpression(r, lhs, .space); | 540 | try renderExpression(r, lhs, .space); |
| 541 | const op_token = tree.nodeMainToken(node); | 541 | const op_token = node.mainToken(tree); |
| 542 | try ais.pushIndent(.binop); | 542 | try ais.pushIndent(.binop); |
| 543 | if (tree.tokensOnSameLine(op_token, op_token + 1)) { | 543 | if (tree.tokensOnSameLine(op_token, op_token + 1)) { |
| 544 | try renderToken(r, op_token, .space); | 544 | try renderToken(r, op_token, .space); |
| ... | @@ -557,7 +557,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -557,7 +557,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 557 | 557 | ||
| 558 | for (full.ast.variables, 0..) |variable_node, i| { | 558 | for (full.ast.variables, 0..) |variable_node, i| { |
| 559 | const variable_space: Space = if (i == full.ast.variables.len - 1) .space else .comma_space; | 559 | const variable_space: Space = if (i == full.ast.variables.len - 1) .space else .comma_space; |
| 560 | switch (tree.nodeTag(variable_node)) { | 560 | switch (variable_node.tag(tree)) { |
| 561 | .global_var_decl, | 561 | .global_var_decl, |
| 562 | .local_var_decl, | 562 | .local_var_decl, |
| 563 | .simple_var_decl, | 563 | .simple_var_decl, |
| ... | @@ -585,16 +585,16 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -585,16 +585,16 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 585 | .optional_type, | 585 | .optional_type, |
| 586 | .address_of, | 586 | .address_of, |
| 587 | => { | 587 | => { |
| 588 | try renderToken(r, tree.nodeMainToken(node), .none); | 588 | try renderToken(r, node.mainToken(tree), .none); |
| 589 | return renderExpression(r, tree.nodeData(node).node, space); | 589 | return renderExpression(r, node.data(tree).node, space); |
| 590 | }, | 590 | }, |
| 591 | 591 | ||
| 592 | .@"try", | 592 | .@"try", |
| 593 | .@"resume", | 593 | .@"resume", |
| 594 | .@"await", | 594 | .@"await", |
| 595 | => { | 595 | => { |
| 596 | try renderToken(r, tree.nodeMainToken(node), .space); | 596 | try renderToken(r, node.mainToken(tree), .space); |
| 597 | return renderExpression(r, tree.nodeData(node).node, space); | 597 | return renderExpression(r, node.data(tree).node, space); |
| 598 | }, | 598 | }, |
| 599 | 599 | ||
| 600 | .array_type, | 600 | .array_type, |
| ... | @@ -647,7 +647,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -647,7 +647,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 647 | }, | 647 | }, |
| 648 | 648 | ||
| 649 | .array_access => { | 649 | .array_access => { |
| 650 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 650 | const lhs, const rhs = node.data(tree).node_and_node; |
| 651 | const lbracket = tree.firstToken(rhs) - 1; | 651 | const lbracket = tree.firstToken(rhs) - 1; |
| 652 | const rbracket = tree.lastToken(rhs) + 1; | 652 | const rbracket = tree.lastToken(rhs) + 1; |
| 653 | const one_line = tree.tokensOnSameLine(lbracket, rbracket); | 653 | const one_line = tree.tokensOnSameLine(lbracket, rbracket); |
| ... | @@ -666,12 +666,12 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -666,12 +666,12 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 666 | => return renderSlice(r, node, tree.fullSlice(node).?, space), | 666 | => return renderSlice(r, node, tree.fullSlice(node).?, space), |
| 667 | 667 | ||
| 668 | .deref => { | 668 | .deref => { |
| 669 | try renderExpression(r, tree.nodeData(node).node, .none); | 669 | try renderExpression(r, node.data(tree).node, .none); |
| 670 | return renderToken(r, tree.nodeMainToken(node), space); | 670 | return renderToken(r, node.mainToken(tree), space); |
| 671 | }, | 671 | }, |
| 672 | 672 | ||
| 673 | .unwrap_optional => { | 673 | .unwrap_optional => { |
| 674 | const lhs, const question_mark = tree.nodeData(node).node_and_token; | 674 | const lhs, const question_mark = node.data(tree).node_and_token; |
| 675 | const dot_token = question_mark - 1; | 675 | const dot_token = question_mark - 1; |
| 676 | try renderExpression(r, lhs, .none); | 676 | try renderExpression(r, lhs, .none); |
| 677 | try renderToken(r, dot_token, .none); | 677 | try renderToken(r, dot_token, .none); |
| ... | @@ -679,8 +679,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -679,8 +679,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 679 | }, | 679 | }, |
| 680 | 680 | ||
| 681 | .@"break", .@"continue" => { | 681 | .@"break", .@"continue" => { |
| 682 | const main_token = tree.nodeMainToken(node); | 682 | const main_token = node.mainToken(tree); |
| 683 | const opt_label_token, const opt_target = tree.nodeData(node).opt_token_and_opt_node; | 683 | const opt_label_token, const opt_target = node.data(tree).opt_token_and_opt_node; |
| 684 | if (opt_label_token == .none and opt_target == .none) { | 684 | if (opt_label_token == .none and opt_target == .none) { |
| 685 | try renderToken(r, main_token, space); // break/continue | 685 | try renderToken(r, main_token, space); // break/continue |
| 686 | } else if (opt_label_token == .none and opt_target != .none) { | 686 | } else if (opt_label_token == .none and opt_target != .none) { |
| ... | @@ -703,18 +703,18 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -703,18 +703,18 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 703 | }, | 703 | }, |
| 704 | 704 | ||
| 705 | .@"return" => { | 705 | .@"return" => { |
| 706 | if (tree.nodeData(node).opt_node.unwrap()) |expr| { | 706 | if (node.data(tree).opt_node.unwrap()) |expr| { |
| 707 | try renderToken(r, tree.nodeMainToken(node), .space); | 707 | try renderToken(r, node.mainToken(tree), .space); |
| 708 | try renderExpression(r, expr, space); | 708 | try renderExpression(r, expr, space); |
| 709 | } else { | 709 | } else { |
| 710 | try renderToken(r, tree.nodeMainToken(node), space); | 710 | try renderToken(r, node.mainToken(tree), space); |
| 711 | } | 711 | } |
| 712 | }, | 712 | }, |
| 713 | 713 | ||
| 714 | .grouped_expression => { | 714 | .grouped_expression => { |
| 715 | const expr, const rparen = tree.nodeData(node).node_and_token; | 715 | const expr, const rparen = node.data(tree).node_and_token; |
| 716 | try ais.pushIndent(.normal); | 716 | try ais.pushIndent(.normal); |
| 717 | try renderToken(r, tree.nodeMainToken(node), .none); // lparen | 717 | try renderToken(r, node.mainToken(tree), .none); // lparen |
| 718 | try renderExpression(r, expr, .none); | 718 | try renderExpression(r, expr, .none); |
| 719 | ais.popIndent(); | 719 | ais.popIndent(); |
| 720 | return renderToken(r, rparen, space); | 720 | return renderToken(r, rparen, space); |
| ... | @@ -738,8 +738,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -738,8 +738,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 738 | }, | 738 | }, |
| 739 | 739 | ||
| 740 | .error_set_decl => { | 740 | .error_set_decl => { |
| 741 | const error_token = tree.nodeMainToken(node); | 741 | const error_token = node.mainToken(tree); |
| 742 | const lbrace, const rbrace = tree.nodeData(node).token_and_token; | 742 | const lbrace, const rbrace = node.data(tree).token_and_token; |
| 743 | 743 | ||
| 744 | try renderToken(r, error_token, .none); | 744 | try renderToken(r, error_token, .none); |
| 745 | 745 | ||
| ... | @@ -796,7 +796,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -796,7 +796,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 796 | => { | 796 | => { |
| 797 | var buf: [2]Ast.Node.Index = undefined; | 797 | var buf: [2]Ast.Node.Index = undefined; |
| 798 | const params = tree.builtinCallParams(&buf, node).?; | 798 | const params = tree.builtinCallParams(&buf, node).?; |
| 799 | return renderBuiltinCall(r, tree.nodeMainToken(node), params, space); | 799 | return renderBuiltinCall(r, node.mainToken(tree), params, space); |
| 800 | }, | 800 | }, |
| 801 | 801 | ||
| 802 | .fn_proto_simple, | 802 | .fn_proto_simple, |
| ... | @@ -809,10 +809,10 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -809,10 +809,10 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 809 | }, | 809 | }, |
| 810 | 810 | ||
| 811 | .anyframe_type => { | 811 | .anyframe_type => { |
| 812 | const main_token = tree.nodeMainToken(node); | 812 | const main_token = node.mainToken(tree); |
| 813 | try renderToken(r, main_token, .none); // anyframe | 813 | try renderToken(r, main_token, .none); // anyframe |
| 814 | try renderToken(r, main_token + 1, .none); // -> | 814 | try renderToken(r, main_token + 1, .none); // -> |
| 815 | return renderExpression(r, tree.nodeData(node).token_and_node[1], space); | 815 | return renderExpression(r, node.data(tree).token_and_node[1], space); |
| 816 | }, | 816 | }, |
| 817 | 817 | ||
| 818 | .@"switch", | 818 | .@"switch", |
| ... | @@ -869,8 +869,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -869,8 +869,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 869 | => return renderAsm(r, tree.fullAsm(node).?, space), | 869 | => return renderAsm(r, tree.fullAsm(node).?, space), |
| 870 | 870 | ||
| 871 | .enum_literal => { | 871 | .enum_literal => { |
| 872 | try renderToken(r, tree.nodeMainToken(node) - 1, .none); // . | 872 | try renderToken(r, node.mainToken(tree) - 1, .none); // . |
| 873 | return renderIdentifier(r, tree.nodeMainToken(node), space, .eagerly_unquote); // name | 873 | return renderIdentifier(r, node.mainToken(tree), space, .eagerly_unquote); // name |
| 874 | }, | 874 | }, |
| 875 | 875 | ||
| 876 | .fn_decl => unreachable, | 876 | .fn_decl => unreachable, |
| ... | @@ -932,7 +932,7 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi | ... | @@ -932,7 +932,7 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi |
| 932 | // this pointer type and rely on the child to render our asterisk | 932 | // this pointer type and rely on the child to render our asterisk |
| 933 | // as well when it renders the ** token. | 933 | // as well when it renders the ** token. |
| 934 | if (tree.tokenTag(main_token) == .asterisk_asterisk and | 934 | if (tree.tokenTag(main_token) == .asterisk_asterisk and |
| 935 | main_token == tree.nodeMainToken(ptr_type.ast.child_type)) | 935 | main_token == ptr_type.ast.child_type.mainToken(tree)) |
| 936 | { | 936 | { |
| 937 | return renderExpression(r, ptr_type.ast.child_type, space); | 937 | return renderExpression(r, ptr_type.ast.child_type, space); |
| 938 | } | 938 | } |
| ... | @@ -1017,8 +1017,8 @@ fn renderSlice( | ... | @@ -1017,8 +1017,8 @@ fn renderSlice( |
| 1017 | space: Space, | 1017 | space: Space, |
| 1018 | ) Error!void { | 1018 | ) Error!void { |
| 1019 | const tree = r.tree; | 1019 | const tree = r.tree; |
| 1020 | const after_start_space_bool = nodeCausesSliceOpSpace(tree.nodeTag(slice.ast.start)) or | 1020 | const after_start_space_bool = nodeCausesSliceOpSpace(slice.ast.start.tag(tree)) or |
| 1021 | if (slice.ast.end.unwrap()) |end| nodeCausesSliceOpSpace(tree.nodeTag(end)) else false; | 1021 | if (slice.ast.end.unwrap()) |end| nodeCausesSliceOpSpace(end.tag(tree)) else false; |
| 1022 | const after_start_space = if (after_start_space_bool) Space.space else Space.none; | 1022 | const after_start_space = if (after_start_space_bool) Space.space else Space.none; |
| 1023 | const after_dots_space = if (slice.ast.end != .none) | 1023 | const after_dots_space = if (slice.ast.end != .none) |
| 1024 | after_start_space | 1024 | after_start_space |
| ... | @@ -1050,8 +1050,8 @@ fn renderAsmOutput( | ... | @@ -1050,8 +1050,8 @@ fn renderAsmOutput( |
| 1050 | space: Space, | 1050 | space: Space, |
| 1051 | ) Error!void { | 1051 | ) Error!void { |
| 1052 | const tree = r.tree; | 1052 | const tree = r.tree; |
| 1053 | assert(tree.nodeTag(asm_output) == .asm_output); | 1053 | assert(asm_output.tag(tree) == .asm_output); |
| 1054 | const symbolic_name = tree.nodeMainToken(asm_output); | 1054 | const symbolic_name = asm_output.mainToken(tree); |
| 1055 | 1055 | ||
| 1056 | try renderToken(r, symbolic_name - 1, .none); // lbracket | 1056 | try renderToken(r, symbolic_name - 1, .none); // lbracket |
| 1057 | try renderIdentifier(r, symbolic_name, .none, .eagerly_unquote); // ident | 1057 | try renderIdentifier(r, symbolic_name, .none, .eagerly_unquote); // ident |
| ... | @@ -1060,7 +1060,7 @@ fn renderAsmOutput( | ... | @@ -1060,7 +1060,7 @@ fn renderAsmOutput( |
| 1060 | try renderToken(r, symbolic_name + 3, .none); // lparen | 1060 | try renderToken(r, symbolic_name + 3, .none); // lparen |
| 1061 | 1061 | ||
| 1062 | if (tree.tokenTag(symbolic_name + 4) == .arrow) { | 1062 | if (tree.tokenTag(symbolic_name + 4) == .arrow) { |
| 1063 | const type_expr, const rparen = tree.nodeData(asm_output).opt_node_and_token; | 1063 | const type_expr, const rparen = asm_output.data(tree).opt_node_and_token; |
| 1064 | try renderToken(r, symbolic_name + 4, .space); // -> | 1064 | try renderToken(r, symbolic_name + 4, .space); // -> |
| 1065 | try renderExpression(r, type_expr.unwrap().?, Space.none); | 1065 | try renderExpression(r, type_expr.unwrap().?, Space.none); |
| 1066 | return renderToken(r, rparen, space); | 1066 | return renderToken(r, rparen, space); |
| ... | @@ -1076,9 +1076,9 @@ fn renderAsmInput( | ... | @@ -1076,9 +1076,9 @@ fn renderAsmInput( |
| 1076 | space: Space, | 1076 | space: Space, |
| 1077 | ) Error!void { | 1077 | ) Error!void { |
| 1078 | const tree = r.tree; | 1078 | const tree = r.tree; |
| 1079 | assert(tree.nodeTag(asm_input) == .asm_input); | 1079 | assert(asm_input.tag(tree) == .asm_input); |
| 1080 | const symbolic_name = tree.nodeMainToken(asm_input); | 1080 | const symbolic_name = asm_input.mainToken(tree); |
| 1081 | const expr, const rparen = tree.nodeData(asm_input).node_and_token; | 1081 | const expr, const rparen = asm_input.data(tree).node_and_token; |
| 1082 | 1082 | ||
| 1083 | try renderToken(r, symbolic_name - 1, .none); // lbracket | 1083 | try renderToken(r, symbolic_name - 1, .none); // lbracket |
| 1084 | try renderIdentifier(r, symbolic_name, .none, .eagerly_unquote); // ident | 1084 | try renderIdentifier(r, symbolic_name, .none, .eagerly_unquote); // ident |
| ... | @@ -1318,7 +1318,7 @@ fn renderThenElse( | ... | @@ -1318,7 +1318,7 @@ fn renderThenElse( |
| 1318 | ) Error!void { | 1318 | ) Error!void { |
| 1319 | const tree = r.tree; | 1319 | const tree = r.tree; |
| 1320 | const ais = r.ais; | 1320 | const ais = r.ais; |
| 1321 | const then_expr_is_block = nodeIsBlock(tree.nodeTag(then_expr)); | 1321 | const then_expr_is_block = nodeIsBlock(then_expr.tag(tree)); |
| 1322 | const indent_then_expr = !then_expr_is_block and | 1322 | const indent_then_expr = !then_expr_is_block and |
| 1323 | !tree.tokensOnSameLine(last_prefix_token, tree.firstToken(then_expr)); | 1323 | !tree.tokensOnSameLine(last_prefix_token, tree.firstToken(then_expr)); |
| 1324 | 1324 | ||
| ... | @@ -1353,8 +1353,8 @@ fn renderThenElse( | ... | @@ -1353,8 +1353,8 @@ fn renderThenElse( |
| 1353 | } | 1353 | } |
| 1354 | 1354 | ||
| 1355 | const indent_else_expr = indent_then_expr and | 1355 | const indent_else_expr = indent_then_expr and |
| 1356 | !nodeIsBlock(tree.nodeTag(else_expr)) and | 1356 | !nodeIsBlock(else_expr.tag(tree)) and |
| 1357 | !nodeIsIfForWhileSwitch(tree.nodeTag(else_expr)); | 1357 | !nodeIsIfForWhileSwitch(else_expr.tag(tree)); |
| 1358 | if (indent_else_expr) { | 1358 | if (indent_else_expr) { |
| 1359 | try ais.pushIndent(.normal); | 1359 | try ais.pushIndent(.normal); |
| 1360 | try renderToken(r, last_else_token, .newline); | 1360 | try renderToken(r, last_else_token, .newline); |
| ... | @@ -1449,7 +1449,7 @@ fn renderContainerField( | ... | @@ -1449,7 +1449,7 @@ fn renderContainerField( |
| 1449 | const tree = r.tree; | 1449 | const tree = r.tree; |
| 1450 | const ais = r.ais; | 1450 | const ais = r.ais; |
| 1451 | var field = field_param; | 1451 | var field = field_param; |
| 1452 | if (container != .tuple) field.convertToNonTupleLike(&tree); | 1452 | if (container != .tuple) field.convertToNonTupleLike(tree); |
| 1453 | const quote: QuoteBehavior = switch (container) { | 1453 | const quote: QuoteBehavior = switch (container) { |
| 1454 | .@"enum" => .eagerly_unquote_except_underscore, | 1454 | .@"enum" => .eagerly_unquote_except_underscore, |
| 1455 | .tuple, .other => .eagerly_unquote, | 1455 | .tuple, .other => .eagerly_unquote, |
| ... | @@ -1569,7 +1569,7 @@ fn renderBuiltinCall( | ... | @@ -1569,7 +1569,7 @@ fn renderBuiltinCall( |
| 1569 | const slice = tree.tokenSlice(builtin_token); | 1569 | const slice = tree.tokenSlice(builtin_token); |
| 1570 | if (mem.eql(u8, slice, "@import")) f: { | 1570 | if (mem.eql(u8, slice, "@import")) f: { |
| 1571 | const param = params[0]; | 1571 | const param = params[0]; |
| 1572 | const str_lit_token = tree.nodeMainToken(param); | 1572 | const str_lit_token = param.mainToken(tree); |
| 1573 | assert(tree.tokenTag(str_lit_token) == .string_literal); | 1573 | assert(tree.tokenTag(str_lit_token) == .string_literal); |
| 1574 | const token_bytes = tree.tokenSlice(str_lit_token); | 1574 | const token_bytes = tree.tokenSlice(str_lit_token); |
| 1575 | const imported_string = std.zig.string_literal.parseAlloc(r.gpa, token_bytes) catch |err| switch (err) { | 1575 | const imported_string = std.zig.string_literal.parseAlloc(r.gpa, token_bytes) catch |err| switch (err) { |
| ... | @@ -1829,7 +1829,7 @@ fn renderFnProto(r: *Render, fn_proto: Ast.full.FnProto, space: Space) Error!voi | ... | @@ -1829,7 +1829,7 @@ fn renderFnProto(r: *Render, fn_proto: Ast.full.FnProto, space: Space) Error!voi |
| 1829 | 1829 | ||
| 1830 | if (fn_proto.ast.callconv_expr.unwrap()) |callconv_expr| { | 1830 | if (fn_proto.ast.callconv_expr.unwrap()) |callconv_expr| { |
| 1831 | // Keep in sync with logic in `renderMember`. Search this file for the marker PROMOTE_CALLCONV_INLINE | 1831 | // Keep in sync with logic in `renderMember`. Search this file for the marker PROMOTE_CALLCONV_INLINE |
| 1832 | const is_callconv_inline = mem.eql(u8, "@\"inline\"", tree.tokenSlice(tree.nodeMainToken(callconv_expr))); | 1832 | const is_callconv_inline = mem.eql(u8, "@\"inline\"", tree.tokenSlice(callconv_expr.mainToken(tree))); |
| 1833 | const is_declaration = fn_proto.name_token != null; | 1833 | const is_declaration = fn_proto.name_token != null; |
| 1834 | if (!(is_declaration and is_callconv_inline)) { | 1834 | if (!(is_declaration and is_callconv_inline)) { |
| 1835 | const callconv_lparen = tree.firstToken(callconv_expr) - 1; | 1835 | const callconv_lparen = tree.firstToken(callconv_expr) - 1; |
| ... | @@ -1882,7 +1882,7 @@ fn renderSwitchCase( | ... | @@ -1882,7 +1882,7 @@ fn renderSwitchCase( |
| 1882 | } | 1882 | } |
| 1883 | 1883 | ||
| 1884 | // Render the arrow and everything after it | 1884 | // Render the arrow and everything after it |
| 1885 | const pre_target_space = if (tree.nodeTag(switch_case.ast.target_expr) == .multiline_string_literal) | 1885 | const pre_target_space = if (switch_case.ast.target_expr.tag(tree) == .multiline_string_literal) |
| 1886 | // Newline gets inserted when rendering the target expr. | 1886 | // Newline gets inserted when rendering the target expr. |
| 1887 | Space.none | 1887 | Space.none |
| 1888 | else | 1888 | else |
| ... | @@ -1917,7 +1917,7 @@ fn renderBlock( | ... | @@ -1917,7 +1917,7 @@ fn renderBlock( |
| 1917 | ) Error!void { | 1917 | ) Error!void { |
| 1918 | const tree = r.tree; | 1918 | const tree = r.tree; |
| 1919 | const ais = r.ais; | 1919 | const ais = r.ais; |
| 1920 | const lbrace = tree.nodeMainToken(block_node); | 1920 | const lbrace = block_node.mainToken(tree); |
| 1921 | 1921 | ||
| 1922 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { | 1922 | if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) { |
| 1923 | try renderIdentifier(r, lbrace - 2, .none, .eagerly_unquote); // identifier | 1923 | try renderIdentifier(r, lbrace - 2, .none, .eagerly_unquote); // identifier |
| ... | @@ -1946,7 +1946,7 @@ fn finishRenderBlock( | ... | @@ -1946,7 +1946,7 @@ fn finishRenderBlock( |
| 1946 | if (i != 0) try renderExtraNewline(r, stmt); | 1946 | if (i != 0) try renderExtraNewline(r, stmt); |
| 1947 | if (r.fixups.omit_nodes.contains(stmt)) continue; | 1947 | if (r.fixups.omit_nodes.contains(stmt)) continue; |
| 1948 | try ais.pushSpace(.semicolon); | 1948 | try ais.pushSpace(.semicolon); |
| 1949 | switch (tree.nodeTag(stmt)) { | 1949 | switch (stmt.tag(tree)) { |
| 1950 | .global_var_decl, | 1950 | .global_var_decl, |
| 1951 | .local_var_decl, | 1951 | .local_var_decl, |
| 1952 | .simple_var_decl, | 1952 | .simple_var_decl, |
| ... | @@ -1996,7 +1996,7 @@ fn renderStructInit( | ... | @@ -1996,7 +1996,7 @@ fn renderStructInit( |
| 1996 | // Don't output a space after the = if expression is a multiline string, | 1996 | // Don't output a space after the = if expression is a multiline string, |
| 1997 | // since then it will start on the next line. | 1997 | // since then it will start on the next line. |
| 1998 | const field_node = struct_init.ast.fields[0]; | 1998 | const field_node = struct_init.ast.fields[0]; |
| 1999 | const expr = tree.nodeTag(field_node); | 1999 | const expr = field_node.tag(tree); |
| 2000 | var space_after_equal: Space = if (expr == .multiline_string_literal) .none else .space; | 2000 | var space_after_equal: Space = if (expr == .multiline_string_literal) .none else .space; |
| 2001 | try renderToken(r, struct_init.ast.lbrace + 3, space_after_equal); // = | 2001 | try renderToken(r, struct_init.ast.lbrace + 3, space_after_equal); // = |
| 2002 | 2002 | ||
| ... | @@ -2009,7 +2009,7 @@ fn renderStructInit( | ... | @@ -2009,7 +2009,7 @@ fn renderStructInit( |
| 2009 | try renderExtraNewlineToken(r, init_token - 3); | 2009 | try renderExtraNewlineToken(r, init_token - 3); |
| 2010 | try renderToken(r, init_token - 3, .none); // . | 2010 | try renderToken(r, init_token - 3, .none); // . |
| 2011 | try renderIdentifier(r, init_token - 2, .space, .eagerly_unquote); // name | 2011 | try renderIdentifier(r, init_token - 2, .space, .eagerly_unquote); // name |
| 2012 | space_after_equal = if (tree.nodeTag(field_init) == .multiline_string_literal) .none else .space; | 2012 | space_after_equal = if (field_init.tag(tree) == .multiline_string_literal) .none else .space; |
| 2013 | try renderToken(r, init_token - 1, space_after_equal); // = | 2013 | try renderToken(r, init_token - 1, space_after_equal); // = |
| 2014 | 2014 | ||
| 2015 | try ais.pushSpace(.comma); | 2015 | try ais.pushSpace(.comma); |
| ... | @@ -2361,7 +2361,7 @@ fn renderContainerDecl( | ... | @@ -2361,7 +2361,7 @@ fn renderContainerDecl( |
| 2361 | } | 2361 | } |
| 2362 | for (container_decl.ast.members, 0..) |member, i| { | 2362 | for (container_decl.ast.members, 0..) |member, i| { |
| 2363 | if (i != 0) try renderExtraNewline(r, member); | 2363 | if (i != 0) try renderExtraNewline(r, member); |
| 2364 | switch (tree.nodeTag(member)) { | 2364 | switch (member.tag(tree)) { |
| 2365 | // For container fields, ensure a trailing comma is added if necessary. | 2365 | // For container fields, ensure a trailing comma is added if necessary. |
| 2366 | .container_field_init, | 2366 | .container_field_init, |
| 2367 | .container_field_align, | 2367 | .container_field_align, |
| ... | @@ -2919,7 +2919,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void { | ... | @@ -2919,7 +2919,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void { |
| 2919 | /// `start_token` to `end_token`. This is used to determine if e.g. a | 2919 | /// `start_token` to `end_token`. This is used to determine if e.g. a |
| 2920 | /// fn_proto should be wrapped and have a trailing comma inserted even if | 2920 | /// fn_proto should be wrapped and have a trailing comma inserted even if |
| 2921 | /// there is none in the source. | 2921 | /// there is none in the source. |
| 2922 | fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool { | 2922 | fn hasComment(tree: *const Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool { |
| 2923 | for (start_token..end_token) |i| { | 2923 | for (start_token..end_token) |i| { |
| 2924 | const token: Ast.TokenIndex = @intCast(i); | 2924 | const token: Ast.TokenIndex = @intCast(i); |
| 2925 | const start = tree.tokenStart(token) + tree.tokenSlice(token).len; | 2925 | const start = tree.tokenStart(token) + tree.tokenSlice(token).len; |
| ... | @@ -2932,7 +2932,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) | ... | @@ -2932,7 +2932,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) |
| 2932 | 2932 | ||
| 2933 | /// Returns true if there exists a multiline string literal between the start | 2933 | /// Returns true if there exists a multiline string literal between the start |
| 2934 | /// of token `start_token` and the start of token `end_token`. | 2934 | /// of token `start_token` and the start of token `end_token`. |
| 2935 | fn hasMultilineString(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool { | 2935 | fn hasMultilineString(tree: *const Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool { |
| 2936 | return std.mem.indexOfScalar( | 2936 | return std.mem.indexOfScalar( |
| 2937 | Token.Tag, | 2937 | Token.Tag, |
| 2938 | tree.tokens.items(.tag)[start_token..end_token], | 2938 | tree.tokens.items(.tag)[start_token..end_token], |
| ... | @@ -3084,7 +3084,7 @@ fn renderContainerDocComments(r: *Render, start_token: Ast.TokenIndex) Error!voi | ... | @@ -3084,7 +3084,7 @@ fn renderContainerDocComments(r: *Render, start_token: Ast.TokenIndex) Error!voi |
| 3084 | } | 3084 | } |
| 3085 | 3085 | ||
| 3086 | fn discardAllParams(r: *Render, fn_proto_node: Ast.Node.Index) Error!void { | 3086 | fn discardAllParams(r: *Render, fn_proto_node: Ast.Node.Index) Error!void { |
| 3087 | const tree = &r.tree; | 3087 | const tree = r.tree; |
| 3088 | const ais = r.ais; | 3088 | const ais = r.ais; |
| 3089 | var buf: [1]Ast.Node.Index = undefined; | 3089 | var buf: [1]Ast.Node.Index = undefined; |
| 3090 | const fn_proto = tree.fullFnProto(&buf, fn_proto_node).?; | 3090 | const fn_proto = tree.fullFnProto(&buf, fn_proto_node).?; |
| ... | @@ -3094,12 +3094,12 @@ fn discardAllParams(r: *Render, fn_proto_node: Ast.Node.Index) Error!void { | ... | @@ -3094,12 +3094,12 @@ fn discardAllParams(r: *Render, fn_proto_node: Ast.Node.Index) Error!void { |
| 3094 | assert(tree.tokenTag(name_ident) == .identifier); | 3094 | assert(tree.tokenTag(name_ident) == .identifier); |
| 3095 | const w = ais.writer(); | 3095 | const w = ais.writer(); |
| 3096 | try w.writeAll("_ = "); | 3096 | try w.writeAll("_ = "); |
| 3097 | try w.writeAll(tokenSliceForRender(r.tree, name_ident)); | 3097 | try w.writeAll(tokenSliceForRender(tree, name_ident)); |
| 3098 | try w.writeAll(";\n"); | 3098 | try w.writeAll(";\n"); |
| 3099 | } | 3099 | } |
| 3100 | } | 3100 | } |
| 3101 | 3101 | ||
| 3102 | fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 { | 3102 | fn tokenSliceForRender(tree: *const Ast, token_index: Ast.TokenIndex) []const u8 { |
| 3103 | var ret = tree.tokenSlice(token_index); | 3103 | var ret = tree.tokenSlice(token_index); |
| 3104 | switch (tree.tokenTag(token_index)) { | 3104 | switch (tree.tokenTag(token_index)) { |
| 3105 | .container_doc_comment, .doc_comment => { | 3105 | .container_doc_comment, .doc_comment => { |
| ... | @@ -3110,7 +3110,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 { | ... | @@ -3110,7 +3110,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 { |
| 3110 | return ret; | 3110 | return ret; |
| 3111 | } | 3111 | } |
| 3112 | 3112 | ||
| 3113 | fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool { | 3113 | fn hasSameLineComment(tree: *const Ast, token_index: Ast.TokenIndex) bool { |
| 3114 | const between_source = tree.source[tree.tokenStart(token_index)..tree.tokenStart(token_index + 1)]; | 3114 | const between_source = tree.source[tree.tokenStart(token_index)..tree.tokenStart(token_index + 1)]; |
| 3115 | for (between_source) |byte| switch (byte) { | 3115 | for (between_source) |byte| switch (byte) { |
| 3116 | '\n' => return false, | 3116 | '\n' => return false, |
| ... | @@ -3122,7 +3122,7 @@ fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool { | ... | @@ -3122,7 +3122,7 @@ fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool { |
| 3122 | 3122 | ||
| 3123 | /// Returns `true` if and only if there are any tokens or line comments between | 3123 | /// Returns `true` if and only if there are any tokens or line comments between |
| 3124 | /// start_token and end_token. | 3124 | /// start_token and end_token. |
| 3125 | fn anythingBetween(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool { | 3125 | fn anythingBetween(tree: *const Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool { |
| 3126 | if (start_token + 1 != end_token) return true; | 3126 | if (start_token + 1 != end_token) return true; |
| 3127 | const between_source = tree.source[tree.tokenStart(start_token)..tree.tokenStart(start_token + 1)]; | 3127 | const between_source = tree.source[tree.tokenStart(start_token)..tree.tokenStart(start_token + 1)]; |
| 3128 | for (between_source) |byte| switch (byte) { | 3128 | for (between_source) |byte| switch (byte) { |
| ... | @@ -3217,7 +3217,7 @@ fn nodeCausesSliceOpSpace(tag: Ast.Node.Tag) bool { | ... | @@ -3217,7 +3217,7 @@ fn nodeCausesSliceOpSpace(tag: Ast.Node.Tag) bool { |
| 3217 | } | 3217 | } |
| 3218 | 3218 | ||
| 3219 | // Returns the number of nodes in `exprs` that are on the same line as `rtoken`. | 3219 | // Returns the number of nodes in `exprs` that are on the same line as `rtoken`. |
| 3220 | fn rowSize(tree: Ast, exprs: []const Ast.Node.Index, rtoken: Ast.TokenIndex) usize { | 3220 | fn rowSize(tree: *const Ast, exprs: []const Ast.Node.Index, rtoken: Ast.TokenIndex) usize { |
| 3221 | const first_token = tree.firstToken(exprs[0]); | 3221 | const first_token = tree.firstToken(exprs[0]); |
| 3222 | if (tree.tokensOnSameLine(first_token, rtoken)) { | 3222 | if (tree.tokensOnSameLine(first_token, rtoken)) { |
| 3223 | const maybe_comma = rtoken - 1; | 3223 | const maybe_comma = rtoken - 1; |
lib/std/zon/parse.zig+5-5| ... | @@ -198,7 +198,7 @@ pub const Error = union(enum) { | ... | @@ -198,7 +198,7 @@ pub const Error = union(enum) { |
| 198 | return location; | 198 | return location; |
| 199 | } else { | 199 | } else { |
| 200 | const ast_node: Ast.Node.Index = @enumFromInt(node_or_offset); | 200 | const ast_node: Ast.Node.Index = @enumFromInt(node_or_offset); |
| 201 | const token = ast.nodeMainToken(ast_node); | 201 | const token = ast_node.mainToken(ast); |
| 202 | return ast.tokenLocation(0, token); | 202 | return ast.tokenLocation(0, token); |
| 203 | } | 203 | } |
| 204 | } | 204 | } |
| ... | @@ -644,7 +644,7 @@ const Parser = struct { | ... | @@ -644,7 +644,7 @@ const Parser = struct { |
| 644 | switch (try ZonGen.parseStrLit(self.ast, ast_node, buf.writer(self.gpa))) { | 644 | switch (try ZonGen.parseStrLit(self.ast, ast_node, buf.writer(self.gpa))) { |
| 645 | .success => {}, | 645 | .success => {}, |
| 646 | .failure => |err| { | 646 | .failure => |err| { |
| 647 | const token = self.ast.nodeMainToken(ast_node); | 647 | const token = ast_node.mainToken(self.ast); |
| 648 | const raw_string = self.ast.tokenSlice(token); | 648 | const raw_string = self.ast.tokenSlice(token); |
| 649 | return self.failTokenFmt(token, @intCast(err.offset()), "{s}", .{err.fmt(raw_string)}); | 649 | return self.failTokenFmt(token, @intCast(err.offset()), "{s}", .{err.fmt(raw_string)}); |
| 650 | }, | 650 | }, |
| ... | @@ -1017,7 +1017,7 @@ const Parser = struct { | ... | @@ -1017,7 +1017,7 @@ const Parser = struct { |
| 1017 | args: anytype, | 1017 | args: anytype, |
| 1018 | ) error{ OutOfMemory, ParseZon } { | 1018 | ) error{ OutOfMemory, ParseZon } { |
| 1019 | @branchHint(.cold); | 1019 | @branchHint(.cold); |
| 1020 | const token = self.ast.nodeMainToken(node.getAstNode(self.zoir)); | 1020 | const token = node.getAstNode(self.zoir).mainToken(self.ast); |
| 1021 | return self.failTokenFmt(token, 0, fmt, args); | 1021 | return self.failTokenFmt(token, 0, fmt, args); |
| 1022 | } | 1022 | } |
| 1023 | 1023 | ||
| ... | @@ -1036,7 +1036,7 @@ const Parser = struct { | ... | @@ -1036,7 +1036,7 @@ const Parser = struct { |
| 1036 | message: []const u8, | 1036 | message: []const u8, |
| 1037 | ) error{ParseZon} { | 1037 | ) error{ParseZon} { |
| 1038 | @branchHint(.cold); | 1038 | @branchHint(.cold); |
| 1039 | const token = self.ast.nodeMainToken(node.getAstNode(self.zoir)); | 1039 | const token = node.getAstNode(self.zoir).mainToken(self.ast); |
| 1040 | return self.failToken(.{ | 1040 | return self.failToken(.{ |
| 1041 | .token = token, | 1041 | .token = token, |
| 1042 | .offset = 0, | 1042 | .offset = 0, |
| ... | @@ -1069,7 +1069,7 @@ const Parser = struct { | ... | @@ -1069,7 +1069,7 @@ const Parser = struct { |
| 1069 | const struct_init = self.ast.fullStructInit(&buf, node.getAstNode(self.zoir)).?; | 1069 | const struct_init = self.ast.fullStructInit(&buf, node.getAstNode(self.zoir)).?; |
| 1070 | const field_node = struct_init.ast.fields[f]; | 1070 | const field_node = struct_init.ast.fields[f]; |
| 1071 | break :b self.ast.firstToken(field_node) - 2; | 1071 | break :b self.ast.firstToken(field_node) - 2; |
| 1072 | } else self.ast.nodeMainToken(node.getAstNode(self.zoir)); | 1072 | } else node.getAstNode(self.zoir).mainToken(self.ast); |
| 1073 | switch (@typeInfo(T)) { | 1073 | switch (@typeInfo(T)) { |
| 1074 | inline .@"struct", .@"union", .@"enum" => |info| { | 1074 | inline .@"struct", .@"union", .@"enum" => |info| { |
| 1075 | const note: Error.TypeCheckFailure.Note = if (info.fields.len == 0) b: { | 1075 | const note: Error.TypeCheckFailure.Note = if (info.fields.len == 0) b: { |
src/Package/Manifest.zig+36-36| ... | @@ -58,7 +58,7 @@ pub const ParseOptions = struct { | ... | @@ -58,7 +58,7 @@ pub const ParseOptions = struct { |
| 58 | pub const Error = Allocator.Error; | 58 | pub const Error = Allocator.Error; |
| 59 | 59 | ||
| 60 | pub fn parse(gpa: Allocator, ast: Ast, options: ParseOptions) Error!Manifest { | 60 | pub fn parse(gpa: Allocator, ast: Ast, options: ParseOptions) Error!Manifest { |
| 61 | const main_node_index = ast.nodeData(.root).node; | 61 | const main_node_index = Ast.Node.Index.root.data(&ast).node; |
| 62 | 62 | ||
| 63 | var arena_instance = std.heap.ArenaAllocator.init(gpa); | 63 | var arena_instance = std.heap.ArenaAllocator.init(gpa); |
| 64 | errdefer arena_instance.deinit(); | 64 | errdefer arena_instance.deinit(); |
| ... | @@ -158,8 +158,8 @@ const Parse = struct { | ... | @@ -158,8 +158,8 @@ const Parse = struct { |
| 158 | const InnerError = error{ ParseFailure, OutOfMemory }; | 158 | const InnerError = error{ ParseFailure, OutOfMemory }; |
| 159 | 159 | ||
| 160 | fn parseRoot(p: *Parse, node: Ast.Node.Index) !void { | 160 | fn parseRoot(p: *Parse, node: Ast.Node.Index) !void { |
| 161 | const ast = p.ast; | 161 | const ast = &p.ast; |
| 162 | const main_token = ast.nodeMainToken(node); | 162 | const main_token = node.mainToken(ast); |
| 163 | 163 | ||
| 164 | var buf: [2]Ast.Node.Index = undefined; | 164 | var buf: [2]Ast.Node.Index = undefined; |
| 165 | const struct_init = ast.fullStructInit(&buf, node) orelse { | 165 | const struct_init = ast.fullStructInit(&buf, node) orelse { |
| ... | @@ -192,17 +192,17 @@ const Parse = struct { | ... | @@ -192,17 +192,17 @@ const Parse = struct { |
| 192 | p.version_node = field_init; | 192 | p.version_node = field_init; |
| 193 | const version_text = try parseString(p, field_init); | 193 | const version_text = try parseString(p, field_init); |
| 194 | if (version_text.len > max_version_len) { | 194 | if (version_text.len > max_version_len) { |
| 195 | try appendError(p, ast.nodeMainToken(field_init), "version string length {d} exceeds maximum of {d}", .{ version_text.len, max_version_len }); | 195 | try appendError(p, field_init.mainToken(ast), "version string length {d} exceeds maximum of {d}", .{ version_text.len, max_version_len }); |
| 196 | } | 196 | } |
| 197 | p.version = std.SemanticVersion.parse(version_text) catch |err| v: { | 197 | p.version = std.SemanticVersion.parse(version_text) catch |err| v: { |
| 198 | try appendError(p, ast.nodeMainToken(field_init), "unable to parse semantic version: {s}", .{@errorName(err)}); | 198 | try appendError(p, field_init.mainToken(ast), "unable to parse semantic version: {s}", .{@errorName(err)}); |
| 199 | break :v undefined; | 199 | break :v undefined; |
| 200 | }; | 200 | }; |
| 201 | have_version = true; | 201 | have_version = true; |
| 202 | } else if (mem.eql(u8, field_name, "minimum_zig_version")) { | 202 | } else if (mem.eql(u8, field_name, "minimum_zig_version")) { |
| 203 | const version_text = try parseString(p, field_init); | 203 | const version_text = try parseString(p, field_init); |
| 204 | p.minimum_zig_version = std.SemanticVersion.parse(version_text) catch |err| v: { | 204 | p.minimum_zig_version = std.SemanticVersion.parse(version_text) catch |err| v: { |
| 205 | try appendError(p, ast.nodeMainToken(field_init), "unable to parse semantic version: {s}", .{@errorName(err)}); | 205 | try appendError(p, field_init.mainToken(ast), "unable to parse semantic version: {s}", .{@errorName(err)}); |
| 206 | break :v null; | 206 | break :v null; |
| 207 | }; | 207 | }; |
| 208 | } else { | 208 | } else { |
| ... | @@ -244,11 +244,11 @@ const Parse = struct { | ... | @@ -244,11 +244,11 @@ const Parse = struct { |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | fn parseDependencies(p: *Parse, node: Ast.Node.Index) !void { | 246 | fn parseDependencies(p: *Parse, node: Ast.Node.Index) !void { |
| 247 | const ast = p.ast; | 247 | const ast = &p.ast; |
| 248 | 248 | ||
| 249 | var buf: [2]Ast.Node.Index = undefined; | 249 | var buf: [2]Ast.Node.Index = undefined; |
| 250 | const struct_init = ast.fullStructInit(&buf, node) orelse { | 250 | const struct_init = ast.fullStructInit(&buf, node) orelse { |
| 251 | const tok = ast.nodeMainToken(node); | 251 | const tok = node.mainToken(ast); |
| 252 | return fail(p, tok, "expected dependencies expression to be a struct", .{}); | 252 | return fail(p, tok, "expected dependencies expression to be a struct", .{}); |
| 253 | }; | 253 | }; |
| 254 | 254 | ||
| ... | @@ -261,11 +261,11 @@ const Parse = struct { | ... | @@ -261,11 +261,11 @@ const Parse = struct { |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | fn parseDependency(p: *Parse, node: Ast.Node.Index) !Dependency { | 263 | fn parseDependency(p: *Parse, node: Ast.Node.Index) !Dependency { |
| 264 | const ast = p.ast; | 264 | const ast = &p.ast; |
| 265 | 265 | ||
| 266 | var buf: [2]Ast.Node.Index = undefined; | 266 | var buf: [2]Ast.Node.Index = undefined; |
| 267 | const struct_init = ast.fullStructInit(&buf, node) orelse { | 267 | const struct_init = ast.fullStructInit(&buf, node) orelse { |
| 268 | const tok = ast.nodeMainToken(node); | 268 | const tok = node.mainToken(ast); |
| 269 | return fail(p, tok, "expected dependency expression to be a struct", .{}); | 269 | return fail(p, tok, "expected dependency expression to be a struct", .{}); |
| 270 | }; | 270 | }; |
| 271 | 271 | ||
| ... | @@ -291,7 +291,7 @@ const Parse = struct { | ... | @@ -291,7 +291,7 @@ const Parse = struct { |
| 291 | // that is desirable on a per-field basis. | 291 | // that is desirable on a per-field basis. |
| 292 | if (mem.eql(u8, field_name, "url")) { | 292 | if (mem.eql(u8, field_name, "url")) { |
| 293 | if (has_location) { | 293 | if (has_location) { |
| 294 | return fail(p, ast.nodeMainToken(field_init), "dependency should specify only one of 'url' and 'path' fields.", .{}); | 294 | return fail(p, field_init.mainToken(ast), "dependency should specify only one of 'url' and 'path' fields.", .{}); |
| 295 | } | 295 | } |
| 296 | dep.location = .{ | 296 | dep.location = .{ |
| 297 | .url = parseString(p, field_init) catch |err| switch (err) { | 297 | .url = parseString(p, field_init) catch |err| switch (err) { |
| ... | @@ -300,11 +300,11 @@ const Parse = struct { | ... | @@ -300,11 +300,11 @@ const Parse = struct { |
| 300 | }, | 300 | }, |
| 301 | }; | 301 | }; |
| 302 | has_location = true; | 302 | has_location = true; |
| 303 | dep.location_tok = ast.nodeMainToken(field_init); | 303 | dep.location_tok = field_init.mainToken(ast); |
| 304 | dep.location_node = field_init; | 304 | dep.location_node = field_init; |
| 305 | } else if (mem.eql(u8, field_name, "path")) { | 305 | } else if (mem.eql(u8, field_name, "path")) { |
| 306 | if (has_location) { | 306 | if (has_location) { |
| 307 | return fail(p, ast.nodeMainToken(field_init), "dependency should specify only one of 'url' and 'path' fields.", .{}); | 307 | return fail(p, field_init.mainToken(ast), "dependency should specify only one of 'url' and 'path' fields.", .{}); |
| 308 | } | 308 | } |
| 309 | dep.location = .{ | 309 | dep.location = .{ |
| 310 | .path = parseString(p, field_init) catch |err| switch (err) { | 310 | .path = parseString(p, field_init) catch |err| switch (err) { |
| ... | @@ -313,14 +313,14 @@ const Parse = struct { | ... | @@ -313,14 +313,14 @@ const Parse = struct { |
| 313 | }, | 313 | }, |
| 314 | }; | 314 | }; |
| 315 | has_location = true; | 315 | has_location = true; |
| 316 | dep.location_tok = ast.nodeMainToken(field_init); | 316 | dep.location_tok = field_init.mainToken(ast); |
| 317 | dep.location_node = field_init; | 317 | dep.location_node = field_init; |
| 318 | } else if (mem.eql(u8, field_name, "hash")) { | 318 | } else if (mem.eql(u8, field_name, "hash")) { |
| 319 | dep.hash = parseHash(p, field_init) catch |err| switch (err) { | 319 | dep.hash = parseHash(p, field_init) catch |err| switch (err) { |
| 320 | error.ParseFailure => continue, | 320 | error.ParseFailure => continue, |
| 321 | else => |e| return e, | 321 | else => |e| return e, |
| 322 | }; | 322 | }; |
| 323 | dep.hash_tok = .fromToken(ast.nodeMainToken(field_init)); | 323 | dep.hash_tok = .fromToken(field_init.mainToken(ast)); |
| 324 | dep.hash_node = field_init.toOptional(); | 324 | dep.hash_node = field_init.toOptional(); |
| 325 | } else if (mem.eql(u8, field_name, "lazy")) { | 325 | } else if (mem.eql(u8, field_name, "lazy")) { |
| 326 | dep.lazy = parseBool(p, field_init) catch |err| switch (err) { | 326 | dep.lazy = parseBool(p, field_init) catch |err| switch (err) { |
| ... | @@ -334,18 +334,18 @@ const Parse = struct { | ... | @@ -334,18 +334,18 @@ const Parse = struct { |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | if (!has_location) { | 336 | if (!has_location) { |
| 337 | try appendError(p, ast.nodeMainToken(node), "dependency requires location field, one of 'url' or 'path'.", .{}); | 337 | try appendError(p, node.mainToken(ast), "dependency requires location field, one of 'url' or 'path'.", .{}); |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | return dep; | 340 | return dep; |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | fn parseIncludedPaths(p: *Parse, node: Ast.Node.Index) !void { | 343 | fn parseIncludedPaths(p: *Parse, node: Ast.Node.Index) !void { |
| 344 | const ast = p.ast; | 344 | const ast = &p.ast; |
| 345 | 345 | ||
| 346 | var buf: [2]Ast.Node.Index = undefined; | 346 | var buf: [2]Ast.Node.Index = undefined; |
| 347 | const array_init = ast.fullArrayInit(&buf, node) orelse { | 347 | const array_init = ast.fullArrayInit(&buf, node) orelse { |
| 348 | const tok = ast.nodeMainToken(node); | 348 | const tok = node.mainToken(ast); |
| 349 | return fail(p, tok, "expected paths expression to be a list of strings", .{}); | 349 | return fail(p, tok, "expected paths expression to be a list of strings", .{}); |
| 350 | }; | 350 | }; |
| 351 | 351 | ||
| ... | @@ -359,11 +359,11 @@ const Parse = struct { | ... | @@ -359,11 +359,11 @@ const Parse = struct { |
| 359 | } | 359 | } |
| 360 | 360 | ||
| 361 | fn parseBool(p: *Parse, node: Ast.Node.Index) !bool { | 361 | fn parseBool(p: *Parse, node: Ast.Node.Index) !bool { |
| 362 | const ast = p.ast; | 362 | const ast = &p.ast; |
| 363 | if (ast.nodeTag(node) != .identifier) { | 363 | if (node.tag(ast) != .identifier) { |
| 364 | return fail(p, ast.nodeMainToken(node), "expected identifier", .{}); | 364 | return fail(p, node.mainToken(ast), "expected identifier", .{}); |
| 365 | } | 365 | } |
| 366 | const ident_token = ast.nodeMainToken(node); | 366 | const ident_token = node.mainToken(ast); |
| 367 | const token_bytes = ast.tokenSlice(ident_token); | 367 | const token_bytes = ast.tokenSlice(ident_token); |
| 368 | if (mem.eql(u8, token_bytes, "true")) { | 368 | if (mem.eql(u8, token_bytes, "true")) { |
| 369 | return true; | 369 | return true; |
| ... | @@ -375,9 +375,9 @@ const Parse = struct { | ... | @@ -375,9 +375,9 @@ const Parse = struct { |
| 375 | } | 375 | } |
| 376 | 376 | ||
| 377 | fn parseFingerprint(p: *Parse, node: Ast.Node.Index) !Package.Fingerprint { | 377 | fn parseFingerprint(p: *Parse, node: Ast.Node.Index) !Package.Fingerprint { |
| 378 | const ast = p.ast; | 378 | const ast = &p.ast; |
| 379 | const main_token = ast.nodeMainToken(node); | 379 | const main_token = node.mainToken(ast); |
| 380 | if (ast.nodeTag(node) != .number_literal) { | 380 | if (node.tag(ast) != .number_literal) { |
| 381 | return fail(p, main_token, "expected integer literal", .{}); | 381 | return fail(p, main_token, "expected integer literal", .{}); |
| 382 | } | 382 | } |
| 383 | const token_bytes = ast.tokenSlice(main_token); | 383 | const token_bytes = ast.tokenSlice(main_token); |
| ... | @@ -392,10 +392,10 @@ const Parse = struct { | ... | @@ -392,10 +392,10 @@ const Parse = struct { |
| 392 | } | 392 | } |
| 393 | 393 | ||
| 394 | fn parseName(p: *Parse, node: Ast.Node.Index) ![]const u8 { | 394 | fn parseName(p: *Parse, node: Ast.Node.Index) ![]const u8 { |
| 395 | const ast = p.ast; | 395 | const ast = &p.ast; |
| 396 | const main_token = ast.nodeMainToken(node); | 396 | const main_token = node.mainToken(ast); |
| 397 | 397 | ||
| 398 | if (p.allow_name_string and ast.nodeTag(node) == .string_literal) { | 398 | if (p.allow_name_string and node.tag(ast) == .string_literal) { |
| 399 | const name = try parseString(p, node); | 399 | const name = try parseString(p, node); |
| 400 | if (!std.zig.isValidId(name)) | 400 | if (!std.zig.isValidId(name)) |
| 401 | return fail(p, main_token, "name must be a valid bare zig identifier (hint: switch from string to enum literal)", .{}); | 401 | return fail(p, main_token, "name must be a valid bare zig identifier (hint: switch from string to enum literal)", .{}); |
| ... | @@ -408,7 +408,7 @@ const Parse = struct { | ... | @@ -408,7 +408,7 @@ const Parse = struct { |
| 408 | return name; | 408 | return name; |
| 409 | } | 409 | } |
| 410 | 410 | ||
| 411 | if (ast.nodeTag(node) != .enum_literal) | 411 | if (node.tag(ast) != .enum_literal) |
| 412 | return fail(p, main_token, "expected enum literal", .{}); | 412 | return fail(p, main_token, "expected enum literal", .{}); |
| 413 | 413 | ||
| 414 | const ident_name = ast.tokenSlice(main_token); | 414 | const ident_name = ast.tokenSlice(main_token); |
| ... | @@ -424,11 +424,11 @@ const Parse = struct { | ... | @@ -424,11 +424,11 @@ const Parse = struct { |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | fn parseString(p: *Parse, node: Ast.Node.Index) ![]const u8 { | 426 | fn parseString(p: *Parse, node: Ast.Node.Index) ![]const u8 { |
| 427 | const ast = p.ast; | 427 | const ast = &p.ast; |
| 428 | if (ast.nodeTag(node) != .string_literal) { | 428 | if (node.tag(ast) != .string_literal) { |
| 429 | return fail(p, ast.nodeMainToken(node), "expected string literal", .{}); | 429 | return fail(p, node.mainToken(ast), "expected string literal", .{}); |
| 430 | } | 430 | } |
| 431 | const str_lit_token = ast.nodeMainToken(node); | 431 | const str_lit_token = node.mainToken(ast); |
| 432 | const token_bytes = ast.tokenSlice(str_lit_token); | 432 | const token_bytes = ast.tokenSlice(str_lit_token); |
| 433 | p.buf.clearRetainingCapacity(); | 433 | p.buf.clearRetainingCapacity(); |
| 434 | try parseStrLit(p, str_lit_token, &p.buf, token_bytes, 0); | 434 | try parseStrLit(p, str_lit_token, &p.buf, token_bytes, 0); |
| ... | @@ -437,8 +437,8 @@ const Parse = struct { | ... | @@ -437,8 +437,8 @@ const Parse = struct { |
| 437 | } | 437 | } |
| 438 | 438 | ||
| 439 | fn parseHash(p: *Parse, node: Ast.Node.Index) ![]const u8 { | 439 | fn parseHash(p: *Parse, node: Ast.Node.Index) ![]const u8 { |
| 440 | const ast = p.ast; | 440 | const ast = &p.ast; |
| 441 | const tok = ast.nodeMainToken(node); | 441 | const tok = node.mainToken(ast); |
| 442 | const h = try parseString(p, node); | 442 | const h = try parseString(p, node); |
| 443 | 443 | ||
| 444 | if (h.len > Package.Hash.max_len) { | 444 | if (h.len > Package.Hash.max_len) { |
| ... | @@ -450,7 +450,7 @@ const Parse = struct { | ... | @@ -450,7 +450,7 @@ const Parse = struct { |
| 450 | 450 | ||
| 451 | /// TODO: try to DRY this with AstGen.identifierTokenString | 451 | /// TODO: try to DRY this with AstGen.identifierTokenString |
| 452 | fn identifierTokenString(p: *Parse, token: Ast.TokenIndex) InnerError![]const u8 { | 452 | fn identifierTokenString(p: *Parse, token: Ast.TokenIndex) InnerError![]const u8 { |
| 453 | const ast = p.ast; | 453 | const ast = &p.ast; |
| 454 | assert(ast.tokenTag(token) == .identifier); | 454 | assert(ast.tokenTag(token) == .identifier); |
| 455 | const ident_name = ast.tokenSlice(token); | 455 | const ident_name = ast.tokenSlice(token); |
| 456 | if (!mem.startsWith(u8, ident_name, "@")) { | 456 | if (!mem.startsWith(u8, ident_name, "@")) { |
src/Sema.zig+2-2| ... | @@ -17298,7 +17298,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17298,7 +17298,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17298 | break :name null; | 17298 | break :name null; |
| 17299 | }; | 17299 | }; |
| 17300 | const node = src_node.toAbsolute(src_base_node); | 17300 | const node = src_node.toAbsolute(src_base_node); |
| 17301 | const token = tree.nodeMainToken(node); | 17301 | const token = node.mainToken(tree); |
| 17302 | break :name tree.tokenSlice(token); | 17302 | break :name tree.tokenSlice(token); |
| 17303 | }; | 17303 | }; |
| 17304 | 17304 | ||
| ... | @@ -17326,7 +17326,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17326,7 +17326,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17326 | break :name null; | 17326 | break :name null; |
| 17327 | }; | 17327 | }; |
| 17328 | const node = src_node.toAbsolute(src_base_node); | 17328 | const node = src_node.toAbsolute(src_base_node); |
| 17329 | const token = tree.nodeMainToken(node); | 17329 | const token = node.mainToken(tree); |
| 17330 | break :name tree.tokenSlice(token); | 17330 | break :name tree.tokenSlice(token); |
| 17331 | }; | 17331 | }; |
| 17332 | 17332 |
src/Zcu.zig+51-51| ... | @@ -1143,7 +1143,7 @@ pub const SrcLoc = struct { | ... | @@ -1143,7 +1143,7 @@ pub const SrcLoc = struct { |
| 1143 | .node_offset_main_token => |node_off| { | 1143 | .node_offset_main_token => |node_off| { |
| 1144 | const tree = try src_loc.file_scope.getTree(gpa); | 1144 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1145 | const node = node_off.toAbsolute(src_loc.base_node); | 1145 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1146 | const main_token = tree.nodeMainToken(node); | 1146 | const main_token = node.mainToken(tree); |
| 1147 | return tree.tokensToSpan(main_token, main_token, main_token); | 1147 | return tree.tokensToSpan(main_token, main_token, main_token); |
| 1148 | }, | 1148 | }, |
| 1149 | .node_offset_bin_op => |node_off| { | 1149 | .node_offset_bin_op => |node_off| { |
| ... | @@ -1157,20 +1157,20 @@ pub const SrcLoc = struct { | ... | @@ -1157,20 +1157,20 @@ pub const SrcLoc = struct { |
| 1157 | return tree.tokensToSpan( | 1157 | return tree.tokensToSpan( |
| 1158 | tree.firstToken(node) - 3, | 1158 | tree.firstToken(node) - 3, |
| 1159 | tree.lastToken(node), | 1159 | tree.lastToken(node), |
| 1160 | tree.nodeMainToken(node) - 2, | 1160 | node.mainToken(tree) - 2, |
| 1161 | ); | 1161 | ); |
| 1162 | }, | 1162 | }, |
| 1163 | .node_offset_var_decl_ty => |node_off| { | 1163 | .node_offset_var_decl_ty => |node_off| { |
| 1164 | const tree = try src_loc.file_scope.getTree(gpa); | 1164 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1165 | const node = node_off.toAbsolute(src_loc.base_node); | 1165 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1166 | const full = switch (tree.nodeTag(node)) { | 1166 | const full = switch (node.tag(tree)) { |
| 1167 | .global_var_decl, | 1167 | .global_var_decl, |
| 1168 | .local_var_decl, | 1168 | .local_var_decl, |
| 1169 | .simple_var_decl, | 1169 | .simple_var_decl, |
| 1170 | .aligned_var_decl, | 1170 | .aligned_var_decl, |
| 1171 | => tree.fullVarDecl(node).?, | 1171 | => tree.fullVarDecl(node).?, |
| 1172 | .@"usingnamespace" => { | 1172 | .@"usingnamespace" => { |
| 1173 | return tree.nodeToSpan(tree.nodeData(node).node); | 1173 | return tree.nodeToSpan(node.data(tree).node); |
| 1174 | }, | 1174 | }, |
| 1175 | else => unreachable, | 1175 | else => unreachable, |
| 1176 | }; | 1176 | }; |
| ... | @@ -1221,7 +1221,7 @@ pub const SrcLoc = struct { | ... | @@ -1221,7 +1221,7 @@ pub const SrcLoc = struct { |
| 1221 | .node_offset_var_decl_init => |node_off| { | 1221 | .node_offset_var_decl_init => |node_off| { |
| 1222 | const tree = try src_loc.file_scope.getTree(gpa); | 1222 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1223 | const node = node_off.toAbsolute(src_loc.base_node); | 1223 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1224 | const init_node = switch (tree.nodeTag(node)) { | 1224 | const init_node = switch (node.tag(tree)) { |
| 1225 | .global_var_decl, | 1225 | .global_var_decl, |
| 1226 | .local_var_decl, | 1226 | .local_var_decl, |
| 1227 | .aligned_var_decl, | 1227 | .aligned_var_decl, |
| ... | @@ -1244,16 +1244,16 @@ pub const SrcLoc = struct { | ... | @@ -1244,16 +1244,16 @@ pub const SrcLoc = struct { |
| 1244 | 1244 | ||
| 1245 | var node = node_off.toAbsolute(src_loc.base_node); | 1245 | var node = node_off.toAbsolute(src_loc.base_node); |
| 1246 | while (true) { | 1246 | while (true) { |
| 1247 | switch (tree.nodeTag(node)) { | 1247 | switch (node.tag(tree)) { |
| 1248 | .builtin_call_two, .builtin_call_two_comma => {}, | 1248 | .builtin_call_two, .builtin_call_two_comma => {}, |
| 1249 | else => break, | 1249 | else => break, |
| 1250 | } | 1250 | } |
| 1251 | 1251 | ||
| 1252 | const first_arg, const second_arg = tree.nodeData(node).opt_node_and_opt_node; | 1252 | const first_arg, const second_arg = node.data(tree).opt_node_and_opt_node; |
| 1253 | if (first_arg == .none) break; // 0 args | 1253 | if (first_arg == .none) break; // 0 args |
| 1254 | if (second_arg != .none) break; // 2 args | 1254 | if (second_arg != .none) break; // 2 args |
| 1255 | 1255 | ||
| 1256 | const builtin_token = tree.nodeMainToken(node); | 1256 | const builtin_token = node.mainToken(tree); |
| 1257 | const builtin_name = tree.tokenSlice(builtin_token); | 1257 | const builtin_name = tree.tokenSlice(builtin_token); |
| 1258 | const info = BuiltinFn.list.get(builtin_name) orelse break; | 1258 | const info = BuiltinFn.list.get(builtin_name) orelse break; |
| 1259 | 1259 | ||
| ... | @@ -1275,7 +1275,7 @@ pub const SrcLoc = struct { | ... | @@ -1275,7 +1275,7 @@ pub const SrcLoc = struct { |
| 1275 | .node_offset_array_access_index => |node_off| { | 1275 | .node_offset_array_access_index => |node_off| { |
| 1276 | const tree = try src_loc.file_scope.getTree(gpa); | 1276 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1277 | const node = node_off.toAbsolute(src_loc.base_node); | 1277 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1278 | return tree.nodeToSpan(tree.nodeData(node).node_and_node[1]); | 1278 | return tree.nodeToSpan(node.data(tree).node_and_node[1]); |
| 1279 | }, | 1279 | }, |
| 1280 | .node_offset_slice_ptr, | 1280 | .node_offset_slice_ptr, |
| 1281 | .node_offset_slice_start, | 1281 | .node_offset_slice_start, |
| ... | @@ -1305,8 +1305,8 @@ pub const SrcLoc = struct { | ... | @@ -1305,8 +1305,8 @@ pub const SrcLoc = struct { |
| 1305 | const tree = try src_loc.file_scope.getTree(gpa); | 1305 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1306 | const node = node_off.toAbsolute(src_loc.base_node); | 1306 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1307 | var buf: [1]Ast.Node.Index = undefined; | 1307 | var buf: [1]Ast.Node.Index = undefined; |
| 1308 | const tok_index = switch (tree.nodeTag(node)) { | 1308 | const tok_index = switch (node.tag(tree)) { |
| 1309 | .field_access => tree.nodeData(node).node_and_token[1], | 1309 | .field_access => node.data(tree).node_and_token[1], |
| 1310 | .call_one, | 1310 | .call_one, |
| 1311 | .call_one_comma, | 1311 | .call_one_comma, |
| 1312 | .async_call_one, | 1312 | .async_call_one, |
| ... | @@ -1349,13 +1349,13 @@ pub const SrcLoc = struct { | ... | @@ -1349,13 +1349,13 @@ pub const SrcLoc = struct { |
| 1349 | const node = node_off.toAbsolute(src_loc.base_node); | 1349 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1350 | const full = tree.fullAsm(node).?; | 1350 | const full = tree.fullAsm(node).?; |
| 1351 | const asm_output = full.outputs[0]; | 1351 | const asm_output = full.outputs[0]; |
| 1352 | return tree.nodeToSpan(tree.nodeData(asm_output).opt_node_and_token[0].unwrap().?); | 1352 | return tree.nodeToSpan(asm_output.data(tree).opt_node_and_token[0].unwrap().?); |
| 1353 | }, | 1353 | }, |
| 1354 | 1354 | ||
| 1355 | .node_offset_if_cond => |node_off| { | 1355 | .node_offset_if_cond => |node_off| { |
| 1356 | const tree = try src_loc.file_scope.getTree(gpa); | 1356 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1357 | const node = node_off.toAbsolute(src_loc.base_node); | 1357 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1358 | const src_node = switch (tree.nodeTag(node)) { | 1358 | const src_node = switch (node.tag(tree)) { |
| 1359 | .if_simple, | 1359 | .if_simple, |
| 1360 | .@"if", | 1360 | .@"if", |
| 1361 | => tree.fullIf(node).?.ast.cond_expr, | 1361 | => tree.fullIf(node).?.ast.cond_expr, |
| ... | @@ -1433,9 +1433,9 @@ pub const SrcLoc = struct { | ... | @@ -1433,9 +1433,9 @@ pub const SrcLoc = struct { |
| 1433 | const node = call_arg.call_node_offset.toAbsolute(src_loc.base_node); | 1433 | const node = call_arg.call_node_offset.toAbsolute(src_loc.base_node); |
| 1434 | var buf: [2]Ast.Node.Index = undefined; | 1434 | var buf: [2]Ast.Node.Index = undefined; |
| 1435 | const call_full = tree.fullCall(buf[0..1], node) orelse { | 1435 | const call_full = tree.fullCall(buf[0..1], node) orelse { |
| 1436 | assert(tree.nodeTag(node) == .builtin_call); | 1436 | assert(node.tag(tree) == .builtin_call); |
| 1437 | const call_args_node: Ast.Node.Index = @enumFromInt(tree.extra_data[@intFromEnum(tree.nodeData(node).extra_range.end) - 1]); | 1437 | const call_args_node: Ast.Node.Index = @enumFromInt(tree.extra_data[@intFromEnum(node.data(tree).extra_range.end) - 1]); |
| 1438 | switch (tree.nodeTag(call_args_node)) { | 1438 | switch (call_args_node.tag(tree)) { |
| 1439 | .array_init_one, | 1439 | .array_init_one, |
| 1440 | .array_init_one_comma, | 1440 | .array_init_one_comma, |
| 1441 | .array_init_dot_two, | 1441 | .array_init_dot_two, |
| ... | @@ -1496,23 +1496,23 @@ pub const SrcLoc = struct { | ... | @@ -1496,23 +1496,23 @@ pub const SrcLoc = struct { |
| 1496 | .node_offset_bin_lhs => |node_off| { | 1496 | .node_offset_bin_lhs => |node_off| { |
| 1497 | const tree = try src_loc.file_scope.getTree(gpa); | 1497 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1498 | const node = node_off.toAbsolute(src_loc.base_node); | 1498 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1499 | return tree.nodeToSpan(tree.nodeData(node).node_and_node[0]); | 1499 | return tree.nodeToSpan(node.data(tree).node_and_node[0]); |
| 1500 | }, | 1500 | }, |
| 1501 | .node_offset_bin_rhs => |node_off| { | 1501 | .node_offset_bin_rhs => |node_off| { |
| 1502 | const tree = try src_loc.file_scope.getTree(gpa); | 1502 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1503 | const node = node_off.toAbsolute(src_loc.base_node); | 1503 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1504 | return tree.nodeToSpan(tree.nodeData(node).node_and_node[1]); | 1504 | return tree.nodeToSpan(node.data(tree).node_and_node[1]); |
| 1505 | }, | 1505 | }, |
| 1506 | .array_cat_lhs, .array_cat_rhs => |cat| { | 1506 | .array_cat_lhs, .array_cat_rhs => |cat| { |
| 1507 | const tree = try src_loc.file_scope.getTree(gpa); | 1507 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1508 | const node = cat.array_cat_offset.toAbsolute(src_loc.base_node); | 1508 | const node = cat.array_cat_offset.toAbsolute(src_loc.base_node); |
| 1509 | const arr_node = if (src_loc.lazy == .array_cat_lhs) | 1509 | const arr_node = if (src_loc.lazy == .array_cat_lhs) |
| 1510 | tree.nodeData(node).node_and_node[0] | 1510 | node.data(tree).node_and_node[0] |
| 1511 | else | 1511 | else |
| 1512 | tree.nodeData(node).node_and_node[1]; | 1512 | node.data(tree).node_and_node[1]; |
| 1513 | 1513 | ||
| 1514 | var buf: [2]Ast.Node.Index = undefined; | 1514 | var buf: [2]Ast.Node.Index = undefined; |
| 1515 | switch (tree.nodeTag(arr_node)) { | 1515 | switch (arr_node.tag(tree)) { |
| 1516 | .array_init_one, | 1516 | .array_init_one, |
| 1517 | .array_init_one_comma, | 1517 | .array_init_one_comma, |
| 1518 | .array_init_dot_two, | 1518 | .array_init_dot_two, |
| ... | @@ -1532,27 +1532,27 @@ pub const SrcLoc = struct { | ... | @@ -1532,27 +1532,27 @@ pub const SrcLoc = struct { |
| 1532 | .node_offset_try_operand => |node_off| { | 1532 | .node_offset_try_operand => |node_off| { |
| 1533 | const tree = try src_loc.file_scope.getTree(gpa); | 1533 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1534 | const node = node_off.toAbsolute(src_loc.base_node); | 1534 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1535 | return tree.nodeToSpan(tree.nodeData(node).node); | 1535 | return tree.nodeToSpan(node.data(tree).node); |
| 1536 | }, | 1536 | }, |
| 1537 | 1537 | ||
| 1538 | .node_offset_switch_operand => |node_off| { | 1538 | .node_offset_switch_operand => |node_off| { |
| 1539 | const tree = try src_loc.file_scope.getTree(gpa); | 1539 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1540 | const node = node_off.toAbsolute(src_loc.base_node); | 1540 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1541 | const condition, _ = tree.nodeData(node).node_and_extra; | 1541 | const condition, _ = node.data(tree).node_and_extra; |
| 1542 | return tree.nodeToSpan(condition); | 1542 | return tree.nodeToSpan(condition); |
| 1543 | }, | 1543 | }, |
| 1544 | 1544 | ||
| 1545 | .node_offset_switch_special_prong => |node_off| { | 1545 | .node_offset_switch_special_prong => |node_off| { |
| 1546 | const tree = try src_loc.file_scope.getTree(gpa); | 1546 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1547 | const switch_node = node_off.toAbsolute(src_loc.base_node); | 1547 | const switch_node = node_off.toAbsolute(src_loc.base_node); |
| 1548 | _, const extra_index = tree.nodeData(switch_node).node_and_extra; | 1548 | _, const extra_index = switch_node.data(tree).node_and_extra; |
| 1549 | const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index); | 1549 | const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index); |
| 1550 | for (case_nodes) |case_node| { | 1550 | for (case_nodes) |case_node| { |
| 1551 | const case = tree.fullSwitchCase(case_node).?; | 1551 | const case = tree.fullSwitchCase(case_node).?; |
| 1552 | const is_special = (case.ast.values.len == 0) or | 1552 | const is_special = (case.ast.values.len == 0) or |
| 1553 | (case.ast.values.len == 1 and | 1553 | (case.ast.values.len == 1 and |
| 1554 | tree.nodeTag(case.ast.values[0]) == .identifier and | 1554 | case.ast.values[0].tag(tree) == .identifier and |
| 1555 | mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(case.ast.values[0])), "_")); | 1555 | mem.eql(u8, tree.tokenSlice(case.ast.values[0].mainToken(tree)), "_")); |
| 1556 | if (!is_special) continue; | 1556 | if (!is_special) continue; |
| 1557 | 1557 | ||
| 1558 | return tree.nodeToSpan(case_node); | 1558 | return tree.nodeToSpan(case_node); |
| ... | @@ -1562,18 +1562,18 @@ pub const SrcLoc = struct { | ... | @@ -1562,18 +1562,18 @@ pub const SrcLoc = struct { |
| 1562 | .node_offset_switch_range => |node_off| { | 1562 | .node_offset_switch_range => |node_off| { |
| 1563 | const tree = try src_loc.file_scope.getTree(gpa); | 1563 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1564 | const switch_node = node_off.toAbsolute(src_loc.base_node); | 1564 | const switch_node = node_off.toAbsolute(src_loc.base_node); |
| 1565 | _, const extra_index = tree.nodeData(switch_node).node_and_extra; | 1565 | _, const extra_index = switch_node.data(tree).node_and_extra; |
| 1566 | const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index); | 1566 | const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index); |
| 1567 | for (case_nodes) |case_node| { | 1567 | for (case_nodes) |case_node| { |
| 1568 | const case = tree.fullSwitchCase(case_node).?; | 1568 | const case = tree.fullSwitchCase(case_node).?; |
| 1569 | const is_special = (case.ast.values.len == 0) or | 1569 | const is_special = (case.ast.values.len == 0) or |
| 1570 | (case.ast.values.len == 1 and | 1570 | (case.ast.values.len == 1 and |
| 1571 | tree.nodeTag(case.ast.values[0]) == .identifier and | 1571 | case.ast.values[0].tag(tree) == .identifier and |
| 1572 | mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(case.ast.values[0])), "_")); | 1572 | mem.eql(u8, tree.tokenSlice(case.ast.values[0].mainToken(tree)), "_")); |
| 1573 | if (is_special) continue; | 1573 | if (is_special) continue; |
| 1574 | 1574 | ||
| 1575 | for (case.ast.values) |item_node| { | 1575 | for (case.ast.values) |item_node| { |
| 1576 | if (tree.nodeTag(item_node) == .switch_range) { | 1576 | if (item_node.tag(tree) == .switch_range) { |
| 1577 | return tree.nodeToSpan(item_node); | 1577 | return tree.nodeToSpan(item_node); |
| 1578 | } | 1578 | } |
| 1579 | } | 1579 | } |
| ... | @@ -1632,7 +1632,7 @@ pub const SrcLoc = struct { | ... | @@ -1632,7 +1632,7 @@ pub const SrcLoc = struct { |
| 1632 | }, | 1632 | }, |
| 1633 | .token_offset_param => |token_off| { | 1633 | .token_offset_param => |token_off| { |
| 1634 | const tree = try src_loc.file_scope.getTree(gpa); | 1634 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1635 | const main_token = tree.nodeMainToken(src_loc.base_node); | 1635 | const main_token = src_loc.base_node.mainToken(tree); |
| 1636 | const tok_index = token_off.toAbsolute(main_token); | 1636 | const tok_index = token_off.toAbsolute(main_token); |
| 1637 | 1637 | ||
| 1638 | var first_tok = tok_index; | 1638 | var first_tok = tok_index; |
| ... | @@ -1650,7 +1650,7 @@ pub const SrcLoc = struct { | ... | @@ -1650,7 +1650,7 @@ pub const SrcLoc = struct { |
| 1650 | .node_offset_anyframe_type => |node_off| { | 1650 | .node_offset_anyframe_type => |node_off| { |
| 1651 | const tree = try src_loc.file_scope.getTree(gpa); | 1651 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1652 | const parent_node = node_off.toAbsolute(src_loc.base_node); | 1652 | const parent_node = node_off.toAbsolute(src_loc.base_node); |
| 1653 | _, const child_type = tree.nodeData(parent_node).token_and_node; | 1653 | _, const child_type = parent_node.data(tree).token_and_node; |
| 1654 | return tree.nodeToSpan(child_type); | 1654 | return tree.nodeToSpan(child_type); |
| 1655 | }, | 1655 | }, |
| 1656 | 1656 | ||
| ... | @@ -1689,7 +1689,7 @@ pub const SrcLoc = struct { | ... | @@ -1689,7 +1689,7 @@ pub const SrcLoc = struct { |
| 1689 | .node_offset_un_op => |node_off| { | 1689 | .node_offset_un_op => |node_off| { |
| 1690 | const tree = try src_loc.file_scope.getTree(gpa); | 1690 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1691 | const node = node_off.toAbsolute(src_loc.base_node); | 1691 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1692 | return tree.nodeToSpan(tree.nodeData(node).node); | 1692 | return tree.nodeToSpan(node.data(tree).node); |
| 1693 | }, | 1693 | }, |
| 1694 | .node_offset_ptr_elem => |node_off| { | 1694 | .node_offset_ptr_elem => |node_off| { |
| 1695 | const tree = try src_loc.file_scope.getTree(gpa); | 1695 | const tree = try src_loc.file_scope.getTree(gpa); |
| ... | @@ -1737,7 +1737,7 @@ pub const SrcLoc = struct { | ... | @@ -1737,7 +1737,7 @@ pub const SrcLoc = struct { |
| 1737 | const tree = try src_loc.file_scope.getTree(gpa); | 1737 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1738 | const parent_node = node_off.toAbsolute(src_loc.base_node); | 1738 | const parent_node = node_off.toAbsolute(src_loc.base_node); |
| 1739 | 1739 | ||
| 1740 | switch (tree.nodeTag(parent_node)) { | 1740 | switch (parent_node.tag(tree)) { |
| 1741 | .container_decl_arg, .container_decl_arg_trailing => { | 1741 | .container_decl_arg, .container_decl_arg_trailing => { |
| 1742 | const full = tree.containerDeclArg(parent_node); | 1742 | const full = tree.containerDeclArg(parent_node); |
| 1743 | const arg_node = full.ast.arg.unwrap().?; | 1743 | const arg_node = full.ast.arg.unwrap().?; |
| ... | @@ -1750,7 +1750,7 @@ pub const SrcLoc = struct { | ... | @@ -1750,7 +1750,7 @@ pub const SrcLoc = struct { |
| 1750 | return tree.tokensToSpan( | 1750 | return tree.tokensToSpan( |
| 1751 | tree.firstToken(arg_node) - 2, | 1751 | tree.firstToken(arg_node) - 2, |
| 1752 | tree.lastToken(arg_node) + 1, | 1752 | tree.lastToken(arg_node) + 1, |
| 1753 | tree.nodeMainToken(arg_node), | 1753 | arg_node.mainToken(tree), |
| 1754 | ); | 1754 | ); |
| 1755 | }, | 1755 | }, |
| 1756 | else => unreachable, | 1756 | else => unreachable, |
| ... | @@ -1760,7 +1760,7 @@ pub const SrcLoc = struct { | ... | @@ -1760,7 +1760,7 @@ pub const SrcLoc = struct { |
| 1760 | const tree = try src_loc.file_scope.getTree(gpa); | 1760 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1761 | const parent_node = node_off.toAbsolute(src_loc.base_node); | 1761 | const parent_node = node_off.toAbsolute(src_loc.base_node); |
| 1762 | 1762 | ||
| 1763 | const full: Ast.full.ContainerField = switch (tree.nodeTag(parent_node)) { | 1763 | const full: Ast.full.ContainerField = switch (parent_node.tag(tree)) { |
| 1764 | .container_field => tree.containerField(parent_node), | 1764 | .container_field => tree.containerField(parent_node), |
| 1765 | .container_field_init => tree.containerFieldInit(parent_node), | 1765 | .container_field_init => tree.containerFieldInit(parent_node), |
| 1766 | else => unreachable, | 1766 | else => unreachable, |
| ... | @@ -1782,7 +1782,7 @@ pub const SrcLoc = struct { | ... | @@ -1782,7 +1782,7 @@ pub const SrcLoc = struct { |
| 1782 | const tree = try src_loc.file_scope.getTree(gpa); | 1782 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1783 | const node = node_off.toAbsolute(src_loc.base_node); | 1783 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1784 | 1784 | ||
| 1785 | switch (tree.nodeTag(node)) { | 1785 | switch (node.tag(tree)) { |
| 1786 | .assign, | 1786 | .assign, |
| 1787 | .assign_mul, | 1787 | .assign_mul, |
| 1788 | .assign_div, | 1788 | .assign_div, |
| ... | @@ -1801,7 +1801,7 @@ pub const SrcLoc = struct { | ... | @@ -1801,7 +1801,7 @@ pub const SrcLoc = struct { |
| 1801 | .assign_mul_sat, | 1801 | .assign_mul_sat, |
| 1802 | .assign_add_sat, | 1802 | .assign_add_sat, |
| 1803 | .assign_sub_sat, | 1803 | .assign_sub_sat, |
| 1804 | => return tree.nodeToSpan(tree.nodeData(node).node_and_node[0]), | 1804 | => return tree.nodeToSpan(node.data(tree).node_and_node[0]), |
| 1805 | else => return tree.nodeToSpan(node), | 1805 | else => return tree.nodeToSpan(node), |
| 1806 | } | 1806 | } |
| 1807 | }, | 1807 | }, |
| ... | @@ -1809,7 +1809,7 @@ pub const SrcLoc = struct { | ... | @@ -1809,7 +1809,7 @@ pub const SrcLoc = struct { |
| 1809 | const tree = try src_loc.file_scope.getTree(gpa); | 1809 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1810 | const node = node_off.toAbsolute(src_loc.base_node); | 1810 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1811 | 1811 | ||
| 1812 | switch (tree.nodeTag(node)) { | 1812 | switch (node.tag(tree)) { |
| 1813 | .assign, | 1813 | .assign, |
| 1814 | .assign_mul, | 1814 | .assign_mul, |
| 1815 | .assign_div, | 1815 | .assign_div, |
| ... | @@ -1828,15 +1828,15 @@ pub const SrcLoc = struct { | ... | @@ -1828,15 +1828,15 @@ pub const SrcLoc = struct { |
| 1828 | .assign_mul_sat, | 1828 | .assign_mul_sat, |
| 1829 | .assign_add_sat, | 1829 | .assign_add_sat, |
| 1830 | .assign_sub_sat, | 1830 | .assign_sub_sat, |
| 1831 | => return tree.nodeToSpan(tree.nodeData(node).node_and_node[1]), | 1831 | => return tree.nodeToSpan(node.data(tree).node_and_node[1]), |
| 1832 | else => return tree.nodeToSpan(node), | 1832 | else => return tree.nodeToSpan(node), |
| 1833 | } | 1833 | } |
| 1834 | }, | 1834 | }, |
| 1835 | .node_offset_return_operand => |node_off| { | 1835 | .node_offset_return_operand => |node_off| { |
| 1836 | const tree = try src_loc.file_scope.getTree(gpa); | 1836 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1837 | const node = node_off.toAbsolute(src_loc.base_node); | 1837 | const node = node_off.toAbsolute(src_loc.base_node); |
| 1838 | if (tree.nodeTag(node) == .@"return") { | 1838 | if (node.tag(tree) == .@"return") { |
| 1839 | if (tree.nodeData(node).opt_node.unwrap()) |lhs| { | 1839 | if (node.data(tree).opt_node.unwrap()) |lhs| { |
| 1840 | return tree.nodeToSpan(lhs); | 1840 | return tree.nodeToSpan(lhs); |
| 1841 | } | 1841 | } |
| 1842 | } | 1842 | } |
| ... | @@ -1900,7 +1900,7 @@ pub const SrcLoc = struct { | ... | @@ -1900,7 +1900,7 @@ pub const SrcLoc = struct { |
| 1900 | return tree.tokensToSpan( | 1900 | return tree.tokensToSpan( |
| 1901 | tree.firstToken(field_node) - 3, | 1901 | tree.firstToken(field_node) - 3, |
| 1902 | tree.lastToken(field_node), | 1902 | tree.lastToken(field_node), |
| 1903 | tree.nodeMainToken(field_node) - 2, | 1903 | field_node.mainToken(tree) - 2, |
| 1904 | ); | 1904 | ); |
| 1905 | } else unreachable; | 1905 | } else unreachable; |
| 1906 | }, | 1906 | }, |
| ... | @@ -1944,7 +1944,7 @@ pub const SrcLoc = struct { | ... | @@ -1944,7 +1944,7 @@ pub const SrcLoc = struct { |
| 1944 | return tree.tokensToSpan( | 1944 | return tree.tokensToSpan( |
| 1945 | name_token - 1, | 1945 | name_token - 1, |
| 1946 | tree.lastToken(field_node), | 1946 | tree.lastToken(field_node), |
| 1947 | tree.nodeMainToken(field_node) - 2, | 1947 | field_node.mainToken(tree) - 2, |
| 1948 | ); | 1948 | ); |
| 1949 | } | 1949 | } |
| 1950 | } | 1950 | } |
| ... | @@ -1969,7 +1969,7 @@ pub const SrcLoc = struct { | ... | @@ -1969,7 +1969,7 @@ pub const SrcLoc = struct { |
| 1969 | 1969 | ||
| 1970 | const tree = try src_loc.file_scope.getTree(gpa); | 1970 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1971 | const switch_node = switch_node_offset.toAbsolute(src_loc.base_node); | 1971 | const switch_node = switch_node_offset.toAbsolute(src_loc.base_node); |
| 1972 | _, const extra_index = tree.nodeData(switch_node).node_and_extra; | 1972 | _, const extra_index = switch_node.data(tree).node_and_extra; |
| 1973 | const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index); | 1973 | const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index); |
| 1974 | 1974 | ||
| 1975 | var multi_i: u32 = 0; | 1975 | var multi_i: u32 = 0; |
| ... | @@ -1978,8 +1978,8 @@ pub const SrcLoc = struct { | ... | @@ -1978,8 +1978,8 @@ pub const SrcLoc = struct { |
| 1978 | const case = tree.fullSwitchCase(case_node).?; | 1978 | const case = tree.fullSwitchCase(case_node).?; |
| 1979 | const is_special = special: { | 1979 | const is_special = special: { |
| 1980 | if (case.ast.values.len == 0) break :special true; | 1980 | if (case.ast.values.len == 0) break :special true; |
| 1981 | if (case.ast.values.len == 1 and tree.nodeTag(case.ast.values[0]) == .identifier) { | 1981 | if (case.ast.values.len == 1 and case.ast.values[0].tag(tree) == .identifier) { |
| 1982 | break :special mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(case.ast.values[0])), "_"); | 1982 | break :special mem.eql(u8, tree.tokenSlice(case.ast.values[0].mainToken(tree)), "_"); |
| 1983 | } | 1983 | } |
| 1984 | break :special false; | 1984 | break :special false; |
| 1985 | }; | 1985 | }; |
| ... | @@ -1991,7 +1991,7 @@ pub const SrcLoc = struct { | ... | @@ -1991,7 +1991,7 @@ pub const SrcLoc = struct { |
| 1991 | } | 1991 | } |
| 1992 | 1992 | ||
| 1993 | const is_multi = case.ast.values.len != 1 or | 1993 | const is_multi = case.ast.values.len != 1 or |
| 1994 | tree.nodeTag(case.ast.values[0]) == .switch_range; | 1994 | case.ast.values[0].tag(tree) == .switch_range; |
| 1995 | 1995 | ||
| 1996 | switch (want_case_idx.kind) { | 1996 | switch (want_case_idx.kind) { |
| 1997 | .scalar => if (!is_multi and want_case_idx.index == scalar_i) break case, | 1997 | .scalar => if (!is_multi and want_case_idx.index == scalar_i) break case, |
| ... | @@ -2034,7 +2034,7 @@ pub const SrcLoc = struct { | ... | @@ -2034,7 +2034,7 @@ pub const SrcLoc = struct { |
| 2034 | .single => { | 2034 | .single => { |
| 2035 | var item_i: u32 = 0; | 2035 | var item_i: u32 = 0; |
| 2036 | for (case.ast.values) |item_node| { | 2036 | for (case.ast.values) |item_node| { |
| 2037 | if (tree.nodeTag(item_node) == .switch_range) continue; | 2037 | if (item_node.tag(tree) == .switch_range) continue; |
| 2038 | if (item_i != want_item.index) { | 2038 | if (item_i != want_item.index) { |
| 2039 | item_i += 1; | 2039 | item_i += 1; |
| 2040 | continue; | 2040 | continue; |
| ... | @@ -2045,12 +2045,12 @@ pub const SrcLoc = struct { | ... | @@ -2045,12 +2045,12 @@ pub const SrcLoc = struct { |
| 2045 | .range => { | 2045 | .range => { |
| 2046 | var range_i: u32 = 0; | 2046 | var range_i: u32 = 0; |
| 2047 | for (case.ast.values) |item_node| { | 2047 | for (case.ast.values) |item_node| { |
| 2048 | if (tree.nodeTag(item_node) != .switch_range) continue; | 2048 | if (item_node.tag(tree) != .switch_range) continue; |
| 2049 | if (range_i != want_item.index) { | 2049 | if (range_i != want_item.index) { |
| 2050 | range_i += 1; | 2050 | range_i += 1; |
| 2051 | continue; | 2051 | continue; |
| 2052 | } | 2052 | } |
| 2053 | const first, const last = tree.nodeData(item_node).node_and_node; | 2053 | const first, const last = item_node.data(tree).node_and_node; |
| 2054 | return switch (src_loc.lazy) { | 2054 | return switch (src_loc.lazy) { |
| 2055 | .switch_case_item => tree.nodeToSpan(item_node), | 2055 | .switch_case_item => tree.nodeToSpan(item_node), |
| 2056 | .switch_case_item_range_first => tree.nodeToSpan(first), | 2056 | .switch_case_item_range_first => tree.nodeToSpan(first), |
src/Zcu/PerThread.zig+1-1| ... | @@ -261,7 +261,7 @@ pub fn updateFile( | ... | @@ -261,7 +261,7 @@ pub fn updateFile( |
| 261 | }; | 261 | }; |
| 262 | }, | 262 | }, |
| 263 | .zon => { | 263 | .zon => { |
| 264 | file.zoir = try ZonGen.generate(gpa, file.tree.?, .{}); | 264 | file.zoir = try ZonGen.generate(gpa, &file.tree.?, .{}); |
| 265 | Zcu.saveZoirCache(cache_file, stat, file.zoir.?) catch |err| { | 265 | Zcu.saveZoirCache(cache_file, stat, file.zoir.?) catch |err| { |
| 266 | log.warn("unable to write cached ZOIR code for {}{s} to {}{s}: {s}", .{ | 266 | log.warn("unable to write cached ZOIR code for {}{s} to {}{s}: {s}", .{ |
| 267 | file.mod.root, file.sub_file_path, cache_directory, &hex_digest, @errorName(err), | 267 | file.mod.root, file.sub_file_path, cache_directory, &hex_digest, @errorName(err), |
src/fmt.zig+4-4| ... | @@ -106,28 +106,28 @@ pub fn run( | ... | @@ -106,28 +106,28 @@ pub fn run( |
| 106 | 106 | ||
| 107 | if (check_ast_flag) { | 107 | if (check_ast_flag) { |
| 108 | if (!force_zon) { | 108 | if (!force_zon) { |
| 109 | var zir = try std.zig.AstGen.generate(gpa, tree); | 109 | var zir = try std.zig.AstGen.generate(gpa, &tree); |
| 110 | defer zir.deinit(gpa); | 110 | defer zir.deinit(gpa); |
| 111 | 111 | ||
| 112 | if (zir.hasCompileErrors()) { | 112 | if (zir.hasCompileErrors()) { |
| 113 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; | 113 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 114 | try wip_errors.init(gpa); | 114 | try wip_errors.init(gpa); |
| 115 | defer wip_errors.deinit(); | 115 | defer wip_errors.deinit(); |
| 116 | try wip_errors.addZirErrorMessages(zir, tree, source_code, "<stdin>"); | 116 | try wip_errors.addZirErrorMessages(zir, &tree, source_code, "<stdin>"); |
| 117 | var error_bundle = try wip_errors.toOwnedBundle(""); | 117 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 118 | defer error_bundle.deinit(gpa); | 118 | defer error_bundle.deinit(gpa); |
| 119 | error_bundle.renderToStdErr(color.renderOptions()); | 119 | error_bundle.renderToStdErr(color.renderOptions()); |
| 120 | process.exit(2); | 120 | process.exit(2); |
| 121 | } | 121 | } |
| 122 | } else { | 122 | } else { |
| 123 | const zoir = try std.zig.ZonGen.generate(gpa, tree, .{}); | 123 | const zoir = try std.zig.ZonGen.generate(gpa, &tree, .{}); |
| 124 | defer zoir.deinit(gpa); | 124 | defer zoir.deinit(gpa); |
| 125 | 125 | ||
| 126 | if (zoir.hasCompileErrors()) { | 126 | if (zoir.hasCompileErrors()) { |
| 127 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; | 127 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 128 | try wip_errors.init(gpa); | 128 | try wip_errors.init(gpa); |
| 129 | defer wip_errors.deinit(); | 129 | defer wip_errors.deinit(); |
| 130 | try wip_errors.addZoirErrorMessages(zoir, tree, source_code, "<stdin>"); | 130 | try wip_errors.addZoirErrorMessages(zoir, &tree, source_code, "<stdin>"); |
| 131 | var error_bundle = try wip_errors.toOwnedBundle(""); | 131 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 132 | defer error_bundle.deinit(gpa); | 132 | defer error_bundle.deinit(gpa); |
| 133 | error_bundle.renderToStdErr(color.renderOptions()); | 133 | error_bundle.renderToStdErr(color.renderOptions()); |
src/main.zig+1-1| ... | @@ -6454,7 +6454,7 @@ fn cmdAstCheck( | ... | @@ -6454,7 +6454,7 @@ fn cmdAstCheck( |
| 6454 | } | 6454 | } |
| 6455 | }, | 6455 | }, |
| 6456 | .zon => { | 6456 | .zon => { |
| 6457 | const zoir = try ZonGen.generate(gpa, file.tree.?, .{}); | 6457 | const zoir = try ZonGen.generate(gpa, &file.tree.?, .{}); |
| 6458 | defer zoir.deinit(gpa); | 6458 | defer zoir.deinit(gpa); |
| 6459 | 6459 | ||
| 6460 | if (zoir.hasCompileErrors()) { | 6460 | if (zoir.hasCompileErrors()) { |