| ... | ... | @@ -250,6 +250,7 @@ pub const Tree = struct { |
| 250 | 250 | .FnProto, |
| 251 | 251 | .ArrayType, |
| 252 | 252 | .ArrayTypeSentinel, |
| 253 | .ErrorValue, |
| 253 | 254 | => return main_tokens[n], |
| 254 | 255 | |
| 255 | 256 | .ArrayInitDot, |
| ... | ... | @@ -424,12 +425,18 @@ pub const Tree = struct { |
| 424 | 425 | return main_tokens[n] - 1; |
| 425 | 426 | }, |
| 426 | 427 | |
| 427 | | .WhileSimple => unreachable, // TODO |
| 428 | | .WhileCont => unreachable, // TODO |
| 429 | | .While => unreachable, // TODO |
| 430 | | .ForSimple => unreachable, // TODO |
| 431 | | .For => unreachable, // TODO |
| 432 | | .ErrorValue => unreachable, // TODO |
| 428 | .WhileSimple, |
| 429 | .WhileCont, |
| 430 | .While, |
| 431 | .ForSimple, |
| 432 | .For, |
| 433 | => { |
| 434 | const main_token = main_tokens[n]; |
| 435 | return switch (token_tags[main_token - 1]) { |
| 436 | .Keyword_inline => main_token - 1, |
| 437 | else => main_token, |
| 438 | }; |
| 439 | }, |
| 433 | 440 | }; |
| 434 | 441 | } |
| 435 | 442 | |
| ... | ... | @@ -437,6 +444,7 @@ pub const Tree = struct { |
| 437 | 444 | const tags = tree.nodes.items(.tag); |
| 438 | 445 | const datas = tree.nodes.items(.data); |
| 439 | 446 | const main_tokens = tree.nodes.items(.main_token); |
| 447 | const token_starts = tree.tokens.items(.start); |
| 440 | 448 | var n = node; |
| 441 | 449 | var end_offset: TokenIndex = 0; |
| 442 | 450 | while (true) switch (tags[n]) { |
| ... | ... | @@ -521,6 +529,8 @@ pub const Tree = struct { |
| 521 | 529 | .AsmSimple, |
| 522 | 530 | .AsmOutput, |
| 523 | 531 | .AsmInput, |
| 532 | .FnProtoSimple, |
| 533 | .FnProtoMulti, |
| 524 | 534 | => return datas[n].rhs + end_offset, |
| 525 | 535 | |
| 526 | 536 | .AnyType, |
| ... | ... | @@ -759,6 +769,74 @@ pub const Tree = struct { |
| 759 | 769 | return main_tokens[n] + end_offset; |
| 760 | 770 | } |
| 761 | 771 | }, |
| 772 | .FnProtoOne => { |
| 773 | const extra = tree.extraData(datas[n].lhs, Node.FnProtoOne); |
| 774 | // linksection, callconv, align can appear in any order, so we |
| 775 | // find the last one here. |
| 776 | var max_node: Node.Index = datas[n].rhs; |
| 777 | var max_start = token_starts[main_tokens[max_node]]; |
| 778 | var max_offset: TokenIndex = 0; |
| 779 | if (extra.align_expr != 0) { |
| 780 | const start = token_starts[main_tokens[extra.align_expr]]; |
| 781 | if (start > max_start) { |
| 782 | max_node = extra.align_expr; |
| 783 | max_start = start; |
| 784 | max_offset = 1; // for the rparen |
| 785 | } |
| 786 | } |
| 787 | if (extra.section_expr != 0) { |
| 788 | const start = token_starts[main_tokens[extra.section_expr]]; |
| 789 | if (start > max_start) { |
| 790 | max_node = extra.section_expr; |
| 791 | max_start = start; |
| 792 | max_offset = 1; // for the rparen |
| 793 | } |
| 794 | } |
| 795 | if (extra.callconv_expr != 0) { |
| 796 | const start = token_starts[main_tokens[extra.callconv_expr]]; |
| 797 | if (start > max_start) { |
| 798 | max_node = extra.callconv_expr; |
| 799 | max_start = start; |
| 800 | max_offset = 1; // for the rparen |
| 801 | } |
| 802 | } |
| 803 | n = max_node; |
| 804 | end_offset += max_offset; |
| 805 | }, |
| 806 | .FnProto => { |
| 807 | const extra = tree.extraData(datas[n].lhs, Node.FnProto); |
| 808 | // linksection, callconv, align can appear in any order, so we |
| 809 | // find the last one here. |
| 810 | var max_node: Node.Index = datas[n].rhs; |
| 811 | var max_start = token_starts[main_tokens[max_node]]; |
| 812 | var max_offset: TokenIndex = 0; |
| 813 | if (extra.align_expr != 0) { |
| 814 | const start = token_starts[main_tokens[extra.align_expr]]; |
| 815 | if (start > max_start) { |
| 816 | max_node = extra.align_expr; |
| 817 | max_start = start; |
| 818 | max_offset = 1; // for the rparen |
| 819 | } |
| 820 | } |
| 821 | if (extra.section_expr != 0) { |
| 822 | const start = token_starts[main_tokens[extra.section_expr]]; |
| 823 | if (start > max_start) { |
| 824 | max_node = extra.section_expr; |
| 825 | max_start = start; |
| 826 | max_offset = 1; // for the rparen |
| 827 | } |
| 828 | } |
| 829 | if (extra.callconv_expr != 0) { |
| 830 | const start = token_starts[main_tokens[extra.callconv_expr]]; |
| 831 | if (start > max_start) { |
| 832 | max_node = extra.callconv_expr; |
| 833 | max_start = start; |
| 834 | max_offset = 1; // for the rparen |
| 835 | } |
| 836 | } |
| 837 | n = max_node; |
| 838 | end_offset += max_offset; |
| 839 | }, |
| 762 | 840 | |
| 763 | 841 | // These are not supported by lastToken() because implementation would |
| 764 | 842 | // require recursion due to the optional comma followed by rbrace. |
| ... | ... | @@ -782,10 +860,6 @@ pub const Tree = struct { |
| 782 | 860 | .While => unreachable, // TODO |
| 783 | 861 | .ForSimple => unreachable, // TODO |
| 784 | 862 | .For => unreachable, // TODO |
| 785 | | .FnProtoSimple => unreachable, // TODO |
| 786 | | .FnProtoMulti => unreachable, // TODO |
| 787 | | .FnProtoOne => unreachable, // TODO |
| 788 | | .FnProto => unreachable, // TODO |
| 789 | 863 | .ErrorValue => unreachable, // TODO |
| 790 | 864 | }; |
| 791 | 865 | } |
| ... | ... | @@ -2217,11 +2291,11 @@ pub const Node = struct { |
| 2217 | 2291 | /// `fn(a: b, c: d) rhs`. `sub_range_list[lhs]`. |
| 2218 | 2292 | /// anytype and ... parameters are omitted from the AST tree. |
| 2219 | 2293 | FnProtoMulti, |
| 2220 | | /// `fn(a: b) rhs linksection(e) callconv(f)`. lhs is index into extra_data. |
| 2294 | /// `fn(a: b) rhs linksection(e) callconv(f)`. `FnProtoOne[lhs]`. |
| 2221 | 2295 | /// zero or one parameters. |
| 2222 | 2296 | /// anytype and ... parameters are omitted from the AST tree. |
| 2223 | 2297 | FnProtoOne, |
| 2224 | | /// `fn(a: b, c: d) rhs linksection(e) callconv(f)`. `fn_proto_list[lhs]`. |
| 2298 | /// `fn(a: b, c: d) rhs linksection(e) callconv(f)`. `FnProto[lhs]`. |
| 2225 | 2299 | /// anytype and ... parameters are omitted from the AST tree. |
| 2226 | 2300 | FnProto, |
| 2227 | 2301 | /// lhs is the FnProto, rhs is the function body block. |