authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-03 17:59:11-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-03 17:59:11-04:00
logc5f1925bc801c34133437d0d78de6b1d520f9f12
tree2dbe57d7ed8899750fad57359269157c5dc6a302
parent5dfcd09e496160054d4f333500d084e35f2fbdd2

when decls don't change, don't regenerate them


4 files changed, 149 insertions(+), 119 deletions(-)

src-self-hosted/compilation.zig+19-7
...@@ -876,13 +876,25 @@ pub const Compilation = struct {...@@ -876,13 +876,25 @@ pub const Compilation = struct {
876876
877 if (existing_decls.remove(name)) |entry| {877 if (existing_decls.remove(name)) |entry| {
878 // compare new code to existing878 // compare new code to existing
879 const existing_decl = entry.value;879 if (entry.value.cast(Decl.Fn)) |existing_fn_decl| {
880 // Just compare the old bytes to the new bytes of the top level decl.880 // Just compare the old bytes to the new bytes of the top level decl.
881 // Even if the AST is technically the same, we want error messages to display881 // Even if the AST is technically the same, we want error messages to display
882 // from the most recent source.882 // from the most recent source.
883 @panic("TODO handle decl comparison");883 const old_decl_src = existing_fn_decl.base.tree_scope.tree.getNodeSource(
884 // Add the new thing before dereferencing the old thing. This way we don't end884 &existing_fn_decl.fn_proto.base,
885 // up pointlessly re-creating things we end up using in the new thing.885 );
886 const new_decl_src = tree_scope.tree.getNodeSource(&fn_proto.base);
887 if (mem.eql(u8, old_decl_src, new_decl_src)) {
888 // it's the same, we can skip this decl
889 continue;
890 } else {
891 @panic("TODO decl changed implementation");
892 // Add the new thing before dereferencing the old thing. This way we don't end
893 // up pointlessly re-creating things we end up using in the new thing.
894 }
895 } else {
896 @panic("TODO decl changed kind");
897 }
886 } else {898 } else {
887 // add new decl899 // add new decl
888 const fn_decl = try self.gpa().create(Decl.Fn{900 const fn_decl = try self.gpa().create(Decl.Fn{
src-self-hosted/decl.zig+5-1
...@@ -22,6 +22,11 @@ pub const Decl = struct {...@@ -22,6 +22,11 @@ pub const Decl = struct {
2222
23 pub const Table = std.HashMap([]const u8, *Decl, mem.hash_slice_u8, mem.eql_slice_u8);23 pub const Table = std.HashMap([]const u8, *Decl, mem.hash_slice_u8, mem.eql_slice_u8);
2424
25 pub fn cast(base: *Decl, comptime T: type) ?*T {
26 if (base.id != @field(Id, @typeName(T))) return null;
27 return @fieldParentPtr(T, "base", base);
28 }
29
25 pub fn isExported(base: *const Decl, tree: *ast.Tree) bool {30 pub fn isExported(base: *const Decl, tree: *ast.Tree) bool {
26 switch (base.id) {31 switch (base.id) {
27 Id.Fn => {32 Id.Fn => {
...@@ -98,4 +103,3 @@ pub const Decl = struct {...@@ -98,4 +103,3 @@ pub const Decl = struct {
98 base: Decl,103 base: Decl,
99 };104 };
100};105};
101
std/segmented_list.zig+13-5
...@@ -2,7 +2,7 @@ const std = @import("index.zig");...@@ -2,7 +2,7 @@ const std = @import("index.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const Allocator = std.mem.Allocator;3const Allocator = std.mem.Allocator;
44
5// Imagine that `fn at(self: &Self, index: usize) &T` is a customer asking for a box5// Imagine that `fn at(self: *Self, index: usize) &T` is a customer asking for a box
6// from a warehouse, based on a flat array, boxes ordered from 0 to N - 1.6// from a warehouse, based on a flat array, boxes ordered from 0 to N - 1.
7// But the warehouse actually stores boxes in shelves of increasing powers of 2 sizes.7// But the warehouse actually stores boxes in shelves of increasing powers of 2 sizes.
8// So when the customer requests a box index, we have to translate it to shelf index8// So when the customer requests a box index, we have to translate it to shelf index
...@@ -93,6 +93,14 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -93,6 +93,14 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
9393
94 pub const prealloc_count = prealloc_item_count;94 pub const prealloc_count = prealloc_item_count;
9595
96 fn AtType(comptime SelfType: type) type {
97 if (@typeInfo(SelfType).Pointer.is_const) {
98 return *const T;
99 } else {
100 return *T;
101 }
102 }
103
96 /// Deinitialize with `deinit`104 /// Deinitialize with `deinit`
97 pub fn init(allocator: *Allocator) Self {105 pub fn init(allocator: *Allocator) Self {
98 return Self{106 return Self{
...@@ -109,7 +117,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -109,7 +117,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
109 self.* = undefined;117 self.* = undefined;
110 }118 }
111119
112 pub fn at(self: *Self, i: usize) *T {120 pub fn at(self: var, i: usize) AtType(@typeOf(self)) {
113 assert(i < self.len);121 assert(i < self.len);
114 return self.uncheckedAt(i);122 return self.uncheckedAt(i);
115 }123 }
...@@ -133,7 +141,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -133,7 +141,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
133 if (self.len == 0) return null;141 if (self.len == 0) return null;
134142
135 const index = self.len - 1;143 const index = self.len - 1;
136 const result = self.uncheckedAt(index).*;144 const result = uncheckedAt(self, index).*;
137 self.len = index;145 self.len = index;
138 return result;146 return result;
139 }147 }
...@@ -141,7 +149,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -141,7 +149,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
141 pub fn addOne(self: *Self) !*T {149 pub fn addOne(self: *Self) !*T {
142 const new_length = self.len + 1;150 const new_length = self.len + 1;
143 try self.growCapacity(new_length);151 try self.growCapacity(new_length);
144 const result = self.uncheckedAt(self.len);152 const result = uncheckedAt(self, self.len);
145 self.len = new_length;153 self.len = new_length;
146 return result;154 return result;
147 }155 }
...@@ -193,7 +201,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -193,7 +201,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
193 self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, new_cap_shelf_count);201 self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, new_cap_shelf_count);
194 }202 }
195203
196 pub fn uncheckedAt(self: *Self, index: usize) *T {204 pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) {
197 if (index < prealloc_item_count) {205 if (index < prealloc_item_count) {
198 return &self.prealloc_segment[index];206 return &self.prealloc_segment[index];
199 }207 }
std/zig/ast.zig+112-106
...@@ -32,6 +32,12 @@ pub const Tree = struct {...@@ -32,6 +32,12 @@ pub const Tree = struct {
32 return self.source[token.start..token.end];32 return self.source[token.start..token.end];
33 }33 }
3434
35 pub fn getNodeSource(self: *const Tree, node: *const Node) []const u8 {
36 const first_token = self.tokens.at(node.firstToken());
37 const last_token = self.tokens.at(node.lastToken());
38 return self.source[first_token.start..last_token.end];
39 }
40
35 pub const Location = struct {41 pub const Location = struct {
36 line: usize,42 line: usize,
37 column: usize,43 column: usize,
...@@ -338,7 +344,7 @@ pub const Node = struct {...@@ -338,7 +344,7 @@ pub const Node = struct {
338 unreachable;344 unreachable;
339 }345 }
340346
341 pub fn firstToken(base: *Node) TokenIndex {347 pub fn firstToken(base: *const Node) TokenIndex {
342 comptime var i = 0;348 comptime var i = 0;
343 inline while (i < @memberCount(Id)) : (i += 1) {349 inline while (i < @memberCount(Id)) : (i += 1) {
344 if (base.id == @field(Id, @memberName(Id, i))) {350 if (base.id == @field(Id, @memberName(Id, i))) {
...@@ -349,7 +355,7 @@ pub const Node = struct {...@@ -349,7 +355,7 @@ pub const Node = struct {
349 unreachable;355 unreachable;
350 }356 }
351357
352 pub fn lastToken(base: *Node) TokenIndex {358 pub fn lastToken(base: *const Node) TokenIndex {
353 comptime var i = 0;359 comptime var i = 0;
354 inline while (i < @memberCount(Id)) : (i += 1) {360 inline while (i < @memberCount(Id)) : (i += 1) {
355 if (base.id == @field(Id, @memberName(Id, i))) {361 if (base.id == @field(Id, @memberName(Id, i))) {
...@@ -473,11 +479,11 @@ pub const Node = struct {...@@ -473,11 +479,11 @@ pub const Node = struct {
473 return null;479 return null;
474 }480 }
475481
476 pub fn firstToken(self: *Root) TokenIndex {482 pub fn firstToken(self: *const Root) TokenIndex {
477 return if (self.decls.len == 0) self.eof_token else (self.decls.at(0).*).firstToken();483 return if (self.decls.len == 0) self.eof_token else (self.decls.at(0).*).firstToken();
478 }484 }
479485
480 pub fn lastToken(self: *Root) TokenIndex {486 pub fn lastToken(self: *const Root) TokenIndex {
481 return if (self.decls.len == 0) self.eof_token else (self.decls.at(self.decls.len - 1).*).lastToken();487 return if (self.decls.len == 0) self.eof_token else (self.decls.at(self.decls.len - 1).*).lastToken();
482 }488 }
483 };489 };
...@@ -518,7 +524,7 @@ pub const Node = struct {...@@ -518,7 +524,7 @@ pub const Node = struct {
518 return null;524 return null;
519 }525 }
520526
521 pub fn firstToken(self: *VarDecl) TokenIndex {527 pub fn firstToken(self: *const VarDecl) TokenIndex {
522 if (self.visib_token) |visib_token| return visib_token;528 if (self.visib_token) |visib_token| return visib_token;
523 if (self.comptime_token) |comptime_token| return comptime_token;529 if (self.comptime_token) |comptime_token| return comptime_token;
524 if (self.extern_export_token) |extern_export_token| return extern_export_token;530 if (self.extern_export_token) |extern_export_token| return extern_export_token;
...@@ -526,7 +532,7 @@ pub const Node = struct {...@@ -526,7 +532,7 @@ pub const Node = struct {
526 return self.mut_token;532 return self.mut_token;
527 }533 }
528534
529 pub fn lastToken(self: *VarDecl) TokenIndex {535 pub fn lastToken(self: *const VarDecl) TokenIndex {
530 return self.semicolon_token;536 return self.semicolon_token;
531 }537 }
532 };538 };
...@@ -548,12 +554,12 @@ pub const Node = struct {...@@ -548,12 +554,12 @@ pub const Node = struct {
548 return null;554 return null;
549 }555 }
550556
551 pub fn firstToken(self: *Use) TokenIndex {557 pub fn firstToken(self: *const Use) TokenIndex {
552 if (self.visib_token) |visib_token| return visib_token;558 if (self.visib_token) |visib_token| return visib_token;
553 return self.use_token;559 return self.use_token;
554 }560 }
555561
556 pub fn lastToken(self: *Use) TokenIndex {562 pub fn lastToken(self: *const Use) TokenIndex {
557 return self.semicolon_token;563 return self.semicolon_token;
558 }564 }
559 };565 };
...@@ -575,11 +581,11 @@ pub const Node = struct {...@@ -575,11 +581,11 @@ pub const Node = struct {
575 return null;581 return null;
576 }582 }
577583
578 pub fn firstToken(self: *ErrorSetDecl) TokenIndex {584 pub fn firstToken(self: *const ErrorSetDecl) TokenIndex {
579 return self.error_token;585 return self.error_token;
580 }586 }
581587
582 pub fn lastToken(self: *ErrorSetDecl) TokenIndex {588 pub fn lastToken(self: *const ErrorSetDecl) TokenIndex {
583 return self.rbrace_token;589 return self.rbrace_token;
584 }590 }
585 };591 };
...@@ -618,14 +624,14 @@ pub const Node = struct {...@@ -618,14 +624,14 @@ pub const Node = struct {
618 return null;624 return null;
619 }625 }
620626
621 pub fn firstToken(self: *ContainerDecl) TokenIndex {627 pub fn firstToken(self: *const ContainerDecl) TokenIndex {
622 if (self.layout_token) |layout_token| {628 if (self.layout_token) |layout_token| {
623 return layout_token;629 return layout_token;
624 }630 }
625 return self.kind_token;631 return self.kind_token;
626 }632 }
627633
628 pub fn lastToken(self: *ContainerDecl) TokenIndex {634 pub fn lastToken(self: *const ContainerDecl) TokenIndex {
629 return self.rbrace_token;635 return self.rbrace_token;
630 }636 }
631 };637 };
...@@ -646,12 +652,12 @@ pub const Node = struct {...@@ -646,12 +652,12 @@ pub const Node = struct {
646 return null;652 return null;
647 }653 }
648654
649 pub fn firstToken(self: *StructField) TokenIndex {655 pub fn firstToken(self: *const StructField) TokenIndex {
650 if (self.visib_token) |visib_token| return visib_token;656 if (self.visib_token) |visib_token| return visib_token;
651 return self.name_token;657 return self.name_token;
652 }658 }
653659
654 pub fn lastToken(self: *StructField) TokenIndex {660 pub fn lastToken(self: *const StructField) TokenIndex {
655 return self.type_expr.lastToken();661 return self.type_expr.lastToken();
656 }662 }
657 };663 };
...@@ -679,11 +685,11 @@ pub const Node = struct {...@@ -679,11 +685,11 @@ pub const Node = struct {
679 return null;685 return null;
680 }686 }
681687
682 pub fn firstToken(self: *UnionTag) TokenIndex {688 pub fn firstToken(self: *const UnionTag) TokenIndex {
683 return self.name_token;689 return self.name_token;
684 }690 }
685691
686 pub fn lastToken(self: *UnionTag) TokenIndex {692 pub fn lastToken(self: *const UnionTag) TokenIndex {
687 if (self.value_expr) |value_expr| {693 if (self.value_expr) |value_expr| {
688 return value_expr.lastToken();694 return value_expr.lastToken();
689 }695 }
...@@ -712,11 +718,11 @@ pub const Node = struct {...@@ -712,11 +718,11 @@ pub const Node = struct {
712 return null;718 return null;
713 }719 }
714720
715 pub fn firstToken(self: *EnumTag) TokenIndex {721 pub fn firstToken(self: *const EnumTag) TokenIndex {
716 return self.name_token;722 return self.name_token;
717 }723 }
718724
719 pub fn lastToken(self: *EnumTag) TokenIndex {725 pub fn lastToken(self: *const EnumTag) TokenIndex {
720 if (self.value) |value| {726 if (self.value) |value| {
721 return value.lastToken();727 return value.lastToken();
722 }728 }
...@@ -741,11 +747,11 @@ pub const Node = struct {...@@ -741,11 +747,11 @@ pub const Node = struct {
741 return null;747 return null;
742 }748 }
743749
744 pub fn firstToken(self: *ErrorTag) TokenIndex {750 pub fn firstToken(self: *const ErrorTag) TokenIndex {
745 return self.name_token;751 return self.name_token;
746 }752 }
747753
748 pub fn lastToken(self: *ErrorTag) TokenIndex {754 pub fn lastToken(self: *const ErrorTag) TokenIndex {
749 return self.name_token;755 return self.name_token;
750 }756 }
751 };757 };
...@@ -758,11 +764,11 @@ pub const Node = struct {...@@ -758,11 +764,11 @@ pub const Node = struct {
758 return null;764 return null;
759 }765 }
760766
761 pub fn firstToken(self: *Identifier) TokenIndex {767 pub fn firstToken(self: *const Identifier) TokenIndex {
762 return self.token;768 return self.token;
763 }769 }
764770
765 pub fn lastToken(self: *Identifier) TokenIndex {771 pub fn lastToken(self: *const Identifier) TokenIndex {
766 return self.token;772 return self.token;
767 }773 }
768 };774 };
...@@ -784,11 +790,11 @@ pub const Node = struct {...@@ -784,11 +790,11 @@ pub const Node = struct {
784 return null;790 return null;
785 }791 }
786792
787 pub fn firstToken(self: *AsyncAttribute) TokenIndex {793 pub fn firstToken(self: *const AsyncAttribute) TokenIndex {
788 return self.async_token;794 return self.async_token;
789 }795 }
790796
791 pub fn lastToken(self: *AsyncAttribute) TokenIndex {797 pub fn lastToken(self: *const AsyncAttribute) TokenIndex {
792 if (self.rangle_bracket) |rangle_bracket| {798 if (self.rangle_bracket) |rangle_bracket| {
793 return rangle_bracket;799 return rangle_bracket;
794 }800 }
...@@ -856,7 +862,7 @@ pub const Node = struct {...@@ -856,7 +862,7 @@ pub const Node = struct {
856 return null;862 return null;
857 }863 }
858864
859 pub fn firstToken(self: *FnProto) TokenIndex {865 pub fn firstToken(self: *const FnProto) TokenIndex {
860 if (self.visib_token) |visib_token| return visib_token;866 if (self.visib_token) |visib_token| return visib_token;
861 if (self.async_attr) |async_attr| return async_attr.firstToken();867 if (self.async_attr) |async_attr| return async_attr.firstToken();
862 if (self.extern_export_inline_token) |extern_export_inline_token| return extern_export_inline_token;868 if (self.extern_export_inline_token) |extern_export_inline_token| return extern_export_inline_token;
...@@ -865,7 +871,7 @@ pub const Node = struct {...@@ -865,7 +871,7 @@ pub const Node = struct {
865 return self.fn_token;871 return self.fn_token;
866 }872 }
867873
868 pub fn lastToken(self: *FnProto) TokenIndex {874 pub fn lastToken(self: *const FnProto) TokenIndex {
869 if (self.body_node) |body_node| return body_node.lastToken();875 if (self.body_node) |body_node| return body_node.lastToken();
870 switch (self.return_type) {876 switch (self.return_type) {
871 // TODO allow this and next prong to share bodies since the types are the same877 // TODO allow this and next prong to share bodies since the types are the same
...@@ -896,11 +902,11 @@ pub const Node = struct {...@@ -896,11 +902,11 @@ pub const Node = struct {
896 return null;902 return null;
897 }903 }
898904
899 pub fn firstToken(self: *PromiseType) TokenIndex {905 pub fn firstToken(self: *const PromiseType) TokenIndex {
900 return self.promise_token;906 return self.promise_token;
901 }907 }
902908
903 pub fn lastToken(self: *PromiseType) TokenIndex {909 pub fn lastToken(self: *const PromiseType) TokenIndex {
904 if (self.result) |result| return result.return_type.lastToken();910 if (self.result) |result| return result.return_type.lastToken();
905 return self.promise_token;911 return self.promise_token;
906 }912 }
...@@ -923,14 +929,14 @@ pub const Node = struct {...@@ -923,14 +929,14 @@ pub const Node = struct {
923 return null;929 return null;
924 }930 }
925931
926 pub fn firstToken(self: *ParamDecl) TokenIndex {932 pub fn firstToken(self: *const ParamDecl) TokenIndex {
927 if (self.comptime_token) |comptime_token| return comptime_token;933 if (self.comptime_token) |comptime_token| return comptime_token;
928 if (self.noalias_token) |noalias_token| return noalias_token;934 if (self.noalias_token) |noalias_token| return noalias_token;
929 if (self.name_token) |name_token| return name_token;935 if (self.name_token) |name_token| return name_token;
930 return self.type_node.firstToken();936 return self.type_node.firstToken();
931 }937 }
932938
933 pub fn lastToken(self: *ParamDecl) TokenIndex {939 pub fn lastToken(self: *const ParamDecl) TokenIndex {
934 if (self.var_args_token) |var_args_token| return var_args_token;940 if (self.var_args_token) |var_args_token| return var_args_token;
935 return self.type_node.lastToken();941 return self.type_node.lastToken();
936 }942 }
...@@ -954,7 +960,7 @@ pub const Node = struct {...@@ -954,7 +960,7 @@ pub const Node = struct {
954 return null;960 return null;
955 }961 }
956962
957 pub fn firstToken(self: *Block) TokenIndex {963 pub fn firstToken(self: *const Block) TokenIndex {
958 if (self.label) |label| {964 if (self.label) |label| {
959 return label;965 return label;
960 }966 }
...@@ -962,7 +968,7 @@ pub const Node = struct {...@@ -962,7 +968,7 @@ pub const Node = struct {
962 return self.lbrace;968 return self.lbrace;
963 }969 }
964970
965 pub fn lastToken(self: *Block) TokenIndex {971 pub fn lastToken(self: *const Block) TokenIndex {
966 return self.rbrace;972 return self.rbrace;
967 }973 }
968 };974 };
...@@ -981,11 +987,11 @@ pub const Node = struct {...@@ -981,11 +987,11 @@ pub const Node = struct {
981 return null;987 return null;
982 }988 }
983989
984 pub fn firstToken(self: *Defer) TokenIndex {990 pub fn firstToken(self: *const Defer) TokenIndex {
985 return self.defer_token;991 return self.defer_token;
986 }992 }
987993
988 pub fn lastToken(self: *Defer) TokenIndex {994 pub fn lastToken(self: *const Defer) TokenIndex {
989 return self.expr.lastToken();995 return self.expr.lastToken();
990 }996 }
991 };997 };
...@@ -1005,11 +1011,11 @@ pub const Node = struct {...@@ -1005,11 +1011,11 @@ pub const Node = struct {
1005 return null;1011 return null;
1006 }1012 }
10071013
1008 pub fn firstToken(self: *Comptime) TokenIndex {1014 pub fn firstToken(self: *const Comptime) TokenIndex {
1009 return self.comptime_token;1015 return self.comptime_token;
1010 }1016 }
10111017
1012 pub fn lastToken(self: *Comptime) TokenIndex {1018 pub fn lastToken(self: *const Comptime) TokenIndex {
1013 return self.expr.lastToken();1019 return self.expr.lastToken();
1014 }1020 }
1015 };1021 };
...@@ -1029,11 +1035,11 @@ pub const Node = struct {...@@ -1029,11 +1035,11 @@ pub const Node = struct {
1029 return null;1035 return null;
1030 }1036 }
10311037
1032 pub fn firstToken(self: *Payload) TokenIndex {1038 pub fn firstToken(self: *const Payload) TokenIndex {
1033 return self.lpipe;1039 return self.lpipe;
1034 }1040 }
10351041
1036 pub fn lastToken(self: *Payload) TokenIndex {1042 pub fn lastToken(self: *const Payload) TokenIndex {
1037 return self.rpipe;1043 return self.rpipe;
1038 }1044 }
1039 };1045 };
...@@ -1054,11 +1060,11 @@ pub const Node = struct {...@@ -1054,11 +1060,11 @@ pub const Node = struct {
1054 return null;1060 return null;
1055 }1061 }
10561062
1057 pub fn firstToken(self: *PointerPayload) TokenIndex {1063 pub fn firstToken(self: *const PointerPayload) TokenIndex {
1058 return self.lpipe;1064 return self.lpipe;
1059 }1065 }
10601066
1061 pub fn lastToken(self: *PointerPayload) TokenIndex {1067 pub fn lastToken(self: *const PointerPayload) TokenIndex {
1062 return self.rpipe;1068 return self.rpipe;
1063 }1069 }
1064 };1070 };
...@@ -1085,11 +1091,11 @@ pub const Node = struct {...@@ -1085,11 +1091,11 @@ pub const Node = struct {
1085 return null;1091 return null;
1086 }1092 }
10871093
1088 pub fn firstToken(self: *PointerIndexPayload) TokenIndex {1094 pub fn firstToken(self: *const PointerIndexPayload) TokenIndex {
1089 return self.lpipe;1095 return self.lpipe;
1090 }1096 }
10911097
1092 pub fn lastToken(self: *PointerIndexPayload) TokenIndex {1098 pub fn lastToken(self: *const PointerIndexPayload) TokenIndex {
1093 return self.rpipe;1099 return self.rpipe;
1094 }1100 }
1095 };1101 };
...@@ -1114,11 +1120,11 @@ pub const Node = struct {...@@ -1114,11 +1120,11 @@ pub const Node = struct {
1114 return null;1120 return null;
1115 }1121 }
11161122
1117 pub fn firstToken(self: *Else) TokenIndex {1123 pub fn firstToken(self: *const Else) TokenIndex {
1118 return self.else_token;1124 return self.else_token;
1119 }1125 }
11201126
1121 pub fn lastToken(self: *Else) TokenIndex {1127 pub fn lastToken(self: *const Else) TokenIndex {
1122 return self.body.lastToken();1128 return self.body.lastToken();
1123 }1129 }
1124 };1130 };
...@@ -1146,11 +1152,11 @@ pub const Node = struct {...@@ -1146,11 +1152,11 @@ pub const Node = struct {
1146 return null;1152 return null;
1147 }1153 }
11481154
1149 pub fn firstToken(self: *Switch) TokenIndex {1155 pub fn firstToken(self: *const Switch) TokenIndex {
1150 return self.switch_token;1156 return self.switch_token;
1151 }1157 }
11521158
1153 pub fn lastToken(self: *Switch) TokenIndex {1159 pub fn lastToken(self: *const Switch) TokenIndex {
1154 return self.rbrace;1160 return self.rbrace;
1155 }1161 }
1156 };1162 };
...@@ -1181,11 +1187,11 @@ pub const Node = struct {...@@ -1181,11 +1187,11 @@ pub const Node = struct {
1181 return null;1187 return null;
1182 }1188 }
11831189
1184 pub fn firstToken(self: *SwitchCase) TokenIndex {1190 pub fn firstToken(self: *const SwitchCase) TokenIndex {
1185 return (self.items.at(0).*).firstToken();1191 return (self.items.at(0).*).firstToken();
1186 }1192 }
11871193
1188 pub fn lastToken(self: *SwitchCase) TokenIndex {1194 pub fn lastToken(self: *const SwitchCase) TokenIndex {
1189 return self.expr.lastToken();1195 return self.expr.lastToken();
1190 }1196 }
1191 };1197 };
...@@ -1198,11 +1204,11 @@ pub const Node = struct {...@@ -1198,11 +1204,11 @@ pub const Node = struct {
1198 return null;1204 return null;
1199 }1205 }
12001206
1201 pub fn firstToken(self: *SwitchElse) TokenIndex {1207 pub fn firstToken(self: *const SwitchElse) TokenIndex {
1202 return self.token;1208 return self.token;
1203 }1209 }
12041210
1205 pub fn lastToken(self: *SwitchElse) TokenIndex {1211 pub fn lastToken(self: *const SwitchElse) TokenIndex {
1206 return self.token;1212 return self.token;
1207 }1213 }
1208 };1214 };
...@@ -1245,7 +1251,7 @@ pub const Node = struct {...@@ -1245,7 +1251,7 @@ pub const Node = struct {
1245 return null;1251 return null;
1246 }1252 }
12471253
1248 pub fn firstToken(self: *While) TokenIndex {1254 pub fn firstToken(self: *const While) TokenIndex {
1249 if (self.label) |label| {1255 if (self.label) |label| {
1250 return label;1256 return label;
1251 }1257 }
...@@ -1257,7 +1263,7 @@ pub const Node = struct {...@@ -1257,7 +1263,7 @@ pub const Node = struct {
1257 return self.while_token;1263 return self.while_token;
1258 }1264 }
12591265
1260 pub fn lastToken(self: *While) TokenIndex {1266 pub fn lastToken(self: *const While) TokenIndex {
1261 if (self.@"else") |@"else"| {1267 if (self.@"else") |@"else"| {
1262 return @"else".body.lastToken();1268 return @"else".body.lastToken();
1263 }1269 }
...@@ -1298,7 +1304,7 @@ pub const Node = struct {...@@ -1298,7 +1304,7 @@ pub const Node = struct {
1298 return null;1304 return null;
1299 }1305 }
13001306
1301 pub fn firstToken(self: *For) TokenIndex {1307 pub fn firstToken(self: *const For) TokenIndex {
1302 if (self.label) |label| {1308 if (self.label) |label| {
1303 return label;1309 return label;
1304 }1310 }
...@@ -1310,7 +1316,7 @@ pub const Node = struct {...@@ -1310,7 +1316,7 @@ pub const Node = struct {
1310 return self.for_token;1316 return self.for_token;
1311 }1317 }
13121318
1313 pub fn lastToken(self: *For) TokenIndex {1319 pub fn lastToken(self: *const For) TokenIndex {
1314 if (self.@"else") |@"else"| {1320 if (self.@"else") |@"else"| {
1315 return @"else".body.lastToken();1321 return @"else".body.lastToken();
1316 }1322 }
...@@ -1349,11 +1355,11 @@ pub const Node = struct {...@@ -1349,11 +1355,11 @@ pub const Node = struct {
1349 return null;1355 return null;
1350 }1356 }
13511357
1352 pub fn firstToken(self: *If) TokenIndex {1358 pub fn firstToken(self: *const If) TokenIndex {
1353 return self.if_token;1359 return self.if_token;
1354 }1360 }
13551361
1356 pub fn lastToken(self: *If) TokenIndex {1362 pub fn lastToken(self: *const If) TokenIndex {
1357 if (self.@"else") |@"else"| {1363 if (self.@"else") |@"else"| {
1358 return @"else".body.lastToken();1364 return @"else".body.lastToken();
1359 }1365 }
...@@ -1480,11 +1486,11 @@ pub const Node = struct {...@@ -1480,11 +1486,11 @@ pub const Node = struct {
1480 return null;1486 return null;
1481 }1487 }
14821488
1483 pub fn firstToken(self: *InfixOp) TokenIndex {1489 pub fn firstToken(self: *const InfixOp) TokenIndex {
1484 return self.lhs.firstToken();1490 return self.lhs.firstToken();
1485 }1491 }
14861492
1487 pub fn lastToken(self: *InfixOp) TokenIndex {1493 pub fn lastToken(self: *const InfixOp) TokenIndex {
1488 return self.rhs.lastToken();1494 return self.rhs.lastToken();
1489 }1495 }
1490 };1496 };
...@@ -1570,11 +1576,11 @@ pub const Node = struct {...@@ -1570,11 +1576,11 @@ pub const Node = struct {
1570 return null;1576 return null;
1571 }1577 }
15721578
1573 pub fn firstToken(self: *PrefixOp) TokenIndex {1579 pub fn firstToken(self: *const PrefixOp) TokenIndex {
1574 return self.op_token;1580 return self.op_token;
1575 }1581 }
15761582
1577 pub fn lastToken(self: *PrefixOp) TokenIndex {1583 pub fn lastToken(self: *const PrefixOp) TokenIndex {
1578 return self.rhs.lastToken();1584 return self.rhs.lastToken();
1579 }1585 }
1580 };1586 };
...@@ -1594,11 +1600,11 @@ pub const Node = struct {...@@ -1594,11 +1600,11 @@ pub const Node = struct {
1594 return null;1600 return null;
1595 }1601 }
15961602
1597 pub fn firstToken(self: *FieldInitializer) TokenIndex {1603 pub fn firstToken(self: *const FieldInitializer) TokenIndex {
1598 return self.period_token;1604 return self.period_token;
1599 }1605 }
16001606
1601 pub fn lastToken(self: *FieldInitializer) TokenIndex {1607 pub fn lastToken(self: *const FieldInitializer) TokenIndex {
1602 return self.expr.lastToken();1608 return self.expr.lastToken();
1603 }1609 }
1604 };1610 };
...@@ -1673,7 +1679,7 @@ pub const Node = struct {...@@ -1673,7 +1679,7 @@ pub const Node = struct {
1673 return null;1679 return null;
1674 }1680 }
16751681
1676 pub fn firstToken(self: *SuffixOp) TokenIndex {1682 pub fn firstToken(self: *const SuffixOp) TokenIndex {
1677 switch (self.op) {1683 switch (self.op) {
1678 @TagType(Op).Call => |*call_info| if (call_info.async_attr) |async_attr| return async_attr.firstToken(),1684 @TagType(Op).Call => |*call_info| if (call_info.async_attr) |async_attr| return async_attr.firstToken(),
1679 else => {},1685 else => {},
...@@ -1681,7 +1687,7 @@ pub const Node = struct {...@@ -1681,7 +1687,7 @@ pub const Node = struct {
1681 return self.lhs.firstToken();1687 return self.lhs.firstToken();
1682 }1688 }
16831689
1684 pub fn lastToken(self: *SuffixOp) TokenIndex {1690 pub fn lastToken(self: *const SuffixOp) TokenIndex {
1685 return self.rtoken;1691 return self.rtoken;
1686 }1692 }
1687 };1693 };
...@@ -1701,11 +1707,11 @@ pub const Node = struct {...@@ -1701,11 +1707,11 @@ pub const Node = struct {
1701 return null;1707 return null;
1702 }1708 }
17031709
1704 pub fn firstToken(self: *GroupedExpression) TokenIndex {1710 pub fn firstToken(self: *const GroupedExpression) TokenIndex {
1705 return self.lparen;1711 return self.lparen;
1706 }1712 }
17071713
1708 pub fn lastToken(self: *GroupedExpression) TokenIndex {1714 pub fn lastToken(self: *const GroupedExpression) TokenIndex {
1709 return self.rparen;1715 return self.rparen;
1710 }1716 }
1711 };1717 };
...@@ -1749,11 +1755,11 @@ pub const Node = struct {...@@ -1749,11 +1755,11 @@ pub const Node = struct {
1749 return null;1755 return null;
1750 }1756 }
17511757
1752 pub fn firstToken(self: *ControlFlowExpression) TokenIndex {1758 pub fn firstToken(self: *const ControlFlowExpression) TokenIndex {
1753 return self.ltoken;1759 return self.ltoken;
1754 }1760 }
17551761
1756 pub fn lastToken(self: *ControlFlowExpression) TokenIndex {1762 pub fn lastToken(self: *const ControlFlowExpression) TokenIndex {
1757 if (self.rhs) |rhs| {1763 if (self.rhs) |rhs| {
1758 return rhs.lastToken();1764 return rhs.lastToken();
1759 }1765 }
...@@ -1792,11 +1798,11 @@ pub const Node = struct {...@@ -1792,11 +1798,11 @@ pub const Node = struct {
1792 return null;1798 return null;
1793 }1799 }
17941800
1795 pub fn firstToken(self: *Suspend) TokenIndex {1801 pub fn firstToken(self: *const Suspend) TokenIndex {
1796 return self.suspend_token;1802 return self.suspend_token;
1797 }1803 }
17981804
1799 pub fn lastToken(self: *Suspend) TokenIndex {1805 pub fn lastToken(self: *const Suspend) TokenIndex {
1800 if (self.body) |body| {1806 if (self.body) |body| {
1801 return body.lastToken();1807 return body.lastToken();
1802 }1808 }
...@@ -1813,11 +1819,11 @@ pub const Node = struct {...@@ -1813,11 +1819,11 @@ pub const Node = struct {
1813 return null;1819 return null;
1814 }1820 }
18151821
1816 pub fn firstToken(self: *IntegerLiteral) TokenIndex {1822 pub fn firstToken(self: *const IntegerLiteral) TokenIndex {
1817 return self.token;1823 return self.token;
1818 }1824 }
18191825
1820 pub fn lastToken(self: *IntegerLiteral) TokenIndex {1826 pub fn lastToken(self: *const IntegerLiteral) TokenIndex {
1821 return self.token;1827 return self.token;
1822 }1828 }
1823 };1829 };
...@@ -1830,11 +1836,11 @@ pub const Node = struct {...@@ -1830,11 +1836,11 @@ pub const Node = struct {
1830 return null;1836 return null;
1831 }1837 }
18321838
1833 pub fn firstToken(self: *FloatLiteral) TokenIndex {1839 pub fn firstToken(self: *const FloatLiteral) TokenIndex {
1834 return self.token;1840 return self.token;
1835 }1841 }
18361842
1837 pub fn lastToken(self: *FloatLiteral) TokenIndex {1843 pub fn lastToken(self: *const FloatLiteral) TokenIndex {
1838 return self.token;1844 return self.token;
1839 }1845 }
1840 };1846 };
...@@ -1856,11 +1862,11 @@ pub const Node = struct {...@@ -1856,11 +1862,11 @@ pub const Node = struct {
1856 return null;1862 return null;
1857 }1863 }
18581864
1859 pub fn firstToken(self: *BuiltinCall) TokenIndex {1865 pub fn firstToken(self: *const BuiltinCall) TokenIndex {
1860 return self.builtin_token;1866 return self.builtin_token;
1861 }1867 }
18621868
1863 pub fn lastToken(self: *BuiltinCall) TokenIndex {1869 pub fn lastToken(self: *const BuiltinCall) TokenIndex {
1864 return self.rparen_token;1870 return self.rparen_token;
1865 }1871 }
1866 };1872 };
...@@ -1873,11 +1879,11 @@ pub const Node = struct {...@@ -1873,11 +1879,11 @@ pub const Node = struct {
1873 return null;1879 return null;
1874 }1880 }
18751881
1876 pub fn firstToken(self: *StringLiteral) TokenIndex {1882 pub fn firstToken(self: *const StringLiteral) TokenIndex {
1877 return self.token;1883 return self.token;
1878 }1884 }
18791885
1880 pub fn lastToken(self: *StringLiteral) TokenIndex {1886 pub fn lastToken(self: *const StringLiteral) TokenIndex {
1881 return self.token;1887 return self.token;
1882 }1888 }
1883 };1889 };
...@@ -1892,11 +1898,11 @@ pub const Node = struct {...@@ -1892,11 +1898,11 @@ pub const Node = struct {
1892 return null;1898 return null;
1893 }1899 }
18941900
1895 pub fn firstToken(self: *MultilineStringLiteral) TokenIndex {1901 pub fn firstToken(self: *const MultilineStringLiteral) TokenIndex {
1896 return self.lines.at(0).*;1902 return self.lines.at(0).*;
1897 }1903 }
18981904
1899 pub fn lastToken(self: *MultilineStringLiteral) TokenIndex {1905 pub fn lastToken(self: *const MultilineStringLiteral) TokenIndex {
1900 return self.lines.at(self.lines.len - 1).*;1906 return self.lines.at(self.lines.len - 1).*;
1901 }1907 }
1902 };1908 };
...@@ -1909,11 +1915,11 @@ pub const Node = struct {...@@ -1909,11 +1915,11 @@ pub const Node = struct {
1909 return null;1915 return null;
1910 }1916 }
19111917
1912 pub fn firstToken(self: *CharLiteral) TokenIndex {1918 pub fn firstToken(self: *const CharLiteral) TokenIndex {
1913 return self.token;1919 return self.token;
1914 }1920 }
19151921
1916 pub fn lastToken(self: *CharLiteral) TokenIndex {1922 pub fn lastToken(self: *const CharLiteral) TokenIndex {
1917 return self.token;1923 return self.token;
1918 }1924 }
1919 };1925 };
...@@ -1926,11 +1932,11 @@ pub const Node = struct {...@@ -1926,11 +1932,11 @@ pub const Node = struct {
1926 return null;1932 return null;
1927 }1933 }
19281934
1929 pub fn firstToken(self: *BoolLiteral) TokenIndex {1935 pub fn firstToken(self: *const BoolLiteral) TokenIndex {
1930 return self.token;1936 return self.token;
1931 }1937 }
19321938
1933 pub fn lastToken(self: *BoolLiteral) TokenIndex {1939 pub fn lastToken(self: *const BoolLiteral) TokenIndex {
1934 return self.token;1940 return self.token;
1935 }1941 }
1936 };1942 };
...@@ -1943,11 +1949,11 @@ pub const Node = struct {...@@ -1943,11 +1949,11 @@ pub const Node = struct {
1943 return null;1949 return null;
1944 }1950 }
19451951
1946 pub fn firstToken(self: *NullLiteral) TokenIndex {1952 pub fn firstToken(self: *const NullLiteral) TokenIndex {
1947 return self.token;1953 return self.token;
1948 }1954 }
19491955
1950 pub fn lastToken(self: *NullLiteral) TokenIndex {1956 pub fn lastToken(self: *const NullLiteral) TokenIndex {
1951 return self.token;1957 return self.token;
1952 }1958 }
1953 };1959 };
...@@ -1960,11 +1966,11 @@ pub const Node = struct {...@@ -1960,11 +1966,11 @@ pub const Node = struct {
1960 return null;1966 return null;
1961 }1967 }
19621968
1963 pub fn firstToken(self: *UndefinedLiteral) TokenIndex {1969 pub fn firstToken(self: *const UndefinedLiteral) TokenIndex {
1964 return self.token;1970 return self.token;
1965 }1971 }
19661972
1967 pub fn lastToken(self: *UndefinedLiteral) TokenIndex {1973 pub fn lastToken(self: *const UndefinedLiteral) TokenIndex {
1968 return self.token;1974 return self.token;
1969 }1975 }
1970 };1976 };
...@@ -1977,11 +1983,11 @@ pub const Node = struct {...@@ -1977,11 +1983,11 @@ pub const Node = struct {
1977 return null;1983 return null;
1978 }1984 }
19791985
1980 pub fn firstToken(self: *ThisLiteral) TokenIndex {1986 pub fn firstToken(self: *const ThisLiteral) TokenIndex {
1981 return self.token;1987 return self.token;
1982 }1988 }
19831989
1984 pub fn lastToken(self: *ThisLiteral) TokenIndex {1990 pub fn lastToken(self: *const ThisLiteral) TokenIndex {
1985 return self.token;1991 return self.token;
1986 }1992 }
1987 };1993 };
...@@ -2022,11 +2028,11 @@ pub const Node = struct {...@@ -2022,11 +2028,11 @@ pub const Node = struct {
2022 return null;2028 return null;
2023 }2029 }
20242030
2025 pub fn firstToken(self: *AsmOutput) TokenIndex {2031 pub fn firstToken(self: *const AsmOutput) TokenIndex {
2026 return self.lbracket;2032 return self.lbracket;
2027 }2033 }
20282034
2029 pub fn lastToken(self: *AsmOutput) TokenIndex {2035 pub fn lastToken(self: *const AsmOutput) TokenIndex {
2030 return self.rparen;2036 return self.rparen;
2031 }2037 }
2032 };2038 };
...@@ -2054,11 +2060,11 @@ pub const Node = struct {...@@ -2054,11 +2060,11 @@ pub const Node = struct {
2054 return null;2060 return null;
2055 }2061 }
20562062
2057 pub fn firstToken(self: *AsmInput) TokenIndex {2063 pub fn firstToken(self: *const AsmInput) TokenIndex {
2058 return self.lbracket;2064 return self.lbracket;
2059 }2065 }
20602066
2061 pub fn lastToken(self: *AsmInput) TokenIndex {2067 pub fn lastToken(self: *const AsmInput) TokenIndex {
2062 return self.rparen;2068 return self.rparen;
2063 }2069 }
2064 };2070 };
...@@ -2089,11 +2095,11 @@ pub const Node = struct {...@@ -2089,11 +2095,11 @@ pub const Node = struct {
2089 return null;2095 return null;
2090 }2096 }
20912097
2092 pub fn firstToken(self: *Asm) TokenIndex {2098 pub fn firstToken(self: *const Asm) TokenIndex {
2093 return self.asm_token;2099 return self.asm_token;
2094 }2100 }
20952101
2096 pub fn lastToken(self: *Asm) TokenIndex {2102 pub fn lastToken(self: *const Asm) TokenIndex {
2097 return self.rparen;2103 return self.rparen;
2098 }2104 }
2099 };2105 };
...@@ -2106,11 +2112,11 @@ pub const Node = struct {...@@ -2106,11 +2112,11 @@ pub const Node = struct {
2106 return null;2112 return null;
2107 }2113 }
21082114
2109 pub fn firstToken(self: *Unreachable) TokenIndex {2115 pub fn firstToken(self: *const Unreachable) TokenIndex {
2110 return self.token;2116 return self.token;
2111 }2117 }
21122118
2113 pub fn lastToken(self: *Unreachable) TokenIndex {2119 pub fn lastToken(self: *const Unreachable) TokenIndex {
2114 return self.token;2120 return self.token;
2115 }2121 }
2116 };2122 };
...@@ -2123,11 +2129,11 @@ pub const Node = struct {...@@ -2123,11 +2129,11 @@ pub const Node = struct {
2123 return null;2129 return null;
2124 }2130 }
21252131
2126 pub fn firstToken(self: *ErrorType) TokenIndex {2132 pub fn firstToken(self: *const ErrorType) TokenIndex {
2127 return self.token;2133 return self.token;
2128 }2134 }
21292135
2130 pub fn lastToken(self: *ErrorType) TokenIndex {2136 pub fn lastToken(self: *const ErrorType) TokenIndex {
2131 return self.token;2137 return self.token;
2132 }2138 }
2133 };2139 };
...@@ -2140,11 +2146,11 @@ pub const Node = struct {...@@ -2140,11 +2146,11 @@ pub const Node = struct {
2140 return null;2146 return null;
2141 }2147 }
21422148
2143 pub fn firstToken(self: *VarType) TokenIndex {2149 pub fn firstToken(self: *const VarType) TokenIndex {
2144 return self.token;2150 return self.token;
2145 }2151 }
21462152
2147 pub fn lastToken(self: *VarType) TokenIndex {2153 pub fn lastToken(self: *const VarType) TokenIndex {
2148 return self.token;2154 return self.token;
2149 }2155 }
2150 };2156 };
...@@ -2159,11 +2165,11 @@ pub const Node = struct {...@@ -2159,11 +2165,11 @@ pub const Node = struct {
2159 return null;2165 return null;
2160 }2166 }
21612167
2162 pub fn firstToken(self: *DocComment) TokenIndex {2168 pub fn firstToken(self: *const DocComment) TokenIndex {
2163 return self.lines.at(0).*;2169 return self.lines.at(0).*;
2164 }2170 }
21652171
2166 pub fn lastToken(self: *DocComment) TokenIndex {2172 pub fn lastToken(self: *const DocComment) TokenIndex {
2167 return self.lines.at(self.lines.len - 1).*;2173 return self.lines.at(self.lines.len - 1).*;
2168 }2174 }
2169 };2175 };
...@@ -2184,11 +2190,11 @@ pub const Node = struct {...@@ -2184,11 +2190,11 @@ pub const Node = struct {
2184 return null;2190 return null;
2185 }2191 }
21862192
2187 pub fn firstToken(self: *TestDecl) TokenIndex {2193 pub fn firstToken(self: *const TestDecl) TokenIndex {
2188 return self.test_token;2194 return self.test_token;
2189 }2195 }
21902196
2191 pub fn lastToken(self: *TestDecl) TokenIndex {2197 pub fn lastToken(self: *const TestDecl) TokenIndex {
2192 return self.body_node.lastToken();2198 return self.body_node.lastToken();
2193 }2199 }
2194 };2200 };