authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-02-11 22:31:44+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-11 15:49:49-08:00
logb6448a533d4465c226b7b8613806ff0673261d6a
treee4e50873616f6165ed0703a09cd0fce3d143f6ce
parent4c8caf33437d8ce55450a51dfbf89db69c65680e

zig fmt: fix Tree.lastToken() for empty *Two nodes


1 files changed, 13 insertions(+), 12 deletions(-)

lib/std/zig/ast.zig+13-12
...@@ -676,20 +676,11 @@ pub const Tree = struct {...@@ -676,20 +676,11 @@ pub const Tree = struct {
676 },676 },
677 .ArrayInitDotTwo,677 .ArrayInitDotTwo,
678 .BlockTwo,678 .BlockTwo,
679 .BuiltinCallTwo,
679 .StructInitDotTwo,680 .StructInitDotTwo,
680 .ContainerDeclTwo,681 .ContainerDeclTwo,
681 .TaggedUnionTwo,682 .TaggedUnionTwo,
682 => {683 => {
683 end_offset += 1; // for the rparen/rbrace
684 if (datas[n].rhs != 0) {
685 n = datas[n].rhs;
686 } else if (datas[n].lhs != 0) {
687 n = datas[n].lhs;
688 } else {
689 return main_tokens[n] + end_offset;
690 }
691 },
692 .BuiltinCallTwo => {
693 if (datas[n].rhs != 0) {684 if (datas[n].rhs != 0) {
694 end_offset += 1; // for the rparen/rbrace685 end_offset += 1; // for the rparen/rbrace
695 n = datas[n].rhs;686 n = datas[n].rhs;
...@@ -697,7 +688,17 @@ pub const Tree = struct {...@@ -697,7 +688,17 @@ pub const Tree = struct {
697 end_offset += 1; // for the rparen/rbrace688 end_offset += 1; // for the rparen/rbrace
698 n = datas[n].lhs;689 n = datas[n].lhs;
699 } else {690 } else {
700 end_offset += 2; // for the lparen and rparen691 switch (tags[n]) {
692 .ArrayInitDotTwo,
693 .BlockTwo,
694 .StructInitDotTwo,
695 => end_offset += 1, // rbrace
696 .BuiltinCallTwo,
697 .ContainerDeclTwo,
698 => end_offset += 2, // lparen/lbrace + rparen/rbrace
699 .TaggedUnionTwo => end_offset += 5, // (enum) {}
700 else => unreachable,
701 }
701 return main_tokens[n] + end_offset;702 return main_tokens[n] + end_offset;
702 }703 }
703 },704 },
...@@ -2708,7 +2709,7 @@ pub const Node = struct {...@@ -2708,7 +2709,7 @@ pub const Node = struct {
2708 /// `{}`. `sub_list[lhs..rhs]`.2709 /// `{}`. `sub_list[lhs..rhs]`.
2709 /// main_token points at the lbrace.2710 /// main_token points at the lbrace.
2710 Block,2711 Block,
2711 /// Same as BlockTwo but there is known to be a semicolon before the rbrace.2712 /// Same as Block but there is known to be a semicolon before the rbrace.
2712 BlockSemicolon,2713 BlockSemicolon,
2713 /// `asm(lhs)`. rhs is the token index of the rparen.2714 /// `asm(lhs)`. rhs is the token index of the rparen.
2714 AsmSimple,2715 AsmSimple,