Skip to content

Commit 0a69a10

Browse files
authored
Merge pull request #4740 from Vexu/cleanup
Cleanup and a fix in self-hosted parser
2 parents 880d8fc + 57f9f07 commit 0a69a10

File tree

3 files changed

+402
-444
lines changed

3 files changed

+402
-444
lines changed

lib/std/zig/ast.zig

Lines changed: 66 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,11 @@ pub const Node = struct {
740740
var i = index;
741741

742742
switch (self.init_arg_expr) {
743-
InitArg.Type => |t| {
743+
.Type => |t| {
744744
if (i < 1) return t;
745745
i -= 1;
746746
},
747-
InitArg.None, InitArg.Enum => {},
747+
.None, .Enum => {},
748748
}
749749

750750
if (i < self.fields_and_decls.len) return self.fields_and_decls.at(i).*;
@@ -904,12 +904,7 @@ pub const Node = struct {
904904
}
905905

906906
switch (self.return_type) {
907-
// TODO allow this and next prong to share bodies since the types are the same
908-
ReturnType.Explicit => |node| {
909-
if (i < 1) return node;
910-
i -= 1;
911-
},
912-
ReturnType.InferErrorSet => |node| {
907+
.Explicit, .InferErrorSet => |node| {
913908
if (i < 1) return node;
914909
i -= 1;
915910
},
@@ -934,9 +929,7 @@ pub const Node = struct {
934929
pub fn lastToken(self: *const FnProto) TokenIndex {
935930
if (self.body_node) |body_node| return body_node.lastToken();
936931
switch (self.return_type) {
937-
// TODO allow this and next prong to share bodies since the types are the same
938-
ReturnType.Explicit => |node| return node.lastToken(),
939-
ReturnType.InferErrorSet => |node| return node.lastToken(),
932+
.Explicit, .InferErrorSet => |node| return node.lastToken(),
940933
}
941934
}
942935
};
@@ -1512,55 +1505,55 @@ pub const Node = struct {
15121505
i -= 1;
15131506

15141507
switch (self.op) {
1515-
Op.Catch => |maybe_payload| {
1508+
.Catch => |maybe_payload| {
15161509
if (maybe_payload) |payload| {
15171510
if (i < 1) return payload;
15181511
i -= 1;
15191512
}
15201513
},
15211514

1522-
Op.Add,
1523-
Op.AddWrap,
1524-
Op.ArrayCat,
1525-
Op.ArrayMult,
1526-
Op.Assign,
1527-
Op.AssignBitAnd,
1528-
Op.AssignBitOr,
1529-
Op.AssignBitShiftLeft,
1530-
Op.AssignBitShiftRight,
1531-
Op.AssignBitXor,
1532-
Op.AssignDiv,
1533-
Op.AssignSub,
1534-
Op.AssignSubWrap,
1535-
Op.AssignMod,
1536-
Op.AssignAdd,
1537-
Op.AssignAddWrap,
1538-
Op.AssignMul,
1539-
Op.AssignMulWrap,
1540-
Op.BangEqual,
1541-
Op.BitAnd,
1542-
Op.BitOr,
1543-
Op.BitShiftLeft,
1544-
Op.BitShiftRight,
1545-
Op.BitXor,
1546-
Op.BoolAnd,
1547-
Op.BoolOr,
1548-
Op.Div,
1549-
Op.EqualEqual,
1550-
Op.ErrorUnion,
1551-
Op.GreaterOrEqual,
1552-
Op.GreaterThan,
1553-
Op.LessOrEqual,
1554-
Op.LessThan,
1555-
Op.MergeErrorSets,
1556-
Op.Mod,
1557-
Op.Mul,
1558-
Op.MulWrap,
1559-
Op.Period,
1560-
Op.Range,
1561-
Op.Sub,
1562-
Op.SubWrap,
1563-
Op.UnwrapOptional,
1515+
.Add,
1516+
.AddWrap,
1517+
.ArrayCat,
1518+
.ArrayMult,
1519+
.Assign,
1520+
.AssignBitAnd,
1521+
.AssignBitOr,
1522+
.AssignBitShiftLeft,
1523+
.AssignBitShiftRight,
1524+
.AssignBitXor,
1525+
.AssignDiv,
1526+
.AssignSub,
1527+
.AssignSubWrap,
1528+
.AssignMod,
1529+
.AssignAdd,
1530+
.AssignAddWrap,
1531+
.AssignMul,
1532+
.AssignMulWrap,
1533+
.BangEqual,
1534+
.BitAnd,
1535+
.BitOr,
1536+
.BitShiftLeft,
1537+
.BitShiftRight,
1538+
.BitXor,
1539+
.BoolAnd,
1540+
.BoolOr,
1541+
.Div,
1542+
.EqualEqual,
1543+
.ErrorUnion,
1544+
.GreaterOrEqual,
1545+
.GreaterThan,
1546+
.LessOrEqual,
1547+
.LessThan,
1548+
.MergeErrorSets,
1549+
.Mod,
1550+
.Mul,
1551+
.MulWrap,
1552+
.Period,
1553+
.Range,
1554+
.Sub,
1555+
.SubWrap,
1556+
.UnwrapOptional,
15641557
=> {},
15651558
}
15661559

@@ -1591,7 +1584,6 @@ pub const Node = struct {
15911584
Await,
15921585
BitNot,
15931586
BoolNot,
1594-
Cancel,
15951587
OptionalType,
15961588
Negation,
15971589
NegationWrap,
@@ -1628,8 +1620,7 @@ pub const Node = struct {
16281620
var i = index;
16291621

16301622
switch (self.op) {
1631-
// TODO https://github.com/ziglang/zig/issues/1107
1632-
Op.SliceType => |addr_of_info| {
1623+
.PtrType, .SliceType => |addr_of_info| {
16331624
if (addr_of_info.sentinel) |sentinel| {
16341625
if (i < 1) return sentinel;
16351626
i -= 1;
@@ -1641,14 +1632,7 @@ pub const Node = struct {
16411632
}
16421633
},
16431634

1644-
Op.PtrType => |addr_of_info| {
1645-
if (addr_of_info.align_info) |align_info| {
1646-
if (i < 1) return align_info.node;
1647-
i -= 1;
1648-
}
1649-
},
1650-
1651-
Op.ArrayType => |array_info| {
1635+
.ArrayType => |array_info| {
16521636
if (i < 1) return array_info.len_expr;
16531637
i -= 1;
16541638
if (array_info.sentinel) |sentinel| {
@@ -1657,16 +1641,15 @@ pub const Node = struct {
16571641
}
16581642
},
16591643

1660-
Op.AddressOf,
1661-
Op.Await,
1662-
Op.BitNot,
1663-
Op.BoolNot,
1664-
Op.Cancel,
1665-
Op.OptionalType,
1666-
Op.Negation,
1667-
Op.NegationWrap,
1668-
Op.Try,
1669-
Op.Resume,
1644+
.AddressOf,
1645+
.Await,
1646+
.BitNot,
1647+
.BoolNot,
1648+
.OptionalType,
1649+
.Negation,
1650+
.NegationWrap,
1651+
.Try,
1652+
.Resume,
16701653
=> {},
16711654
}
16721655

@@ -1850,19 +1833,14 @@ pub const Node = struct {
18501833
var i = index;
18511834

18521835
switch (self.kind) {
1853-
Kind.Break => |maybe_label| {
1836+
.Break,
1837+
.Continue => |maybe_label| {
18541838
if (maybe_label) |label| {
18551839
if (i < 1) return label;
18561840
i -= 1;
18571841
}
18581842
},
1859-
Kind.Continue => |maybe_label| {
1860-
if (maybe_label) |label| {
1861-
if (i < 1) return label;
1862-
i -= 1;
1863-
}
1864-
},
1865-
Kind.Return => {},
1843+
.Return => {},
18661844
}
18671845

18681846
if (self.rhs) |rhs| {
@@ -1883,17 +1861,13 @@ pub const Node = struct {
18831861
}
18841862

18851863
switch (self.kind) {
1886-
Kind.Break => |maybe_label| {
1887-
if (maybe_label) |label| {
1888-
return label.lastToken();
1889-
}
1890-
},
1891-
Kind.Continue => |maybe_label| {
1864+
.Break,
1865+
.Continue => |maybe_label| {
18921866
if (maybe_label) |label| {
18931867
return label.lastToken();
18941868
}
18951869
},
1896-
Kind.Return => return self.ltoken,
1870+
.Return => return self.ltoken,
18971871
}
18981872

18991873
return self.ltoken;
@@ -2134,11 +2108,11 @@ pub const Node = struct {
21342108
i -= 1;
21352109

21362110
switch (self.kind) {
2137-
Kind.Variable => |variable_name| {
2111+
.Variable => |variable_name| {
21382112
if (i < 1) return &variable_name.base;
21392113
i -= 1;
21402114
},
2141-
Kind.Return => |return_type| {
2115+
.Return => |return_type| {
21422116
if (i < 1) return return_type;
21432117
i -= 1;
21442118
},

0 commit comments

Comments
 (0)