| author | |
| committer | |
| log | cf0d300ddecf3e1bf0363002c995425dab007b74 |
| tree | 1911b3595996594dffb1390699849c46eba8ad0a |
| parent | 33d9dda5584a6c21df1a4d14ab1a251772f76d4d |
| parent | e57e3602e7802789d56a076c6052092715997c24 |
| signature |
Translate-c-2 enums7 files changed, 482 insertions(+), 252 deletions(-)
lib/std/zig/ast.zig+46-46| ... | @@ -581,7 +581,7 @@ pub const Node = struct { | ... | @@ -581,7 +581,7 @@ pub const Node = struct { |
| 581 | } | 581 | } |
| 582 | 582 | ||
| 583 | pub const Root = struct { | 583 | pub const Root = struct { |
| 584 | base: Node, | 584 | base: Node = Node {.id = .Root}, |
| 585 | decls: DeclList, | 585 | decls: DeclList, |
| 586 | eof_token: TokenIndex, | 586 | eof_token: TokenIndex, |
| 587 | 587 | ||
| ... | @@ -604,7 +604,7 @@ pub const Node = struct { | ... | @@ -604,7 +604,7 @@ pub const Node = struct { |
| 604 | }; | 604 | }; |
| 605 | 605 | ||
| 606 | pub const VarDecl = struct { | 606 | pub const VarDecl = struct { |
| 607 | base: Node, | 607 | base: Node = Node {.id = .VarDecl}, |
| 608 | doc_comments: ?*DocComment, | 608 | doc_comments: ?*DocComment, |
| 609 | visib_token: ?TokenIndex, | 609 | visib_token: ?TokenIndex, |
| 610 | thread_local_token: ?TokenIndex, | 610 | thread_local_token: ?TokenIndex, |
| ... | @@ -661,7 +661,7 @@ pub const Node = struct { | ... | @@ -661,7 +661,7 @@ pub const Node = struct { |
| 661 | }; | 661 | }; |
| 662 | 662 | ||
| 663 | pub const Use = struct { | 663 | pub const Use = struct { |
| 664 | base: Node, | 664 | base: Node = Node {.id = .Use}, |
| 665 | doc_comments: ?*DocComment, | 665 | doc_comments: ?*DocComment, |
| 666 | visib_token: ?TokenIndex, | 666 | visib_token: ?TokenIndex, |
| 667 | use_token: TokenIndex, | 667 | use_token: TokenIndex, |
| ... | @@ -688,7 +688,7 @@ pub const Node = struct { | ... | @@ -688,7 +688,7 @@ pub const Node = struct { |
| 688 | }; | 688 | }; |
| 689 | 689 | ||
| 690 | pub const ErrorSetDecl = struct { | 690 | pub const ErrorSetDecl = struct { |
| 691 | base: Node, | 691 | base: Node = Node {.id = .ErrorSetDecl}, |
| 692 | error_token: TokenIndex, | 692 | error_token: TokenIndex, |
| 693 | decls: DeclList, | 693 | decls: DeclList, |
| 694 | rbrace_token: TokenIndex, | 694 | rbrace_token: TokenIndex, |
| ... | @@ -714,7 +714,7 @@ pub const Node = struct { | ... | @@ -714,7 +714,7 @@ pub const Node = struct { |
| 714 | }; | 714 | }; |
| 715 | 715 | ||
| 716 | pub const ContainerDecl = struct { | 716 | pub const ContainerDecl = struct { |
| 717 | base: Node, | 717 | base: Node = Node {.id = .ContainerDecl}, |
| 718 | layout_token: ?TokenIndex, | 718 | layout_token: ?TokenIndex, |
| 719 | kind_token: TokenIndex, | 719 | kind_token: TokenIndex, |
| 720 | init_arg_expr: InitArg, | 720 | init_arg_expr: InitArg, |
| ... | @@ -801,7 +801,7 @@ pub const Node = struct { | ... | @@ -801,7 +801,7 @@ pub const Node = struct { |
| 801 | }; | 801 | }; |
| 802 | 802 | ||
| 803 | pub const ErrorTag = struct { | 803 | pub const ErrorTag = struct { |
| 804 | base: Node, | 804 | base: Node = Node {.id = .ErrorTag}, |
| 805 | doc_comments: ?*DocComment, | 805 | doc_comments: ?*DocComment, |
| 806 | name_token: TokenIndex, | 806 | name_token: TokenIndex, |
| 807 | 807 | ||
| ... | @@ -826,7 +826,7 @@ pub const Node = struct { | ... | @@ -826,7 +826,7 @@ pub const Node = struct { |
| 826 | }; | 826 | }; |
| 827 | 827 | ||
| 828 | pub const Identifier = struct { | 828 | pub const Identifier = struct { |
| 829 | base: Node, | 829 | base: Node = Node {.id = .Identifier}, |
| 830 | token: TokenIndex, | 830 | token: TokenIndex, |
| 831 | 831 | ||
| 832 | pub fn iterate(self: *Identifier, index: usize) ?*Node { | 832 | pub fn iterate(self: *Identifier, index: usize) ?*Node { |
| ... | @@ -843,7 +843,7 @@ pub const Node = struct { | ... | @@ -843,7 +843,7 @@ pub const Node = struct { |
| 843 | }; | 843 | }; |
| 844 | 844 | ||
| 845 | pub const FnProto = struct { | 845 | pub const FnProto = struct { |
| 846 | base: Node, | 846 | base: Node = Node {.id = .FnProto}, |
| 847 | doc_comments: ?*DocComment, | 847 | doc_comments: ?*DocComment, |
| 848 | visib_token: ?TokenIndex, | 848 | visib_token: ?TokenIndex, |
| 849 | fn_token: TokenIndex, | 849 | fn_token: TokenIndex, |
| ... | @@ -925,7 +925,7 @@ pub const Node = struct { | ... | @@ -925,7 +925,7 @@ pub const Node = struct { |
| 925 | }; | 925 | }; |
| 926 | 926 | ||
| 927 | pub const AnyFrameType = struct { | 927 | pub const AnyFrameType = struct { |
| 928 | base: Node, | 928 | base: Node = Node {.id = .AnyFrameType}, |
| 929 | anyframe_token: TokenIndex, | 929 | anyframe_token: TokenIndex, |
| 930 | result: ?Result, | 930 | result: ?Result, |
| 931 | 931 | ||
| ... | @@ -956,7 +956,7 @@ pub const Node = struct { | ... | @@ -956,7 +956,7 @@ pub const Node = struct { |
| 956 | }; | 956 | }; |
| 957 | 957 | ||
| 958 | pub const ParamDecl = struct { | 958 | pub const ParamDecl = struct { |
| 959 | base: Node, | 959 | base: Node = Node {.id = .ParamDecl}, |
| 960 | doc_comments: ?*DocComment, | 960 | doc_comments: ?*DocComment, |
| 961 | comptime_token: ?TokenIndex, | 961 | comptime_token: ?TokenIndex, |
| 962 | noalias_token: ?TokenIndex, | 962 | noalias_token: ?TokenIndex, |
| ... | @@ -989,7 +989,7 @@ pub const Node = struct { | ... | @@ -989,7 +989,7 @@ pub const Node = struct { |
| 989 | }; | 989 | }; |
| 990 | 990 | ||
| 991 | pub const Block = struct { | 991 | pub const Block = struct { |
| 992 | base: Node, | 992 | base: Node = Node {.id = .Block}, |
| 993 | label: ?TokenIndex, | 993 | label: ?TokenIndex, |
| 994 | lbrace: TokenIndex, | 994 | lbrace: TokenIndex, |
| 995 | statements: StatementList, | 995 | statements: StatementList, |
| ... | @@ -1020,7 +1020,7 @@ pub const Node = struct { | ... | @@ -1020,7 +1020,7 @@ pub const Node = struct { |
| 1020 | }; | 1020 | }; |
| 1021 | 1021 | ||
| 1022 | pub const Defer = struct { | 1022 | pub const Defer = struct { |
| 1023 | base: Node, | 1023 | base: Node = Node {.id = .Defer}, |
| 1024 | defer_token: TokenIndex, | 1024 | defer_token: TokenIndex, |
| 1025 | expr: *Node, | 1025 | expr: *Node, |
| 1026 | 1026 | ||
| ... | @@ -1043,7 +1043,7 @@ pub const Node = struct { | ... | @@ -1043,7 +1043,7 @@ pub const Node = struct { |
| 1043 | }; | 1043 | }; |
| 1044 | 1044 | ||
| 1045 | pub const Comptime = struct { | 1045 | pub const Comptime = struct { |
| 1046 | base: Node, | 1046 | base: Node = Node {.id = .Comptime}, |
| 1047 | doc_comments: ?*DocComment, | 1047 | doc_comments: ?*DocComment, |
| 1048 | comptime_token: TokenIndex, | 1048 | comptime_token: TokenIndex, |
| 1049 | expr: *Node, | 1049 | expr: *Node, |
| ... | @@ -1067,7 +1067,7 @@ pub const Node = struct { | ... | @@ -1067,7 +1067,7 @@ pub const Node = struct { |
| 1067 | }; | 1067 | }; |
| 1068 | 1068 | ||
| 1069 | pub const Payload = struct { | 1069 | pub const Payload = struct { |
| 1070 | base: Node, | 1070 | base: Node = Node {.id = .Payload}, |
| 1071 | lpipe: TokenIndex, | 1071 | lpipe: TokenIndex, |
| 1072 | error_symbol: *Node, | 1072 | error_symbol: *Node, |
| 1073 | rpipe: TokenIndex, | 1073 | rpipe: TokenIndex, |
| ... | @@ -1091,7 +1091,7 @@ pub const Node = struct { | ... | @@ -1091,7 +1091,7 @@ pub const Node = struct { |
| 1091 | }; | 1091 | }; |
| 1092 | 1092 | ||
| 1093 | pub const PointerPayload = struct { | 1093 | pub const PointerPayload = struct { |
| 1094 | base: Node, | 1094 | base: Node = Node {.id = .PointerPayload}, |
| 1095 | lpipe: TokenIndex, | 1095 | lpipe: TokenIndex, |
| 1096 | ptr_token: ?TokenIndex, | 1096 | ptr_token: ?TokenIndex, |
| 1097 | value_symbol: *Node, | 1097 | value_symbol: *Node, |
| ... | @@ -1116,7 +1116,7 @@ pub const Node = struct { | ... | @@ -1116,7 +1116,7 @@ pub const Node = struct { |
| 1116 | }; | 1116 | }; |
| 1117 | 1117 | ||
| 1118 | pub const PointerIndexPayload = struct { | 1118 | pub const PointerIndexPayload = struct { |
| 1119 | base: Node, | 1119 | base: Node = Node {.id = .PointerIndexPayload}, |
| 1120 | lpipe: TokenIndex, | 1120 | lpipe: TokenIndex, |
| 1121 | ptr_token: ?TokenIndex, | 1121 | ptr_token: ?TokenIndex, |
| 1122 | value_symbol: *Node, | 1122 | value_symbol: *Node, |
| ... | @@ -1147,7 +1147,7 @@ pub const Node = struct { | ... | @@ -1147,7 +1147,7 @@ pub const Node = struct { |
| 1147 | }; | 1147 | }; |
| 1148 | 1148 | ||
| 1149 | pub const Else = struct { | 1149 | pub const Else = struct { |
| 1150 | base: Node, | 1150 | base: Node = Node {.id = .Else}, |
| 1151 | else_token: TokenIndex, | 1151 | else_token: TokenIndex, |
| 1152 | payload: ?*Node, | 1152 | payload: ?*Node, |
| 1153 | body: *Node, | 1153 | body: *Node, |
| ... | @@ -1176,7 +1176,7 @@ pub const Node = struct { | ... | @@ -1176,7 +1176,7 @@ pub const Node = struct { |
| 1176 | }; | 1176 | }; |
| 1177 | 1177 | ||
| 1178 | pub const Switch = struct { | 1178 | pub const Switch = struct { |
| 1179 | base: Node, | 1179 | base: Node = Node {.id = .Switch}, |
| 1180 | switch_token: TokenIndex, | 1180 | switch_token: TokenIndex, |
| 1181 | expr: *Node, | 1181 | expr: *Node, |
| 1182 | 1182 | ||
| ... | @@ -1208,7 +1208,7 @@ pub const Node = struct { | ... | @@ -1208,7 +1208,7 @@ pub const Node = struct { |
| 1208 | }; | 1208 | }; |
| 1209 | 1209 | ||
| 1210 | pub const SwitchCase = struct { | 1210 | pub const SwitchCase = struct { |
| 1211 | base: Node, | 1211 | base: Node = Node {.id = .SwitchCase}, |
| 1212 | items: ItemList, | 1212 | items: ItemList, |
| 1213 | arrow_token: TokenIndex, | 1213 | arrow_token: TokenIndex, |
| 1214 | payload: ?*Node, | 1214 | payload: ?*Node, |
| ... | @@ -1243,7 +1243,7 @@ pub const Node = struct { | ... | @@ -1243,7 +1243,7 @@ pub const Node = struct { |
| 1243 | }; | 1243 | }; |
| 1244 | 1244 | ||
| 1245 | pub const SwitchElse = struct { | 1245 | pub const SwitchElse = struct { |
| 1246 | base: Node, | 1246 | base: Node = Node {.id = .SwitchElse}, |
| 1247 | token: TokenIndex, | 1247 | token: TokenIndex, |
| 1248 | 1248 | ||
| 1249 | pub fn iterate(self: *SwitchElse, index: usize) ?*Node { | 1249 | pub fn iterate(self: *SwitchElse, index: usize) ?*Node { |
| ... | @@ -1260,7 +1260,7 @@ pub const Node = struct { | ... | @@ -1260,7 +1260,7 @@ pub const Node = struct { |
| 1260 | }; | 1260 | }; |
| 1261 | 1261 | ||
| 1262 | pub const While = struct { | 1262 | pub const While = struct { |
| 1263 | base: Node, | 1263 | base: Node = Node {.id = .While}, |
| 1264 | label: ?TokenIndex, | 1264 | label: ?TokenIndex, |
| 1265 | inline_token: ?TokenIndex, | 1265 | inline_token: ?TokenIndex, |
| 1266 | while_token: TokenIndex, | 1266 | while_token: TokenIndex, |
| ... | @@ -1319,7 +1319,7 @@ pub const Node = struct { | ... | @@ -1319,7 +1319,7 @@ pub const Node = struct { |
| 1319 | }; | 1319 | }; |
| 1320 | 1320 | ||
| 1321 | pub const For = struct { | 1321 | pub const For = struct { |
| 1322 | base: Node, | 1322 | base: Node = Node {.id = .For}, |
| 1323 | label: ?TokenIndex, | 1323 | label: ?TokenIndex, |
| 1324 | inline_token: ?TokenIndex, | 1324 | inline_token: ?TokenIndex, |
| 1325 | for_token: TokenIndex, | 1325 | for_token: TokenIndex, |
| ... | @@ -1370,7 +1370,7 @@ pub const Node = struct { | ... | @@ -1370,7 +1370,7 @@ pub const Node = struct { |
| 1370 | }; | 1370 | }; |
| 1371 | 1371 | ||
| 1372 | pub const If = struct { | 1372 | pub const If = struct { |
| 1373 | base: Node, | 1373 | base: Node = Node {.id = .If}, |
| 1374 | if_token: TokenIndex, | 1374 | if_token: TokenIndex, |
| 1375 | condition: *Node, | 1375 | condition: *Node, |
| 1376 | payload: ?*Node, | 1376 | payload: ?*Node, |
| ... | @@ -1413,7 +1413,7 @@ pub const Node = struct { | ... | @@ -1413,7 +1413,7 @@ pub const Node = struct { |
| 1413 | }; | 1413 | }; |
| 1414 | 1414 | ||
| 1415 | pub const InfixOp = struct { | 1415 | pub const InfixOp = struct { |
| 1416 | base: Node, | 1416 | base: Node = Node {.id = .InfixOp}, |
| 1417 | op_token: TokenIndex, | 1417 | op_token: TokenIndex, |
| 1418 | lhs: *Node, | 1418 | lhs: *Node, |
| 1419 | op: Op, | 1419 | op: Op, |
| ... | @@ -1646,7 +1646,7 @@ pub const Node = struct { | ... | @@ -1646,7 +1646,7 @@ pub const Node = struct { |
| 1646 | }; | 1646 | }; |
| 1647 | 1647 | ||
| 1648 | pub const FieldInitializer = struct { | 1648 | pub const FieldInitializer = struct { |
| 1649 | base: Node, | 1649 | base: Node = Node {.id = .FieldInitializer}, |
| 1650 | period_token: TokenIndex, | 1650 | period_token: TokenIndex, |
| 1651 | name_token: TokenIndex, | 1651 | name_token: TokenIndex, |
| 1652 | expr: *Node, | 1652 | expr: *Node, |
| ... | @@ -1670,7 +1670,7 @@ pub const Node = struct { | ... | @@ -1670,7 +1670,7 @@ pub const Node = struct { |
| 1670 | }; | 1670 | }; |
| 1671 | 1671 | ||
| 1672 | pub const SuffixOp = struct { | 1672 | pub const SuffixOp = struct { |
| 1673 | base: Node, | 1673 | base: Node = Node {.id = .SuffixOp}, |
| 1674 | lhs: Lhs, | 1674 | lhs: Lhs, |
| 1675 | op: Op, | 1675 | op: Op, |
| 1676 | rtoken: TokenIndex, | 1676 | rtoken: TokenIndex, |
| ... | @@ -1766,7 +1766,7 @@ pub const Node = struct { | ... | @@ -1766,7 +1766,7 @@ pub const Node = struct { |
| 1766 | }; | 1766 | }; |
| 1767 | 1767 | ||
| 1768 | pub const GroupedExpression = struct { | 1768 | pub const GroupedExpression = struct { |
| 1769 | base: Node, | 1769 | base: Node = Node {.id = .GroupedExpression}, |
| 1770 | lparen: TokenIndex, | 1770 | lparen: TokenIndex, |
| 1771 | expr: *Node, | 1771 | expr: *Node, |
| 1772 | rparen: TokenIndex, | 1772 | rparen: TokenIndex, |
| ... | @@ -1790,7 +1790,7 @@ pub const Node = struct { | ... | @@ -1790,7 +1790,7 @@ pub const Node = struct { |
| 1790 | }; | 1790 | }; |
| 1791 | 1791 | ||
| 1792 | pub const ControlFlowExpression = struct { | 1792 | pub const ControlFlowExpression = struct { |
| 1793 | base: Node, | 1793 | base: Node = Node {.id = .ControlFlowExpression}, |
| 1794 | ltoken: TokenIndex, | 1794 | ltoken: TokenIndex, |
| 1795 | kind: Kind, | 1795 | kind: Kind, |
| 1796 | rhs: ?*Node, | 1796 | rhs: ?*Node, |
| ... | @@ -1856,7 +1856,7 @@ pub const Node = struct { | ... | @@ -1856,7 +1856,7 @@ pub const Node = struct { |
| 1856 | }; | 1856 | }; |
| 1857 | 1857 | ||
| 1858 | pub const Suspend = struct { | 1858 | pub const Suspend = struct { |
| 1859 | base: Node, | 1859 | base: Node = Node {.id = .Suspend}, |
| 1860 | suspend_token: TokenIndex, | 1860 | suspend_token: TokenIndex, |
| 1861 | body: ?*Node, | 1861 | body: ?*Node, |
| 1862 | 1862 | ||
| ... | @@ -1885,7 +1885,7 @@ pub const Node = struct { | ... | @@ -1885,7 +1885,7 @@ pub const Node = struct { |
| 1885 | }; | 1885 | }; |
| 1886 | 1886 | ||
| 1887 | pub const IntegerLiteral = struct { | 1887 | pub const IntegerLiteral = struct { |
| 1888 | base: Node, | 1888 | base: Node = Node {.id = .IntegerLiteral}, |
| 1889 | token: TokenIndex, | 1889 | token: TokenIndex, |
| 1890 | 1890 | ||
| 1891 | pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node { | 1891 | pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node { |
| ... | @@ -1902,7 +1902,7 @@ pub const Node = struct { | ... | @@ -1902,7 +1902,7 @@ pub const Node = struct { |
| 1902 | }; | 1902 | }; |
| 1903 | 1903 | ||
| 1904 | pub const EnumLiteral = struct { | 1904 | pub const EnumLiteral = struct { |
| 1905 | base: Node, | 1905 | base: Node = Node {.id = .EnumLiteral}, |
| 1906 | dot: TokenIndex, | 1906 | dot: TokenIndex, |
| 1907 | name: TokenIndex, | 1907 | name: TokenIndex, |
| 1908 | 1908 | ||
| ... | @@ -1920,7 +1920,7 @@ pub const Node = struct { | ... | @@ -1920,7 +1920,7 @@ pub const Node = struct { |
| 1920 | }; | 1920 | }; |
| 1921 | 1921 | ||
| 1922 | pub const FloatLiteral = struct { | 1922 | pub const FloatLiteral = struct { |
| 1923 | base: Node, | 1923 | base: Node = Node {.id = .FloatLiteral}, |
| 1924 | token: TokenIndex, | 1924 | token: TokenIndex, |
| 1925 | 1925 | ||
| 1926 | pub fn iterate(self: *FloatLiteral, index: usize) ?*Node { | 1926 | pub fn iterate(self: *FloatLiteral, index: usize) ?*Node { |
| ... | @@ -1937,7 +1937,7 @@ pub const Node = struct { | ... | @@ -1937,7 +1937,7 @@ pub const Node = struct { |
| 1937 | }; | 1937 | }; |
| 1938 | 1938 | ||
| 1939 | pub const BuiltinCall = struct { | 1939 | pub const BuiltinCall = struct { |
| 1940 | base: Node, | 1940 | base: Node = Node {.id = .BuiltinCall}, |
| 1941 | builtin_token: TokenIndex, | 1941 | builtin_token: TokenIndex, |
| 1942 | params: ParamList, | 1942 | params: ParamList, |
| 1943 | rparen_token: TokenIndex, | 1943 | rparen_token: TokenIndex, |
| ... | @@ -1963,7 +1963,7 @@ pub const Node = struct { | ... | @@ -1963,7 +1963,7 @@ pub const Node = struct { |
| 1963 | }; | 1963 | }; |
| 1964 | 1964 | ||
| 1965 | pub const StringLiteral = struct { | 1965 | pub const StringLiteral = struct { |
| 1966 | base: Node, | 1966 | base: Node = Node {.id = .StringLiteral}, |
| 1967 | token: TokenIndex, | 1967 | token: TokenIndex, |
| 1968 | 1968 | ||
| 1969 | pub fn iterate(self: *StringLiteral, index: usize) ?*Node { | 1969 | pub fn iterate(self: *StringLiteral, index: usize) ?*Node { |
| ... | @@ -1980,7 +1980,7 @@ pub const Node = struct { | ... | @@ -1980,7 +1980,7 @@ pub const Node = struct { |
| 1980 | }; | 1980 | }; |
| 1981 | 1981 | ||
| 1982 | pub const MultilineStringLiteral = struct { | 1982 | pub const MultilineStringLiteral = struct { |
| 1983 | base: Node, | 1983 | base: Node = Node {.id = .MultilineStringLiteral}, |
| 1984 | lines: LineList, | 1984 | lines: LineList, |
| 1985 | 1985 | ||
| 1986 | pub const LineList = SegmentedList(TokenIndex, 4); | 1986 | pub const LineList = SegmentedList(TokenIndex, 4); |
| ... | @@ -1999,7 +1999,7 @@ pub const Node = struct { | ... | @@ -1999,7 +1999,7 @@ pub const Node = struct { |
| 1999 | }; | 1999 | }; |
| 2000 | 2000 | ||
| 2001 | pub const CharLiteral = struct { | 2001 | pub const CharLiteral = struct { |
| 2002 | base: Node, | 2002 | base: Node = Node {.id = .CharLiteral}, |
| 2003 | token: TokenIndex, | 2003 | token: TokenIndex, |
| 2004 | 2004 | ||
| 2005 | pub fn iterate(self: *CharLiteral, index: usize) ?*Node { | 2005 | pub fn iterate(self: *CharLiteral, index: usize) ?*Node { |
| ... | @@ -2016,7 +2016,7 @@ pub const Node = struct { | ... | @@ -2016,7 +2016,7 @@ pub const Node = struct { |
| 2016 | }; | 2016 | }; |
| 2017 | 2017 | ||
| 2018 | pub const BoolLiteral = struct { | 2018 | pub const BoolLiteral = struct { |
| 2019 | base: Node, | 2019 | base: Node = Node {.id = .BoolLiteral}, |
| 2020 | token: TokenIndex, | 2020 | token: TokenIndex, |
| 2021 | 2021 | ||
| 2022 | pub fn iterate(self: *BoolLiteral, index: usize) ?*Node { | 2022 | pub fn iterate(self: *BoolLiteral, index: usize) ?*Node { |
| ... | @@ -2033,7 +2033,7 @@ pub const Node = struct { | ... | @@ -2033,7 +2033,7 @@ pub const Node = struct { |
| 2033 | }; | 2033 | }; |
| 2034 | 2034 | ||
| 2035 | pub const NullLiteral = struct { | 2035 | pub const NullLiteral = struct { |
| 2036 | base: Node, | 2036 | base: Node = Node {.id = .NullLiteral}, |
| 2037 | token: TokenIndex, | 2037 | token: TokenIndex, |
| 2038 | 2038 | ||
| 2039 | pub fn iterate(self: *NullLiteral, index: usize) ?*Node { | 2039 | pub fn iterate(self: *NullLiteral, index: usize) ?*Node { |
| ... | @@ -2050,7 +2050,7 @@ pub const Node = struct { | ... | @@ -2050,7 +2050,7 @@ pub const Node = struct { |
| 2050 | }; | 2050 | }; |
| 2051 | 2051 | ||
| 2052 | pub const UndefinedLiteral = struct { | 2052 | pub const UndefinedLiteral = struct { |
| 2053 | base: Node, | 2053 | base: Node = Node {.id = .UndefinedLiteral}, |
| 2054 | token: TokenIndex, | 2054 | token: TokenIndex, |
| 2055 | 2055 | ||
| 2056 | pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node { | 2056 | pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node { |
| ... | @@ -2067,7 +2067,7 @@ pub const Node = struct { | ... | @@ -2067,7 +2067,7 @@ pub const Node = struct { |
| 2067 | }; | 2067 | }; |
| 2068 | 2068 | ||
| 2069 | pub const AsmOutput = struct { | 2069 | pub const AsmOutput = struct { |
| 2070 | base: Node, | 2070 | base: Node = Node {.id = .AsmOutput}, |
| 2071 | lbracket: TokenIndex, | 2071 | lbracket: TokenIndex, |
| 2072 | symbolic_name: *Node, | 2072 | symbolic_name: *Node, |
| 2073 | constraint: *Node, | 2073 | constraint: *Node, |
| ... | @@ -2112,7 +2112,7 @@ pub const Node = struct { | ... | @@ -2112,7 +2112,7 @@ pub const Node = struct { |
| 2112 | }; | 2112 | }; |
| 2113 | 2113 | ||
| 2114 | pub const AsmInput = struct { | 2114 | pub const AsmInput = struct { |
| 2115 | base: Node, | 2115 | base: Node = Node {.id = .AsmInput}, |
| 2116 | lbracket: TokenIndex, | 2116 | lbracket: TokenIndex, |
| 2117 | symbolic_name: *Node, | 2117 | symbolic_name: *Node, |
| 2118 | constraint: *Node, | 2118 | constraint: *Node, |
| ... | @@ -2144,7 +2144,7 @@ pub const Node = struct { | ... | @@ -2144,7 +2144,7 @@ pub const Node = struct { |
| 2144 | }; | 2144 | }; |
| 2145 | 2145 | ||
| 2146 | pub const Asm = struct { | 2146 | pub const Asm = struct { |
| 2147 | base: Node, | 2147 | base: Node = Node {.id = .Asm}, |
| 2148 | asm_token: TokenIndex, | 2148 | asm_token: TokenIndex, |
| 2149 | volatile_token: ?TokenIndex, | 2149 | volatile_token: ?TokenIndex, |
| 2150 | template: *Node, | 2150 | template: *Node, |
| ... | @@ -2179,7 +2179,7 @@ pub const Node = struct { | ... | @@ -2179,7 +2179,7 @@ pub const Node = struct { |
| 2179 | }; | 2179 | }; |
| 2180 | 2180 | ||
| 2181 | pub const Unreachable = struct { | 2181 | pub const Unreachable = struct { |
| 2182 | base: Node, | 2182 | base: Node = Node {.id = .Unreachable}, |
| 2183 | token: TokenIndex, | 2183 | token: TokenIndex, |
| 2184 | 2184 | ||
| 2185 | pub fn iterate(self: *Unreachable, index: usize) ?*Node { | 2185 | pub fn iterate(self: *Unreachable, index: usize) ?*Node { |
| ... | @@ -2196,7 +2196,7 @@ pub const Node = struct { | ... | @@ -2196,7 +2196,7 @@ pub const Node = struct { |
| 2196 | }; | 2196 | }; |
| 2197 | 2197 | ||
| 2198 | pub const ErrorType = struct { | 2198 | pub const ErrorType = struct { |
| 2199 | base: Node, | 2199 | base: Node = Node {.id = .ErrorType}, |
| 2200 | token: TokenIndex, | 2200 | token: TokenIndex, |
| 2201 | 2201 | ||
| 2202 | pub fn iterate(self: *ErrorType, index: usize) ?*Node { | 2202 | pub fn iterate(self: *ErrorType, index: usize) ?*Node { |
| ... | @@ -2230,7 +2230,7 @@ pub const Node = struct { | ... | @@ -2230,7 +2230,7 @@ pub const Node = struct { |
| 2230 | }; | 2230 | }; |
| 2231 | 2231 | ||
| 2232 | pub const DocComment = struct { | 2232 | pub const DocComment = struct { |
| 2233 | base: Node, | 2233 | base: Node = Node {.id = .DocComment}, |
| 2234 | lines: LineList, | 2234 | lines: LineList, |
| 2235 | 2235 | ||
| 2236 | pub const LineList = SegmentedList(TokenIndex, 4); | 2236 | pub const LineList = SegmentedList(TokenIndex, 4); |
| ... | @@ -2249,7 +2249,7 @@ pub const Node = struct { | ... | @@ -2249,7 +2249,7 @@ pub const Node = struct { |
| 2249 | }; | 2249 | }; |
| 2250 | 2250 | ||
| 2251 | pub const TestDecl = struct { | 2251 | pub const TestDecl = struct { |
| 2252 | base: Node, | 2252 | base: Node = Node {.id = .TestDecl}, |
| 2253 | doc_comments: ?*DocComment, | 2253 | doc_comments: ?*DocComment, |
| 2254 | test_token: TokenIndex, | 2254 | test_token: TokenIndex, |
| 2255 | name: *Node, | 2255 | name: *Node, |
lib/std/zig/parse.zig-72| ... | @@ -56,7 +56,6 @@ pub fn parse(allocator: *Allocator, source: []const u8) !*Tree { | ... | @@ -56,7 +56,6 @@ pub fn parse(allocator: *Allocator, source: []const u8) !*Tree { |
| 56 | fn parseRoot(arena: *Allocator, it: *TokenIterator, tree: *Tree) Allocator.Error!*Node.Root { | 56 | fn parseRoot(arena: *Allocator, it: *TokenIterator, tree: *Tree) Allocator.Error!*Node.Root { |
| 57 | const node = try arena.create(Node.Root); | 57 | const node = try arena.create(Node.Root); |
| 58 | node.* = Node.Root{ | 58 | node.* = Node.Root{ |
| 59 | .base = Node{ .id = .Root }, | ||
| 60 | .decls = undefined, | 59 | .decls = undefined, |
| 61 | .eof_token = undefined, | 60 | .eof_token = undefined, |
| 62 | }; | 61 | }; |
| ... | @@ -176,7 +175,6 @@ fn parseContainerDocComments(arena: *Allocator, it: *TokenIterator, tree: *Tree) | ... | @@ -176,7 +175,6 @@ fn parseContainerDocComments(arena: *Allocator, it: *TokenIterator, tree: *Tree) |
| 176 | 175 | ||
| 177 | const node = try arena.create(Node.DocComment); | 176 | const node = try arena.create(Node.DocComment); |
| 178 | node.* = Node.DocComment{ | 177 | node.* = Node.DocComment{ |
| 179 | .base = Node{ .id = .DocComment }, | ||
| 180 | .lines = lines, | 178 | .lines = lines, |
| 181 | }; | 179 | }; |
| 182 | return &node.base; | 180 | return &node.base; |
| ... | @@ -194,7 +192,6 @@ fn parseTestDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -194,7 +192,6 @@ fn parseTestDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 194 | 192 | ||
| 195 | const test_node = try arena.create(Node.TestDecl); | 193 | const test_node = try arena.create(Node.TestDecl); |
| 196 | test_node.* = Node.TestDecl{ | 194 | test_node.* = Node.TestDecl{ |
| 197 | .base = Node{ .id = .TestDecl }, | ||
| 198 | .doc_comments = null, | 195 | .doc_comments = null, |
| 199 | .test_token = test_token, | 196 | .test_token = test_token, |
| 200 | .name = name_node, | 197 | .name = name_node, |
| ... | @@ -217,7 +214,6 @@ fn parseTopLevelComptime(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?* | ... | @@ -217,7 +214,6 @@ fn parseTopLevelComptime(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?* |
| 217 | 214 | ||
| 218 | const comptime_node = try arena.create(Node.Comptime); | 215 | const comptime_node = try arena.create(Node.Comptime); |
| 219 | comptime_node.* = Node.Comptime{ | 216 | comptime_node.* = Node.Comptime{ |
| 220 | .base = Node{ .id = .Comptime }, | ||
| 221 | .doc_comments = null, | 217 | .doc_comments = null, |
| 222 | .comptime_token = tok, | 218 | .comptime_token = tok, |
| 223 | .expr = block_node, | 219 | .expr = block_node, |
| ... | @@ -338,7 +334,6 @@ fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -338,7 +334,6 @@ fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 338 | 334 | ||
| 339 | const fn_proto_node = try arena.create(Node.FnProto); | 335 | const fn_proto_node = try arena.create(Node.FnProto); |
| 340 | fn_proto_node.* = Node.FnProto{ | 336 | fn_proto_node.* = Node.FnProto{ |
| 341 | .base = Node{ .id = .FnProto }, | ||
| 342 | .doc_comments = null, | 337 | .doc_comments = null, |
| 343 | .visib_token = null, | 338 | .visib_token = null, |
| 344 | .fn_token = fn_token, | 339 | .fn_token = fn_token, |
| ... | @@ -389,7 +384,6 @@ fn parseVarDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -389,7 +384,6 @@ fn parseVarDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 389 | 384 | ||
| 390 | const node = try arena.create(Node.VarDecl); | 385 | const node = try arena.create(Node.VarDecl); |
| 391 | node.* = Node.VarDecl{ | 386 | node.* = Node.VarDecl{ |
| 392 | .base = Node{ .id = .VarDecl }, | ||
| 393 | .doc_comments = null, | 387 | .doc_comments = null, |
| 394 | .visib_token = null, | 388 | .visib_token = null, |
| 395 | .thread_local_token = null, | 389 | .thread_local_token = null, |
| ... | @@ -477,7 +471,6 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No | ... | @@ -477,7 +471,6 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No |
| 477 | 471 | ||
| 478 | const node = try arena.create(Node.Comptime); | 472 | const node = try arena.create(Node.Comptime); |
| 479 | node.* = Node.Comptime{ | 473 | node.* = Node.Comptime{ |
| 480 | .base = Node{ .id = .Comptime }, | ||
| 481 | .doc_comments = null, | 474 | .doc_comments = null, |
| 482 | .comptime_token = token, | 475 | .comptime_token = token, |
| 483 | .expr = block_expr, | 476 | .expr = block_expr, |
| ... | @@ -496,7 +489,6 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No | ... | @@ -496,7 +489,6 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No |
| 496 | 489 | ||
| 497 | const node = try arena.create(Node.Suspend); | 490 | const node = try arena.create(Node.Suspend); |
| 498 | node.* = Node.Suspend{ | 491 | node.* = Node.Suspend{ |
| 499 | .base = Node{ .id = .Suspend }, | ||
| 500 | .suspend_token = suspend_token, | 492 | .suspend_token = suspend_token, |
| 501 | .body = body_node, | 493 | .body = body_node, |
| 502 | }; | 494 | }; |
| ... | @@ -510,7 +502,6 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No | ... | @@ -510,7 +502,6 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No |
| 510 | }); | 502 | }); |
| 511 | const node = try arena.create(Node.Defer); | 503 | const node = try arena.create(Node.Defer); |
| 512 | node.* = Node.Defer{ | 504 | node.* = Node.Defer{ |
| 513 | .base = Node{ .id = .Defer }, | ||
| 514 | .defer_token = token, | 505 | .defer_token = token, |
| 515 | .expr = expr_node, | 506 | .expr = expr_node, |
| 516 | }; | 507 | }; |
| ... | @@ -558,7 +549,6 @@ fn parseIfStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -558,7 +549,6 @@ fn parseIfStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 558 | 549 | ||
| 559 | const node = try arena.create(Node.Else); | 550 | const node = try arena.create(Node.Else); |
| 560 | node.* = Node.Else{ | 551 | node.* = Node.Else{ |
| 561 | .base = Node{ .id = .Else }, | ||
| 562 | .else_token = else_token, | 552 | .else_token = else_token, |
| 563 | .payload = payload, | 553 | .payload = payload, |
| 564 | .body = else_body, | 554 | .body = else_body, |
| ... | @@ -652,7 +642,6 @@ fn parseForStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -652,7 +642,6 @@ fn parseForStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 652 | 642 | ||
| 653 | const else_node = try arena.create(Node.Else); | 643 | const else_node = try arena.create(Node.Else); |
| 654 | else_node.* = Node.Else{ | 644 | else_node.* = Node.Else{ |
| 655 | .base = Node{ .id = .Else }, | ||
| 656 | .else_token = else_token, | 645 | .else_token = else_token, |
| 657 | .payload = null, | 646 | .payload = null, |
| 658 | .body = statement_node, | 647 | .body = statement_node, |
| ... | @@ -677,7 +666,6 @@ fn parseForStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -677,7 +666,6 @@ fn parseForStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 677 | 666 | ||
| 678 | const else_node = try arena.create(Node.Else); | 667 | const else_node = try arena.create(Node.Else); |
| 679 | else_node.* = Node.Else{ | 668 | else_node.* = Node.Else{ |
| 680 | .base = Node{ .id = .Else }, | ||
| 681 | .else_token = else_token, | 669 | .else_token = else_token, |
| 682 | .payload = null, | 670 | .payload = null, |
| 683 | .body = statement_node, | 671 | .body = statement_node, |
| ... | @@ -714,7 +702,6 @@ fn parseWhileStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No | ... | @@ -714,7 +702,6 @@ fn parseWhileStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No |
| 714 | 702 | ||
| 715 | const else_node = try arena.create(Node.Else); | 703 | const else_node = try arena.create(Node.Else); |
| 716 | else_node.* = Node.Else{ | 704 | else_node.* = Node.Else{ |
| 717 | .base = Node{ .id = .Else }, | ||
| 718 | .else_token = else_token, | 705 | .else_token = else_token, |
| 719 | .payload = payload, | 706 | .payload = payload, |
| 720 | .body = statement_node, | 707 | .body = statement_node, |
| ... | @@ -741,7 +728,6 @@ fn parseWhileStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No | ... | @@ -741,7 +728,6 @@ fn parseWhileStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No |
| 741 | 728 | ||
| 742 | const else_node = try arena.create(Node.Else); | 729 | const else_node = try arena.create(Node.Else); |
| 743 | else_node.* = Node.Else{ | 730 | else_node.* = Node.Else{ |
| 744 | .base = Node{ .id = .Else }, | ||
| 745 | .else_token = else_token, | 731 | .else_token = else_token, |
| 746 | .payload = payload, | 732 | .payload = payload, |
| 747 | .body = statement_node, | 733 | .body = statement_node, |
| ... | @@ -870,7 +856,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -870,7 +856,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 870 | const expr_node = try parseExpr(arena, it, tree); | 856 | const expr_node = try parseExpr(arena, it, tree); |
| 871 | const node = try arena.create(Node.ControlFlowExpression); | 857 | const node = try arena.create(Node.ControlFlowExpression); |
| 872 | node.* = Node.ControlFlowExpression{ | 858 | node.* = Node.ControlFlowExpression{ |
| 873 | .base = Node{ .id = .ControlFlowExpression }, | ||
| 874 | .ltoken = token, | 859 | .ltoken = token, |
| 875 | .kind = Node.ControlFlowExpression.Kind{ .Break = label }, | 860 | .kind = Node.ControlFlowExpression.Kind{ .Break = label }, |
| 876 | .rhs = expr_node, | 861 | .rhs = expr_node, |
| ... | @@ -884,7 +869,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -884,7 +869,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 884 | }); | 869 | }); |
| 885 | const node = try arena.create(Node.Comptime); | 870 | const node = try arena.create(Node.Comptime); |
| 886 | node.* = Node.Comptime{ | 871 | node.* = Node.Comptime{ |
| 887 | .base = Node{ .id = .Comptime }, | ||
| 888 | .doc_comments = null, | 872 | .doc_comments = null, |
| 889 | .comptime_token = token, | 873 | .comptime_token = token, |
| 890 | .expr = expr_node, | 874 | .expr = expr_node, |
| ... | @@ -896,7 +880,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -896,7 +880,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 896 | const label = try parseBreakLabel(arena, it, tree); | 880 | const label = try parseBreakLabel(arena, it, tree); |
| 897 | const node = try arena.create(Node.ControlFlowExpression); | 881 | const node = try arena.create(Node.ControlFlowExpression); |
| 898 | node.* = Node.ControlFlowExpression{ | 882 | node.* = Node.ControlFlowExpression{ |
| 899 | .base = Node{ .id = .ControlFlowExpression }, | ||
| 900 | .ltoken = token, | 883 | .ltoken = token, |
| 901 | .kind = Node.ControlFlowExpression.Kind{ .Continue = label }, | 884 | .kind = Node.ControlFlowExpression.Kind{ .Continue = label }, |
| 902 | .rhs = null, | 885 | .rhs = null, |
| ... | @@ -910,7 +893,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -910,7 +893,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 910 | }); | 893 | }); |
| 911 | const node = try arena.create(Node.PrefixOp); | 894 | const node = try arena.create(Node.PrefixOp); |
| 912 | node.* = Node.PrefixOp{ | 895 | node.* = Node.PrefixOp{ |
| 913 | .base = Node{ .id = .PrefixOp }, | ||
| 914 | .op_token = token, | 896 | .op_token = token, |
| 915 | .op = Node.PrefixOp.Op.Resume, | 897 | .op = Node.PrefixOp.Op.Resume, |
| 916 | .rhs = expr_node, | 898 | .rhs = expr_node, |
| ... | @@ -922,7 +904,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -922,7 +904,6 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 922 | const expr_node = try parseExpr(arena, it, tree); | 904 | const expr_node = try parseExpr(arena, it, tree); |
| 923 | const node = try arena.create(Node.ControlFlowExpression); | 905 | const node = try arena.create(Node.ControlFlowExpression); |
| 924 | node.* = Node.ControlFlowExpression{ | 906 | node.* = Node.ControlFlowExpression{ |
| 925 | .base = Node{ .id = .ControlFlowExpression }, | ||
| 926 | .ltoken = token, | 907 | .ltoken = token, |
| 927 | .kind = Node.ControlFlowExpression.Kind.Return, | 908 | .kind = Node.ControlFlowExpression.Kind.Return, |
| 928 | .rhs = expr_node, | 909 | .rhs = expr_node, |
| ... | @@ -970,7 +951,6 @@ fn parseBlock(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -970,7 +951,6 @@ fn parseBlock(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 970 | 951 | ||
| 971 | const block_node = try arena.create(Node.Block); | 952 | const block_node = try arena.create(Node.Block); |
| 972 | block_node.* = Node.Block{ | 953 | block_node.* = Node.Block{ |
| 973 | .base = Node{ .id = .Block }, | ||
| 974 | .label = null, | 954 | .label = null, |
| 975 | .lbrace = lbrace, | 955 | .lbrace = lbrace, |
| 976 | .statements = statements, | 956 | .statements = statements, |
| ... | @@ -1020,7 +1000,6 @@ fn parseForExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1020,7 +1000,6 @@ fn parseForExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1020 | 1000 | ||
| 1021 | const else_node = try arena.create(Node.Else); | 1001 | const else_node = try arena.create(Node.Else); |
| 1022 | else_node.* = Node.Else{ | 1002 | else_node.* = Node.Else{ |
| 1023 | .base = Node{ .id = .Else }, | ||
| 1024 | .else_token = else_token, | 1003 | .else_token = else_token, |
| 1025 | .payload = null, | 1004 | .payload = null, |
| 1026 | .body = body, | 1005 | .body = body, |
| ... | @@ -1050,7 +1029,6 @@ fn parseWhileExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1050,7 +1029,6 @@ fn parseWhileExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1050 | 1029 | ||
| 1051 | const else_node = try arena.create(Node.Else); | 1030 | const else_node = try arena.create(Node.Else); |
| 1052 | else_node.* = Node.Else{ | 1031 | else_node.* = Node.Else{ |
| 1053 | .base = Node{ .id = .Else }, | ||
| 1054 | .else_token = else_token, | 1032 | .else_token = else_token, |
| 1055 | .payload = payload, | 1033 | .payload = payload, |
| 1056 | .body = body, | 1034 | .body = body, |
| ... | @@ -1102,7 +1080,6 @@ fn parseInitList(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node.Suf | ... | @@ -1102,7 +1080,6 @@ fn parseInitList(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node.Suf |
| 1102 | 1080 | ||
| 1103 | const node = try arena.create(Node.SuffixOp); | 1081 | const node = try arena.create(Node.SuffixOp); |
| 1104 | node.* = Node.SuffixOp{ | 1082 | node.* = Node.SuffixOp{ |
| 1105 | .base = Node{ .id = .SuffixOp }, | ||
| 1106 | .lhs = .{ .node = undefined }, // set by caller | 1083 | .lhs = .{ .node = undefined }, // set by caller |
| 1107 | .op = op, | 1084 | .op = op, |
| 1108 | .rtoken = try expectToken(it, tree, .RBrace), | 1085 | .rtoken = try expectToken(it, tree, .RBrace), |
| ... | @@ -1171,7 +1148,6 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1171,7 +1148,6 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1171 | }; | 1148 | }; |
| 1172 | const node = try arena.create(Node.SuffixOp); | 1149 | const node = try arena.create(Node.SuffixOp); |
| 1173 | node.* = Node.SuffixOp{ | 1150 | node.* = Node.SuffixOp{ |
| 1174 | .base = Node{ .id = .SuffixOp }, | ||
| 1175 | .lhs = .{ .node = res }, | 1151 | .lhs = .{ .node = res }, |
| 1176 | .op = Node.SuffixOp.Op{ | 1152 | .op = Node.SuffixOp.Op{ |
| 1177 | .Call = Node.SuffixOp.Op.Call{ | 1153 | .Call = Node.SuffixOp.Op.Call{ |
| ... | @@ -1199,7 +1175,6 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1199,7 +1175,6 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1199 | if (try parseFnCallArguments(arena, it, tree)) |params| { | 1175 | if (try parseFnCallArguments(arena, it, tree)) |params| { |
| 1200 | const call = try arena.create(Node.SuffixOp); | 1176 | const call = try arena.create(Node.SuffixOp); |
| 1201 | call.* = Node.SuffixOp{ | 1177 | call.* = Node.SuffixOp{ |
| 1202 | .base = Node{ .id = .SuffixOp }, | ||
| 1203 | .lhs = .{ .node = res }, | 1178 | .lhs = .{ .node = res }, |
| 1204 | .op = Node.SuffixOp.Op{ | 1179 | .op = Node.SuffixOp.Op{ |
| 1205 | .Call = Node.SuffixOp.Op.Call{ | 1180 | .Call = Node.SuffixOp.Op.Call{ |
| ... | @@ -1248,7 +1223,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N | ... | @@ -1248,7 +1223,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N |
| 1248 | if (eatToken(it, .CharLiteral)) |token| { | 1223 | if (eatToken(it, .CharLiteral)) |token| { |
| 1249 | const node = try arena.create(Node.CharLiteral); | 1224 | const node = try arena.create(Node.CharLiteral); |
| 1250 | node.* = Node.CharLiteral{ | 1225 | node.* = Node.CharLiteral{ |
| 1251 | .base = Node{ .id = .CharLiteral }, | ||
| 1252 | .token = token, | 1226 | .token = token, |
| 1253 | }; | 1227 | }; |
| 1254 | return &node.base; | 1228 | return &node.base; |
| ... | @@ -1267,7 +1241,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N | ... | @@ -1267,7 +1241,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N |
| 1267 | const expr = (try parseTypeExpr(arena, it, tree)) orelse return null; | 1241 | const expr = (try parseTypeExpr(arena, it, tree)) orelse return null; |
| 1268 | const node = try arena.create(Node.Comptime); | 1242 | const node = try arena.create(Node.Comptime); |
| 1269 | node.* = Node.Comptime{ | 1243 | node.* = Node.Comptime{ |
| 1270 | .base = Node{ .id = .Comptime }, | ||
| 1271 | .doc_comments = null, | 1244 | .doc_comments = null, |
| 1272 | .comptime_token = token, | 1245 | .comptime_token = token, |
| 1273 | .expr = expr, | 1246 | .expr = expr, |
| ... | @@ -1282,7 +1255,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N | ... | @@ -1282,7 +1255,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N |
| 1282 | const global_error_set = try createLiteral(arena, Node.ErrorType, token); | 1255 | const global_error_set = try createLiteral(arena, Node.ErrorType, token); |
| 1283 | const node = try arena.create(Node.InfixOp); | 1256 | const node = try arena.create(Node.InfixOp); |
| 1284 | node.* = Node.InfixOp{ | 1257 | node.* = Node.InfixOp{ |
| 1285 | .base = Node{ .id = .InfixOp }, | ||
| 1286 | .op_token = period, | 1258 | .op_token = period, |
| 1287 | .lhs = global_error_set, | 1259 | .lhs = global_error_set, |
| 1288 | .op = Node.InfixOp.Op.Period, | 1260 | .op = Node.InfixOp.Op.Period, |
| ... | @@ -1295,7 +1267,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N | ... | @@ -1295,7 +1267,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N |
| 1295 | if (eatToken(it, .Keyword_anyframe)) |token| { | 1267 | if (eatToken(it, .Keyword_anyframe)) |token| { |
| 1296 | const node = try arena.create(Node.AnyFrameType); | 1268 | const node = try arena.create(Node.AnyFrameType); |
| 1297 | node.* = Node.AnyFrameType{ | 1269 | node.* = Node.AnyFrameType{ |
| 1298 | .base = Node{ .id = .AnyFrameType }, | ||
| 1299 | .anyframe_token = token, | 1270 | .anyframe_token = token, |
| 1300 | .result = null, | 1271 | .result = null, |
| 1301 | }; | 1272 | }; |
| ... | @@ -1337,7 +1308,6 @@ fn parseErrorSetDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -1337,7 +1308,6 @@ fn parseErrorSetDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 1337 | 1308 | ||
| 1338 | const node = try arena.create(Node.ErrorSetDecl); | 1309 | const node = try arena.create(Node.ErrorSetDecl); |
| 1339 | node.* = Node.ErrorSetDecl{ | 1310 | node.* = Node.ErrorSetDecl{ |
| 1340 | .base = Node{ .id = .ErrorSetDecl }, | ||
| 1341 | .error_token = error_token, | 1311 | .error_token = error_token, |
| 1342 | .decls = decls, | 1312 | .decls = decls, |
| 1343 | .rbrace_token = rbrace, | 1313 | .rbrace_token = rbrace, |
| ... | @@ -1355,7 +1325,6 @@ fn parseGroupedExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -1355,7 +1325,6 @@ fn parseGroupedExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 1355 | 1325 | ||
| 1356 | const node = try arena.create(Node.GroupedExpression); | 1326 | const node = try arena.create(Node.GroupedExpression); |
| 1357 | node.* = Node.GroupedExpression{ | 1327 | node.* = Node.GroupedExpression{ |
| 1358 | .base = Node{ .id = .GroupedExpression }, | ||
| 1359 | .lparen = lparen, | 1328 | .lparen = lparen, |
| 1360 | .expr = expr, | 1329 | .expr = expr, |
| 1361 | .rparen = rparen, | 1330 | .rparen = rparen, |
| ... | @@ -1438,7 +1407,6 @@ fn parseForTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -1438,7 +1407,6 @@ fn parseForTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 1438 | 1407 | ||
| 1439 | const else_node = try arena.create(Node.Else); | 1408 | const else_node = try arena.create(Node.Else); |
| 1440 | else_node.* = Node.Else{ | 1409 | else_node.* = Node.Else{ |
| 1441 | .base = Node{ .id = .Else }, | ||
| 1442 | .else_token = else_token, | 1410 | .else_token = else_token, |
| 1443 | .payload = null, | 1411 | .payload = null, |
| 1444 | .body = else_expr, | 1412 | .body = else_expr, |
| ... | @@ -1469,7 +1437,6 @@ fn parseWhileTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod | ... | @@ -1469,7 +1437,6 @@ fn parseWhileTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod |
| 1469 | 1437 | ||
| 1470 | const else_node = try arena.create(Node.Else); | 1438 | const else_node = try arena.create(Node.Else); |
| 1471 | else_node.* = Node.Else{ | 1439 | else_node.* = Node.Else{ |
| 1472 | .base = Node{ .id = .Else }, | ||
| 1473 | .else_token = else_token, | 1440 | .else_token = else_token, |
| 1474 | .payload = null, | 1441 | .payload = null, |
| 1475 | .body = else_expr, | 1442 | .body = else_expr, |
| ... | @@ -1495,7 +1462,6 @@ fn parseSwitchExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1495,7 +1462,6 @@ fn parseSwitchExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1495 | 1462 | ||
| 1496 | const node = try arena.create(Node.Switch); | 1463 | const node = try arena.create(Node.Switch); |
| 1497 | node.* = Node.Switch{ | 1464 | node.* = Node.Switch{ |
| 1498 | .base = Node{ .id = .Switch }, | ||
| 1499 | .switch_token = switch_token, | 1465 | .switch_token = switch_token, |
| 1500 | .expr = expr_node, | 1466 | .expr = expr_node, |
| 1501 | .cases = cases, | 1467 | .cases = cases, |
| ... | @@ -1515,7 +1481,6 @@ fn parseAsmExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1515,7 +1481,6 @@ fn parseAsmExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1515 | 1481 | ||
| 1516 | const node = try arena.create(Node.Asm); | 1482 | const node = try arena.create(Node.Asm); |
| 1517 | node.* = Node.Asm{ | 1483 | node.* = Node.Asm{ |
| 1518 | .base = Node{ .id = .Asm }, | ||
| 1519 | .asm_token = asm_token, | 1484 | .asm_token = asm_token, |
| 1520 | .volatile_token = volatile_token, | 1485 | .volatile_token = volatile_token, |
| 1521 | .template = template, | 1486 | .template = template, |
| ... | @@ -1538,7 +1503,6 @@ fn parseAnonLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -1538,7 +1503,6 @@ fn parseAnonLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 1538 | if (eatToken(it, .Identifier)) |name| { | 1503 | if (eatToken(it, .Identifier)) |name| { |
| 1539 | const node = try arena.create(Node.EnumLiteral); | 1504 | const node = try arena.create(Node.EnumLiteral); |
| 1540 | node.* = Node.EnumLiteral{ | 1505 | node.* = Node.EnumLiteral{ |
| 1541 | .base = Node{ .id = .EnumLiteral }, | ||
| 1542 | .dot = dot, | 1506 | .dot = dot, |
| 1543 | .name = name, | 1507 | .name = name, |
| 1544 | }; | 1508 | }; |
| ... | @@ -1591,7 +1555,6 @@ fn parseAsmOutputItem(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod | ... | @@ -1591,7 +1555,6 @@ fn parseAsmOutputItem(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod |
| 1591 | 1555 | ||
| 1592 | const node = try arena.create(Node.AsmOutput); | 1556 | const node = try arena.create(Node.AsmOutput); |
| 1593 | node.* = Node.AsmOutput{ | 1557 | node.* = Node.AsmOutput{ |
| 1594 | .base = Node{ .id = .AsmOutput }, | ||
| 1595 | .lbracket = lbracket, | 1558 | .lbracket = lbracket, |
| 1596 | .symbolic_name = name, | 1559 | .symbolic_name = name, |
| 1597 | .constraint = constraint, | 1560 | .constraint = constraint, |
| ... | @@ -1628,7 +1591,6 @@ fn parseAsmInputItem(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -1628,7 +1591,6 @@ fn parseAsmInputItem(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 1628 | 1591 | ||
| 1629 | const node = try arena.create(Node.AsmInput); | 1592 | const node = try arena.create(Node.AsmInput); |
| 1630 | node.* = Node.AsmInput{ | 1593 | node.* = Node.AsmInput{ |
| 1631 | .base = Node{ .id = .AsmInput }, | ||
| 1632 | .lbracket = lbracket, | 1594 | .lbracket = lbracket, |
| 1633 | .symbolic_name = name, | 1595 | .symbolic_name = name, |
| 1634 | .constraint = constraint, | 1596 | .constraint = constraint, |
| ... | @@ -1687,7 +1649,6 @@ fn parseFieldInit(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1687,7 +1649,6 @@ fn parseFieldInit(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1687 | 1649 | ||
| 1688 | const node = try arena.create(Node.FieldInitializer); | 1650 | const node = try arena.create(Node.FieldInitializer); |
| 1689 | node.* = Node.FieldInitializer{ | 1651 | node.* = Node.FieldInitializer{ |
| 1690 | .base = Node{ .id = .FieldInitializer }, | ||
| 1691 | .period_token = period_token, | 1652 | .period_token = period_token, |
| 1692 | .name_token = name_token, | 1653 | .name_token = name_token, |
| 1693 | .expr = expr_node, | 1654 | .expr = expr_node, |
| ... | @@ -1760,7 +1721,6 @@ fn parseParamDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1760,7 +1721,6 @@ fn parseParamDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1760 | 1721 | ||
| 1761 | const param_decl = try arena.create(Node.ParamDecl); | 1722 | const param_decl = try arena.create(Node.ParamDecl); |
| 1762 | param_decl.* = Node.ParamDecl{ | 1723 | param_decl.* = Node.ParamDecl{ |
| 1763 | .base = Node{ .id = .ParamDecl }, | ||
| 1764 | .doc_comments = doc_comments, | 1724 | .doc_comments = doc_comments, |
| 1765 | .comptime_token = comptime_token, | 1725 | .comptime_token = comptime_token, |
| 1766 | .noalias_token = noalias_token, | 1726 | .noalias_token = noalias_token, |
| ... | @@ -1807,7 +1767,6 @@ fn parseIfPrefix(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1807,7 +1767,6 @@ fn parseIfPrefix(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1807 | 1767 | ||
| 1808 | const node = try arena.create(Node.If); | 1768 | const node = try arena.create(Node.If); |
| 1809 | node.* = Node.If{ | 1769 | node.* = Node.If{ |
| 1810 | .base = Node{ .id = .If }, | ||
| 1811 | .if_token = if_token, | 1770 | .if_token = if_token, |
| 1812 | .condition = condition, | 1771 | .condition = condition, |
| 1813 | .payload = payload, | 1772 | .payload = payload, |
| ... | @@ -1832,7 +1791,6 @@ fn parseWhilePrefix(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -1832,7 +1791,6 @@ fn parseWhilePrefix(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 1832 | 1791 | ||
| 1833 | const node = try arena.create(Node.While); | 1792 | const node = try arena.create(Node.While); |
| 1834 | node.* = Node.While{ | 1793 | node.* = Node.While{ |
| 1835 | .base = Node{ .id = .While }, | ||
| 1836 | .label = null, | 1794 | .label = null, |
| 1837 | .inline_token = null, | 1795 | .inline_token = null, |
| 1838 | .while_token = while_token, | 1796 | .while_token = while_token, |
| ... | @@ -1861,7 +1819,6 @@ fn parseForPrefix(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1861,7 +1819,6 @@ fn parseForPrefix(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1861 | 1819 | ||
| 1862 | const node = try arena.create(Node.For); | 1820 | const node = try arena.create(Node.For); |
| 1863 | node.* = Node.For{ | 1821 | node.* = Node.For{ |
| 1864 | .base = Node{ .id = .For }, | ||
| 1865 | .label = null, | 1822 | .label = null, |
| 1866 | .inline_token = null, | 1823 | .inline_token = null, |
| 1867 | .for_token = for_token, | 1824 | .for_token = for_token, |
| ... | @@ -1883,7 +1840,6 @@ fn parsePayload(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1883,7 +1840,6 @@ fn parsePayload(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1883 | 1840 | ||
| 1884 | const node = try arena.create(Node.Payload); | 1841 | const node = try arena.create(Node.Payload); |
| 1885 | node.* = Node.Payload{ | 1842 | node.* = Node.Payload{ |
| 1886 | .base = Node{ .id = .Payload }, | ||
| 1887 | .lpipe = lpipe, | 1843 | .lpipe = lpipe, |
| 1888 | .error_symbol = identifier, | 1844 | .error_symbol = identifier, |
| 1889 | .rpipe = rpipe, | 1845 | .rpipe = rpipe, |
| ... | @@ -1902,7 +1858,6 @@ fn parsePtrPayload(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1902,7 +1858,6 @@ fn parsePtrPayload(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1902 | 1858 | ||
| 1903 | const node = try arena.create(Node.PointerPayload); | 1859 | const node = try arena.create(Node.PointerPayload); |
| 1904 | node.* = Node.PointerPayload{ | 1860 | node.* = Node.PointerPayload{ |
| 1905 | .base = Node{ .id = .PointerPayload }, | ||
| 1906 | .lpipe = lpipe, | 1861 | .lpipe = lpipe, |
| 1907 | .ptr_token = asterisk, | 1862 | .ptr_token = asterisk, |
| 1908 | .value_symbol = identifier, | 1863 | .value_symbol = identifier, |
| ... | @@ -1930,7 +1885,6 @@ fn parsePtrIndexPayload(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N | ... | @@ -1930,7 +1885,6 @@ fn parsePtrIndexPayload(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N |
| 1930 | 1885 | ||
| 1931 | const node = try arena.create(Node.PointerIndexPayload); | 1886 | const node = try arena.create(Node.PointerIndexPayload); |
| 1932 | node.* = Node.PointerIndexPayload{ | 1887 | node.* = Node.PointerIndexPayload{ |
| 1933 | .base = Node{ .id = .PointerIndexPayload }, | ||
| 1934 | .lpipe = lpipe, | 1888 | .lpipe = lpipe, |
| 1935 | .ptr_token = asterisk, | 1889 | .ptr_token = asterisk, |
| 1936 | .value_symbol = identifier, | 1890 | .value_symbol = identifier, |
| ... | @@ -1972,7 +1926,6 @@ fn parseSwitchCase(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1972,7 +1926,6 @@ fn parseSwitchCase(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1972 | } else if (eatToken(it, .Keyword_else)) |else_token| { | 1926 | } else if (eatToken(it, .Keyword_else)) |else_token| { |
| 1973 | const else_node = try arena.create(Node.SwitchElse); | 1927 | const else_node = try arena.create(Node.SwitchElse); |
| 1974 | else_node.* = Node.SwitchElse{ | 1928 | else_node.* = Node.SwitchElse{ |
| 1975 | .base = Node{ .id = .SwitchElse }, | ||
| 1976 | .token = else_token, | 1929 | .token = else_token, |
| 1977 | }; | 1930 | }; |
| 1978 | try list.push(&else_node.base); | 1931 | try list.push(&else_node.base); |
| ... | @@ -1980,7 +1933,6 @@ fn parseSwitchCase(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1980,7 +1933,6 @@ fn parseSwitchCase(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1980 | 1933 | ||
| 1981 | const node = try arena.create(Node.SwitchCase); | 1934 | const node = try arena.create(Node.SwitchCase); |
| 1982 | node.* = Node.SwitchCase{ | 1935 | node.* = Node.SwitchCase{ |
| 1983 | .base = Node{ .id = .SwitchCase }, | ||
| 1984 | .items = list, | 1936 | .items = list, |
| 1985 | .arrow_token = undefined, // set by caller | 1937 | .arrow_token = undefined, // set by caller |
| 1986 | .payload = null, | 1938 | .payload = null, |
| ... | @@ -1999,7 +1951,6 @@ fn parseSwitchItem(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -1999,7 +1951,6 @@ fn parseSwitchItem(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1999 | 1951 | ||
| 2000 | const node = try arena.create(Node.InfixOp); | 1952 | const node = try arena.create(Node.InfixOp); |
| 2001 | node.* = Node.InfixOp{ | 1953 | node.* = Node.InfixOp{ |
| 2002 | .base = Node{ .id = .InfixOp }, | ||
| 2003 | .op_token = token, | 1954 | .op_token = token, |
| 2004 | .lhs = expr, | 1955 | .lhs = expr, |
| 2005 | .op = Node.InfixOp.Op{ .Range = {} }, | 1956 | .op = Node.InfixOp.Op{ .Range = {} }, |
| ... | @@ -2052,7 +2003,6 @@ fn parseAssignOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2052,7 +2003,6 @@ fn parseAssignOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2052 | 2003 | ||
| 2053 | const node = try arena.create(Node.InfixOp); | 2004 | const node = try arena.create(Node.InfixOp); |
| 2054 | node.* = Node.InfixOp{ | 2005 | node.* = Node.InfixOp{ |
| 2055 | .base = Node{ .id = .InfixOp }, | ||
| 2056 | .op_token = token.index, | 2006 | .op_token = token.index, |
| 2057 | .lhs = undefined, // set by caller | 2007 | .lhs = undefined, // set by caller |
| 2058 | .op = op, | 2008 | .op = op, |
| ... | @@ -2212,7 +2162,6 @@ fn parsePrefixOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2212,7 +2162,6 @@ fn parsePrefixOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2212 | 2162 | ||
| 2213 | const node = try arena.create(Node.PrefixOp); | 2163 | const node = try arena.create(Node.PrefixOp); |
| 2214 | node.* = Node.PrefixOp{ | 2164 | node.* = Node.PrefixOp{ |
| 2215 | .base = Node{ .id = .PrefixOp }, | ||
| 2216 | .op_token = token.index, | 2165 | .op_token = token.index, |
| 2217 | .op = op, | 2166 | .op = op, |
| 2218 | .rhs = undefined, | 2167 | .rhs = undefined, |
| ... | @@ -2236,7 +2185,6 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -2236,7 +2185,6 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 2236 | if (eatToken(it, .QuestionMark)) |token| { | 2185 | if (eatToken(it, .QuestionMark)) |token| { |
| 2237 | const node = try arena.create(Node.PrefixOp); | 2186 | const node = try arena.create(Node.PrefixOp); |
| 2238 | node.* = Node.PrefixOp{ | 2187 | node.* = Node.PrefixOp{ |
| 2239 | .base = Node{ .id = .PrefixOp }, | ||
| 2240 | .op_token = token, | 2188 | .op_token = token, |
| 2241 | .op = Node.PrefixOp.Op.OptionalType, | 2189 | .op = Node.PrefixOp.Op.OptionalType, |
| 2242 | .rhs = undefined, // set by caller | 2190 | .rhs = undefined, // set by caller |
| ... | @@ -2255,7 +2203,6 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -2255,7 +2203,6 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 2255 | }; | 2203 | }; |
| 2256 | const node = try arena.create(Node.AnyFrameType); | 2204 | const node = try arena.create(Node.AnyFrameType); |
| 2257 | node.* = Node.AnyFrameType{ | 2205 | node.* = Node.AnyFrameType{ |
| 2258 | .base = Node{ .id = .AnyFrameType }, | ||
| 2259 | .anyframe_token = token, | 2206 | .anyframe_token = token, |
| 2260 | .result = Node.AnyFrameType.Result{ | 2207 | .result = Node.AnyFrameType.Result{ |
| 2261 | .arrow_token = arrow, | 2208 | .arrow_token = arrow, |
| ... | @@ -2430,7 +2377,6 @@ fn parseSuffixOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2430,7 +2377,6 @@ fn parseSuffixOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2430 | // this grammar rule be altered? | 2377 | // this grammar rule be altered? |
| 2431 | const node = try arena.create(Node.InfixOp); | 2378 | const node = try arena.create(Node.InfixOp); |
| 2432 | node.* = Node.InfixOp{ | 2379 | node.* = Node.InfixOp{ |
| 2433 | .base = Node{ .id = .InfixOp }, | ||
| 2434 | .op_token = period, | 2380 | .op_token = period, |
| 2435 | .lhs = undefined, // set by caller | 2381 | .lhs = undefined, // set by caller |
| 2436 | .op = Node.InfixOp.Op.Period, | 2382 | .op = Node.InfixOp.Op.Period, |
| ... | @@ -2452,7 +2398,6 @@ fn parseSuffixOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2452,7 +2398,6 @@ fn parseSuffixOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2452 | 2398 | ||
| 2453 | const node = try arena.create(Node.SuffixOp); | 2399 | const node = try arena.create(Node.SuffixOp); |
| 2454 | node.* = Node.SuffixOp{ | 2400 | node.* = Node.SuffixOp{ |
| 2455 | .base = Node{ .id = .SuffixOp }, | ||
| 2456 | .lhs = undefined, // set by caller | 2401 | .lhs = undefined, // set by caller |
| 2457 | .op = op_and_token.op, | 2402 | .op = op_and_token.op, |
| 2458 | .rtoken = op_and_token.token, | 2403 | .rtoken = op_and_token.token, |
| ... | @@ -2506,7 +2451,6 @@ fn parseArrayTypeStart(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No | ... | @@ -2506,7 +2451,6 @@ fn parseArrayTypeStart(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No |
| 2506 | 2451 | ||
| 2507 | const node = try arena.create(Node.PrefixOp); | 2452 | const node = try arena.create(Node.PrefixOp); |
| 2508 | node.* = Node.PrefixOp{ | 2453 | node.* = Node.PrefixOp{ |
| 2509 | .base = Node{ .id = .PrefixOp }, | ||
| 2510 | .op_token = lbracket, | 2454 | .op_token = lbracket, |
| 2511 | .op = op, | 2455 | .op = op, |
| 2512 | .rhs = undefined, // set by caller | 2456 | .rhs = undefined, // set by caller |
| ... | @@ -2656,7 +2600,6 @@ fn parseContainerDeclType(arena: *Allocator, it: *TokenIterator, tree: *Tree) !? | ... | @@ -2656,7 +2600,6 @@ fn parseContainerDeclType(arena: *Allocator, it: *TokenIterator, tree: *Tree) !? |
| 2656 | 2600 | ||
| 2657 | const node = try arena.create(Node.ContainerDecl); | 2601 | const node = try arena.create(Node.ContainerDecl); |
| 2658 | node.* = Node.ContainerDecl{ | 2602 | node.* = Node.ContainerDecl{ |
| 2659 | .base = Node{ .id = .ContainerDecl }, | ||
| 2660 | .layout_token = null, | 2603 | .layout_token = null, |
| 2661 | .kind_token = kind_token.index, | 2604 | .kind_token = kind_token.index, |
| 2662 | .init_arg_expr = init_arg_expr, | 2605 | .init_arg_expr = init_arg_expr, |
| ... | @@ -2729,7 +2672,6 @@ fn SimpleBinOpParseFn(comptime token: Token.Id, comptime op: Node.InfixOp.Op) No | ... | @@ -2729,7 +2672,6 @@ fn SimpleBinOpParseFn(comptime token: Token.Id, comptime op: Node.InfixOp.Op) No |
| 2729 | const op_token = eatToken(it, token) orelse return null; | 2672 | const op_token = eatToken(it, token) orelse return null; |
| 2730 | const node = try arena.create(Node.InfixOp); | 2673 | const node = try arena.create(Node.InfixOp); |
| 2731 | node.* = Node.InfixOp{ | 2674 | node.* = Node.InfixOp{ |
| 2732 | .base = Node{ .id = .InfixOp }, | ||
| 2733 | .op_token = op_token, | 2675 | .op_token = op_token, |
| 2734 | .lhs = undefined, // set by caller | 2676 | .lhs = undefined, // set by caller |
| 2735 | .op = op, | 2677 | .op = op, |
| ... | @@ -2752,7 +2694,6 @@ fn parseBuiltinCall(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -2752,7 +2694,6 @@ fn parseBuiltinCall(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 2752 | }; | 2694 | }; |
| 2753 | const node = try arena.create(Node.BuiltinCall); | 2695 | const node = try arena.create(Node.BuiltinCall); |
| 2754 | node.* = Node.BuiltinCall{ | 2696 | node.* = Node.BuiltinCall{ |
| 2755 | .base = Node{ .id = .BuiltinCall }, | ||
| 2756 | .builtin_token = token, | 2697 | .builtin_token = token, |
| 2757 | .params = params.list, | 2698 | .params = params.list, |
| 2758 | .rparen_token = params.rparen, | 2699 | .rparen_token = params.rparen, |
| ... | @@ -2766,7 +2707,6 @@ fn parseErrorTag(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2766,7 +2707,6 @@ fn parseErrorTag(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2766 | 2707 | ||
| 2767 | const node = try arena.create(Node.ErrorTag); | 2708 | const node = try arena.create(Node.ErrorTag); |
| 2768 | node.* = Node.ErrorTag{ | 2709 | node.* = Node.ErrorTag{ |
| 2769 | .base = Node{ .id = .ErrorTag }, | ||
| 2770 | .doc_comments = doc_comments, | 2710 | .doc_comments = doc_comments, |
| 2771 | .name_token = token, | 2711 | .name_token = token, |
| 2772 | }; | 2712 | }; |
| ... | @@ -2777,7 +2717,6 @@ fn parseIdentifier(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2777,7 +2717,6 @@ fn parseIdentifier(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2777 | const token = eatToken(it, .Identifier) orelse return null; | 2717 | const token = eatToken(it, .Identifier) orelse return null; |
| 2778 | const node = try arena.create(Node.Identifier); | 2718 | const node = try arena.create(Node.Identifier); |
| 2779 | node.* = Node.Identifier{ | 2719 | node.* = Node.Identifier{ |
| 2780 | .base = Node{ .id = .Identifier }, | ||
| 2781 | .token = token, | 2720 | .token = token, |
| 2782 | }; | 2721 | }; |
| 2783 | return &node.base; | 2722 | return &node.base; |
| ... | @@ -2787,7 +2726,6 @@ fn parseVarType(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2787,7 +2726,6 @@ fn parseVarType(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2787 | const token = eatToken(it, .Keyword_var) orelse return null; | 2726 | const token = eatToken(it, .Keyword_var) orelse return null; |
| 2788 | const node = try arena.create(Node.VarType); | 2727 | const node = try arena.create(Node.VarType); |
| 2789 | node.* = Node.VarType{ | 2728 | node.* = Node.VarType{ |
| 2790 | .base = Node{ .id = .VarType }, | ||
| 2791 | .token = token, | 2729 | .token = token, |
| 2792 | }; | 2730 | }; |
| 2793 | return &node.base; | 2731 | return &node.base; |
| ... | @@ -2807,7 +2745,6 @@ fn parseStringLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod | ... | @@ -2807,7 +2745,6 @@ fn parseStringLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod |
| 2807 | if (eatToken(it, .StringLiteral)) |token| { | 2745 | if (eatToken(it, .StringLiteral)) |token| { |
| 2808 | const node = try arena.create(Node.StringLiteral); | 2746 | const node = try arena.create(Node.StringLiteral); |
| 2809 | node.* = Node.StringLiteral{ | 2747 | node.* = Node.StringLiteral{ |
| 2810 | .base = Node{ .id = .StringLiteral }, | ||
| 2811 | .token = token, | 2748 | .token = token, |
| 2812 | }; | 2749 | }; |
| 2813 | return &node.base; | 2750 | return &node.base; |
| ... | @@ -2816,7 +2753,6 @@ fn parseStringLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod | ... | @@ -2816,7 +2753,6 @@ fn parseStringLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod |
| 2816 | if (eatToken(it, .MultilineStringLiteralLine)) |first_line| { | 2753 | if (eatToken(it, .MultilineStringLiteralLine)) |first_line| { |
| 2817 | const node = try arena.create(Node.MultilineStringLiteral); | 2754 | const node = try arena.create(Node.MultilineStringLiteral); |
| 2818 | node.* = Node.MultilineStringLiteral{ | 2755 | node.* = Node.MultilineStringLiteral{ |
| 2819 | .base = Node{ .id = .MultilineStringLiteral }, | ||
| 2820 | .lines = Node.MultilineStringLiteral.LineList.init(arena), | 2756 | .lines = Node.MultilineStringLiteral.LineList.init(arena), |
| 2821 | }; | 2757 | }; |
| 2822 | try node.lines.push(first_line); | 2758 | try node.lines.push(first_line); |
| ... | @@ -2833,7 +2769,6 @@ fn parseIntegerLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No | ... | @@ -2833,7 +2769,6 @@ fn parseIntegerLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No |
| 2833 | const token = eatToken(it, .IntegerLiteral) orelse return null; | 2769 | const token = eatToken(it, .IntegerLiteral) orelse return null; |
| 2834 | const node = try arena.create(Node.IntegerLiteral); | 2770 | const node = try arena.create(Node.IntegerLiteral); |
| 2835 | node.* = Node.IntegerLiteral{ | 2771 | node.* = Node.IntegerLiteral{ |
| 2836 | .base = Node{ .id = .IntegerLiteral }, | ||
| 2837 | .token = token, | 2772 | .token = token, |
| 2838 | }; | 2773 | }; |
| 2839 | return &node.base; | 2774 | return &node.base; |
| ... | @@ -2843,7 +2778,6 @@ fn parseFloatLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node | ... | @@ -2843,7 +2778,6 @@ fn parseFloatLiteral(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 2843 | const token = eatToken(it, .FloatLiteral) orelse return null; | 2778 | const token = eatToken(it, .FloatLiteral) orelse return null; |
| 2844 | const node = try arena.create(Node.FloatLiteral); | 2779 | const node = try arena.create(Node.FloatLiteral); |
| 2845 | node.* = Node.FloatLiteral{ | 2780 | node.* = Node.FloatLiteral{ |
| 2846 | .base = Node{ .id = .FloatLiteral }, | ||
| 2847 | .token = token, | 2781 | .token = token, |
| 2848 | }; | 2782 | }; |
| 2849 | return &node.base; | 2783 | return &node.base; |
| ... | @@ -2853,7 +2787,6 @@ fn parseTry(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2853,7 +2787,6 @@ fn parseTry(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2853 | const token = eatToken(it, .Keyword_try) orelse return null; | 2787 | const token = eatToken(it, .Keyword_try) orelse return null; |
| 2854 | const node = try arena.create(Node.PrefixOp); | 2788 | const node = try arena.create(Node.PrefixOp); |
| 2855 | node.* = Node.PrefixOp{ | 2789 | node.* = Node.PrefixOp{ |
| 2856 | .base = Node{ .id = .PrefixOp }, | ||
| 2857 | .op_token = token, | 2790 | .op_token = token, |
| 2858 | .op = Node.PrefixOp.Op.Try, | 2791 | .op = Node.PrefixOp.Op.Try, |
| 2859 | .rhs = undefined, // set by caller | 2792 | .rhs = undefined, // set by caller |
| ... | @@ -2865,7 +2798,6 @@ fn parseUse(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { | ... | @@ -2865,7 +2798,6 @@ fn parseUse(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 2865 | const token = eatToken(it, .Keyword_usingnamespace) orelse return null; | 2798 | const token = eatToken(it, .Keyword_usingnamespace) orelse return null; |
| 2866 | const node = try arena.create(Node.Use); | 2799 | const node = try arena.create(Node.Use); |
| 2867 | node.* = Node.Use{ | 2800 | node.* = Node.Use{ |
| 2868 | .base = Node{ .id = .Use }, | ||
| 2869 | .doc_comments = null, | 2801 | .doc_comments = null, |
| 2870 | .visib_token = null, | 2802 | .visib_token = null, |
| 2871 | .use_token = token, | 2803 | .use_token = token, |
| ... | @@ -2891,7 +2823,6 @@ fn parseIf(arena: *Allocator, it: *TokenIterator, tree: *Tree, bodyParseFn: Node | ... | @@ -2891,7 +2823,6 @@ fn parseIf(arena: *Allocator, it: *TokenIterator, tree: *Tree, bodyParseFn: Node |
| 2891 | }); | 2823 | }); |
| 2892 | const else_node = try arena.create(Node.Else); | 2824 | const else_node = try arena.create(Node.Else); |
| 2893 | else_node.* = Node.Else{ | 2825 | else_node.* = Node.Else{ |
| 2894 | .base = Node{ .id = .Else }, | ||
| 2895 | .else_token = else_token, | 2826 | .else_token = else_token, |
| 2896 | .payload = payload, | 2827 | .payload = payload, |
| 2897 | .body = else_expr, | 2828 | .body = else_expr, |
| ... | @@ -2912,7 +2843,6 @@ fn parseDocComment(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node.D | ... | @@ -2912,7 +2843,6 @@ fn parseDocComment(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node.D |
| 2912 | 2843 | ||
| 2913 | const node = try arena.create(Node.DocComment); | 2844 | const node = try arena.create(Node.DocComment); |
| 2914 | node.* = Node.DocComment{ | 2845 | node.* = Node.DocComment{ |
| 2915 | .base = Node{ .id = .DocComment }, | ||
| 2916 | .lines = lines, | 2846 | .lines = lines, |
| 2917 | }; | 2847 | }; |
| 2918 | return node; | 2848 | return node; |
| ... | @@ -2924,7 +2854,6 @@ fn parseAppendedDocComment(arena: *Allocator, it: *TokenIterator, tree: *Tree, a | ... | @@ -2924,7 +2854,6 @@ fn parseAppendedDocComment(arena: *Allocator, it: *TokenIterator, tree: *Tree, a |
| 2924 | if (tree.tokensOnSameLine(after_token, comment_token)) { | 2854 | if (tree.tokensOnSameLine(after_token, comment_token)) { |
| 2925 | const node = try arena.create(Node.DocComment); | 2855 | const node = try arena.create(Node.DocComment); |
| 2926 | node.* = Node.DocComment{ | 2856 | node.* = Node.DocComment{ |
| 2927 | .base = Node{ .id = .DocComment }, | ||
| 2928 | .lines = Node.DocComment.LineList.init(arena), | 2857 | .lines = Node.DocComment.LineList.init(arena), |
| 2929 | }; | 2858 | }; |
| 2930 | try node.lines.push(comment_token); | 2859 | try node.lines.push(comment_token); |
| ... | @@ -3031,7 +2960,6 @@ fn parseBinOpExpr( | ... | @@ -3031,7 +2960,6 @@ fn parseBinOpExpr( |
| 3031 | fn createInfixOp(arena: *Allocator, index: TokenIndex, op: Node.InfixOp.Op) !*Node { | 2960 | fn createInfixOp(arena: *Allocator, index: TokenIndex, op: Node.InfixOp.Op) !*Node { |
| 3032 | const node = try arena.create(Node.InfixOp); | 2961 | const node = try arena.create(Node.InfixOp); |
| 3033 | node.* = Node.InfixOp{ | 2962 | node.* = Node.InfixOp{ |
| 3034 | .base = Node{ .id = .InfixOp }, | ||
| 3035 | .op_token = index, | 2963 | .op_token = index, |
| 3036 | .lhs = undefined, | 2964 | .lhs = undefined, |
| 3037 | .op = op, | 2965 | .op = op, |
lib/std/zig/render.zig+1| ... | @@ -193,6 +193,7 @@ fn renderRoot( | ... | @@ -193,6 +193,7 @@ fn renderRoot( |
| 193 | fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @TypeOf(stream).Child.Error!void { | 193 | fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @TypeOf(stream).Child.Error!void { |
| 194 | const first_token = node.firstToken(); | 194 | const first_token = node.firstToken(); |
| 195 | var prev_token = first_token; | 195 | var prev_token = first_token; |
| 196 | if (prev_token == 0) return; | ||
| 196 | while (tree.tokens.at(prev_token - 1).id == .DocComment) { | 197 | while (tree.tokens.at(prev_token - 1).id == .DocComment) { |
| 197 | prev_token -= 1; | 198 | prev_token -= 1; |
| 198 | } | 199 | } |
lib/std/zig/tokenizer.zig+64-53| ... | @@ -9,66 +9,77 @@ pub const Token = struct { | ... | @@ -9,66 +9,77 @@ pub const Token = struct { |
| 9 | pub const Keyword = struct { | 9 | pub const Keyword = struct { |
| 10 | bytes: []const u8, | 10 | bytes: []const u8, |
| 11 | id: Id, | 11 | id: Id, |
| 12 | hash: u32, | ||
| 13 | |||
| 14 | fn init(bytes: []const u8, id: Id) Keyword { | ||
| 15 | @setEvalBranchQuota(2000); | ||
| 16 | return .{ | ||
| 17 | .bytes = bytes, | ||
| 18 | .id = id, | ||
| 19 | .hash = std.hash_map.hashString(bytes), | ||
| 20 | }; | ||
| 21 | } | ||
| 12 | }; | 22 | }; |
| 13 | 23 | ||
| 14 | pub const keywords = [_]Keyword{ | 24 | pub const keywords = [_]Keyword{ |
| 15 | Keyword{ .bytes = "align", .id = Id.Keyword_align }, | 25 | Keyword.init("align", .Keyword_align), |
| 16 | Keyword{ .bytes = "allowzero", .id = Id.Keyword_allowzero }, | 26 | Keyword.init("allowzero", .Keyword_allowzero), |
| 17 | Keyword{ .bytes = "and", .id = Id.Keyword_and }, | 27 | Keyword.init("and", .Keyword_and), |
| 18 | Keyword{ .bytes = "anyframe", .id = Id.Keyword_anyframe }, | 28 | Keyword.init("anyframe", .Keyword_anyframe), |
| 19 | Keyword{ .bytes = "asm", .id = Id.Keyword_asm }, | 29 | Keyword.init("asm", .Keyword_asm), |
| 20 | Keyword{ .bytes = "async", .id = Id.Keyword_async }, | 30 | Keyword.init("async", .Keyword_async), |
| 21 | Keyword{ .bytes = "await", .id = Id.Keyword_await }, | 31 | Keyword.init("await", .Keyword_await), |
| 22 | Keyword{ .bytes = "break", .id = Id.Keyword_break }, | 32 | Keyword.init("break", .Keyword_break), |
| 23 | Keyword{ .bytes = "catch", .id = Id.Keyword_catch }, | 33 | Keyword.init("catch", .Keyword_catch), |
| 24 | Keyword{ .bytes = "comptime", .id = Id.Keyword_comptime }, | 34 | Keyword.init("comptime", .Keyword_comptime), |
| 25 | Keyword{ .bytes = "const", .id = Id.Keyword_const }, | 35 | Keyword.init("const", .Keyword_const), |
| 26 | Keyword{ .bytes = "continue", .id = Id.Keyword_continue }, | 36 | Keyword.init("continue", .Keyword_continue), |
| 27 | Keyword{ .bytes = "defer", .id = Id.Keyword_defer }, | 37 | Keyword.init("defer", .Keyword_defer), |
| 28 | Keyword{ .bytes = "else", .id = Id.Keyword_else }, | 38 | Keyword.init("else", .Keyword_else), |
| 29 | Keyword{ .bytes = "enum", .id = Id.Keyword_enum }, | 39 | Keyword.init("enum", .Keyword_enum), |
| 30 | Keyword{ .bytes = "errdefer", .id = Id.Keyword_errdefer }, | 40 | Keyword.init("errdefer", .Keyword_errdefer), |
| 31 | Keyword{ .bytes = "error", .id = Id.Keyword_error }, | 41 | Keyword.init("error", .Keyword_error), |
| 32 | Keyword{ .bytes = "export", .id = Id.Keyword_export }, | 42 | Keyword.init("export", .Keyword_export), |
| 33 | Keyword{ .bytes = "extern", .id = Id.Keyword_extern }, | 43 | Keyword.init("extern", .Keyword_extern), |
| 34 | Keyword{ .bytes = "false", .id = Id.Keyword_false }, | 44 | Keyword.init("false", .Keyword_false), |
| 35 | Keyword{ .bytes = "fn", .id = Id.Keyword_fn }, | 45 | Keyword.init("fn", .Keyword_fn), |
| 36 | Keyword{ .bytes = "for", .id = Id.Keyword_for }, | 46 | Keyword.init("for", .Keyword_for), |
| 37 | Keyword{ .bytes = "if", .id = Id.Keyword_if }, | 47 | Keyword.init("if", .Keyword_if), |
| 38 | Keyword{ .bytes = "inline", .id = Id.Keyword_inline }, | 48 | Keyword.init("inline", .Keyword_inline), |
| 39 | Keyword{ .bytes = "nakedcc", .id = Id.Keyword_nakedcc }, | 49 | Keyword.init("nakedcc", .Keyword_nakedcc), |
| 40 | Keyword{ .bytes = "noalias", .id = Id.Keyword_noalias }, | 50 | Keyword.init("noalias", .Keyword_noalias), |
| 41 | Keyword{ .bytes = "noasync", .id = Id.Keyword_noasync }, | 51 | Keyword.init("noasync", .Keyword_noasync), |
| 42 | Keyword{ .bytes = "noinline", .id = Id.Keyword_noinline }, | 52 | Keyword.init("noinline", .Keyword_noinline), |
| 43 | Keyword{ .bytes = "null", .id = Id.Keyword_null }, | 53 | Keyword.init("null", .Keyword_null), |
| 44 | Keyword{ .bytes = "or", .id = Id.Keyword_or }, | 54 | Keyword.init("or", .Keyword_or), |
| 45 | Keyword{ .bytes = "orelse", .id = Id.Keyword_orelse }, | 55 | Keyword.init("orelse", .Keyword_orelse), |
| 46 | Keyword{ .bytes = "packed", .id = Id.Keyword_packed }, | 56 | Keyword.init("packed", .Keyword_packed), |
| 47 | Keyword{ .bytes = "pub", .id = Id.Keyword_pub }, | 57 | Keyword.init("pub", .Keyword_pub), |
| 48 | Keyword{ .bytes = "resume", .id = Id.Keyword_resume }, | 58 | Keyword.init("resume", .Keyword_resume), |
| 49 | Keyword{ .bytes = "return", .id = Id.Keyword_return }, | 59 | Keyword.init("return", .Keyword_return), |
| 50 | Keyword{ .bytes = "linksection", .id = Id.Keyword_linksection }, | 60 | Keyword.init("linksection", .Keyword_linksection), |
| 51 | Keyword{ .bytes = "stdcallcc", .id = Id.Keyword_stdcallcc }, | 61 | Keyword.init("stdcallcc", .Keyword_stdcallcc), |
| 52 | Keyword{ .bytes = "struct", .id = Id.Keyword_struct }, | 62 | Keyword.init("struct", .Keyword_struct), |
| 53 | Keyword{ .bytes = "suspend", .id = Id.Keyword_suspend }, | 63 | Keyword.init("suspend", .Keyword_suspend), |
| 54 | Keyword{ .bytes = "switch", .id = Id.Keyword_switch }, | 64 | Keyword.init("switch", .Keyword_switch), |
| 55 | Keyword{ .bytes = "test", .id = Id.Keyword_test }, | 65 | Keyword.init("test", .Keyword_test), |
| 56 | Keyword{ .bytes = "threadlocal", .id = Id.Keyword_threadlocal }, | 66 | Keyword.init("threadlocal", .Keyword_threadlocal), |
| 57 | Keyword{ .bytes = "true", .id = Id.Keyword_true }, | 67 | Keyword.init("true", .Keyword_true), |
| 58 | Keyword{ .bytes = "try", .id = Id.Keyword_try }, | 68 | Keyword.init("try", .Keyword_try), |
| 59 | Keyword{ .bytes = "undefined", .id = Id.Keyword_undefined }, | 69 | Keyword.init("undefined", .Keyword_undefined), |
| 60 | Keyword{ .bytes = "union", .id = Id.Keyword_union }, | 70 | Keyword.init("union", .Keyword_union), |
| 61 | Keyword{ .bytes = "unreachable", .id = Id.Keyword_unreachable }, | 71 | Keyword.init("unreachable", .Keyword_unreachable), |
| 62 | Keyword{ .bytes = "usingnamespace", .id = Id.Keyword_usingnamespace }, | 72 | Keyword.init("usingnamespace", .Keyword_usingnamespace), |
| 63 | Keyword{ .bytes = "var", .id = Id.Keyword_var }, | 73 | Keyword.init("var", .Keyword_var), |
| 64 | Keyword{ .bytes = "volatile", .id = Id.Keyword_volatile }, | 74 | Keyword.init("volatile", .Keyword_volatile), |
| 65 | Keyword{ .bytes = "while", .id = Id.Keyword_while }, | 75 | Keyword.init("while", .Keyword_while), |
| 66 | }; | 76 | }; |
| 67 | 77 | ||
| 68 | // TODO perfect hash at comptime | 78 | // TODO perfect hash at comptime |
| 69 | fn getKeyword(bytes: []const u8) ?Id { | 79 | pub fn getKeyword(bytes: []const u8) ?Id { |
| 80 | var hash = std.hash_map.hashString(bytes); | ||
| 70 | for (keywords) |kw| { | 81 | for (keywords) |kw| { |
| 71 | if (mem.eql(u8, kw.bytes, bytes)) { | 82 | if (kw.hash == hash and mem.eql(u8, kw.bytes, bytes)) { |
| 72 | return kw.id; | 83 | return kw.id; |
| 73 | } | 84 | } |
| 74 | } | 85 | } |
src-self-hosted/clang.zig+15-1| ... | @@ -713,6 +713,10 @@ pub const ZigClangRecordDecl_field_iterator = extern struct { | ... | @@ -713,6 +713,10 @@ pub const ZigClangRecordDecl_field_iterator = extern struct { |
| 713 | opaque: *c_void, | 713 | opaque: *c_void, |
| 714 | }; | 714 | }; |
| 715 | 715 | ||
| 716 | pub const ZigClangEnumDecl_enumerator_iterator = extern struct { | ||
| 717 | opaque: *c_void, | ||
| 718 | }; | ||
| 719 | |||
| 716 | pub extern fn ZigClangSourceManager_getSpellingLoc(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation; | 720 | pub extern fn ZigClangSourceManager_getSpellingLoc(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation; |
| 717 | pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*:0]const u8; | 721 | pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*:0]const u8; |
| 718 | pub extern fn ZigClangSourceManager_getSpellingLineNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; | 722 | pub extern fn ZigClangSourceManager_getSpellingLineNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; |
| ... | @@ -723,7 +727,7 @@ pub extern fn ZigClangASTUnit_getASTContext(self: ?*struct_ZigClangASTUnit) ?*st | ... | @@ -723,7 +727,7 @@ pub extern fn ZigClangASTUnit_getASTContext(self: ?*struct_ZigClangASTUnit) ?*st |
| 723 | pub extern fn ZigClangASTUnit_getSourceManager(self: *struct_ZigClangASTUnit) *struct_ZigClangSourceManager; | 727 | pub extern fn ZigClangASTUnit_getSourceManager(self: *struct_ZigClangASTUnit) *struct_ZigClangSourceManager; |
| 724 | pub extern fn ZigClangASTUnit_visitLocalTopLevelDecls(self: *struct_ZigClangASTUnit, context: ?*c_void, Fn: ?extern fn (?*c_void, *const struct_ZigClangDecl) bool) bool; | 728 | pub extern fn ZigClangASTUnit_visitLocalTopLevelDecls(self: *struct_ZigClangASTUnit, context: ?*c_void, Fn: ?extern fn (?*c_void, *const struct_ZigClangDecl) bool) bool; |
| 725 | pub extern fn ZigClangRecordType_getDecl(record_ty: ?*const struct_ZigClangRecordType) *const struct_ZigClangRecordDecl; | 729 | pub extern fn ZigClangRecordType_getDecl(record_ty: ?*const struct_ZigClangRecordType) *const struct_ZigClangRecordDecl; |
| 726 | pub extern fn ZigClangEnumType_getDecl(record_ty: ?*const struct_ZigClangEnumType) ?*const struct_ZigClangEnumDecl; | 730 | pub extern fn ZigClangEnumType_getDecl(record_ty: ?*const struct_ZigClangEnumType) *const struct_ZigClangEnumDecl; |
| 727 | pub extern fn ZigClangRecordDecl_getCanonicalDecl(record_decl: ?*const struct_ZigClangRecordDecl) ?*const struct_ZigClangTagDecl; | 731 | pub extern fn ZigClangRecordDecl_getCanonicalDecl(record_decl: ?*const struct_ZigClangRecordDecl) ?*const struct_ZigClangTagDecl; |
| 728 | pub extern fn ZigClangEnumDecl_getCanonicalDecl(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl; | 732 | pub extern fn ZigClangEnumDecl_getCanonicalDecl(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl; |
| 729 | pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(self: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl; | 733 | pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(self: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl; |
| ... | @@ -742,6 +746,11 @@ pub extern fn ZigClangRecordDecl_field_iterator_next(ZigClangRecordDecl_field_it | ... | @@ -742,6 +746,11 @@ pub extern fn ZigClangRecordDecl_field_iterator_next(ZigClangRecordDecl_field_it |
| 742 | pub extern fn ZigClangRecordDecl_field_iterator_deref(ZigClangRecordDecl_field_iterator) *const struct_ZigClangFieldDecl; | 746 | pub extern fn ZigClangRecordDecl_field_iterator_deref(ZigClangRecordDecl_field_iterator) *const struct_ZigClangFieldDecl; |
| 743 | pub extern fn ZigClangRecordDecl_field_iterator_neq(ZigClangRecordDecl_field_iterator, ZigClangRecordDecl_field_iterator) bool; | 747 | pub extern fn ZigClangRecordDecl_field_iterator_neq(ZigClangRecordDecl_field_iterator, ZigClangRecordDecl_field_iterator) bool; |
| 744 | pub extern fn ZigClangEnumDecl_getIntegerType(self: ?*const struct_ZigClangEnumDecl) struct_ZigClangQualType; | 748 | pub extern fn ZigClangEnumDecl_getIntegerType(self: ?*const struct_ZigClangEnumDecl) struct_ZigClangQualType; |
| 749 | pub extern fn ZigClangEnumDecl_enumerator_begin(*const ZigClangEnumDecl) ZigClangEnumDecl_enumerator_iterator; | ||
| 750 | pub extern fn ZigClangEnumDecl_enumerator_end(*const ZigClangEnumDecl) ZigClangEnumDecl_enumerator_iterator; | ||
| 751 | pub extern fn ZigClangEnumDecl_enumerator_iterator_next(ZigClangEnumDecl_enumerator_iterator) ZigClangEnumDecl_enumerator_iterator; | ||
| 752 | pub extern fn ZigClangEnumDecl_enumerator_iterator_deref(ZigClangEnumDecl_enumerator_iterator) *const ZigClangEnumConstantDecl; | ||
| 753 | pub extern fn ZigClangEnumDecl_enumerator_iterator_neq(ZigClangEnumDecl_enumerator_iterator, ZigClangEnumDecl_enumerator_iterator) bool; | ||
| 745 | pub extern fn ZigClangDecl_getName_bytes_begin(decl: ?*const struct_ZigClangDecl) [*c]const u8; | 754 | pub extern fn ZigClangDecl_getName_bytes_begin(decl: ?*const struct_ZigClangDecl) [*c]const u8; |
| 746 | pub extern fn ZigClangSourceLocation_eq(a: struct_ZigClangSourceLocation, b: struct_ZigClangSourceLocation) bool; | 755 | pub extern fn ZigClangSourceLocation_eq(a: struct_ZigClangSourceLocation, b: struct_ZigClangSourceLocation) bool; |
| 747 | pub extern fn ZigClangTypedefType_getDecl(self: ?*const struct_ZigClangTypedefType) *const struct_ZigClangTypedefNameDecl; | 756 | pub extern fn ZigClangTypedefType_getDecl(self: ?*const struct_ZigClangTypedefType) *const struct_ZigClangTypedefNameDecl; |
| ... | @@ -992,6 +1001,8 @@ pub extern fn ZigClangBinaryOperator_getLHS(*const ZigClangBinaryOperator) *cons | ... | @@ -992,6 +1001,8 @@ pub extern fn ZigClangBinaryOperator_getLHS(*const ZigClangBinaryOperator) *cons |
| 992 | pub extern fn ZigClangBinaryOperator_getRHS(*const ZigClangBinaryOperator) *const ZigClangExpr; | 1001 | pub extern fn ZigClangBinaryOperator_getRHS(*const ZigClangBinaryOperator) *const ZigClangExpr; |
| 993 | pub extern fn ZigClangBinaryOperator_getType(*const ZigClangBinaryOperator) ZigClangQualType; | 1002 | pub extern fn ZigClangBinaryOperator_getType(*const ZigClangBinaryOperator) ZigClangQualType; |
| 994 | 1003 | ||
| 1004 | pub extern fn ZigClangDecayedType_getDecayedType(*const ZigClangDecayedType) ZigClangQualType; | ||
| 1005 | |||
| 995 | pub extern fn ZigClangStringLiteral_getKind(*const ZigClangStringLiteral) ZigClangStringLiteral_StringKind; | 1006 | pub extern fn ZigClangStringLiteral_getKind(*const ZigClangStringLiteral) ZigClangStringLiteral_StringKind; |
| 996 | pub extern fn ZigClangStringLiteral_getString_bytes_begin_size(*const ZigClangStringLiteral, *usize) [*c]const u8; | 1007 | pub extern fn ZigClangStringLiteral_getString_bytes_begin_size(*const ZigClangStringLiteral, *usize) [*c]const u8; |
| 997 | 1008 | ||
| ... | @@ -1000,3 +1011,6 @@ pub extern fn ZigClangParenExpr_getSubExpr(*const ZigClangParenExpr) *const ZigC | ... | @@ -1000,3 +1011,6 @@ pub extern fn ZigClangParenExpr_getSubExpr(*const ZigClangParenExpr) *const ZigC |
| 1000 | pub extern fn ZigClangFieldDecl_isBitField(*const struct_ZigClangFieldDecl) bool; | 1011 | pub extern fn ZigClangFieldDecl_isBitField(*const struct_ZigClangFieldDecl) bool; |
| 1001 | pub extern fn ZigClangFieldDecl_getType(*const struct_ZigClangFieldDecl) struct_ZigClangQualType; | 1012 | pub extern fn ZigClangFieldDecl_getType(*const struct_ZigClangFieldDecl) struct_ZigClangQualType; |
| 1002 | pub extern fn ZigClangFieldDecl_getLocation(*const struct_ZigClangFieldDecl) struct_ZigClangSourceLocation; | 1013 | pub extern fn ZigClangFieldDecl_getLocation(*const struct_ZigClangFieldDecl) struct_ZigClangSourceLocation; |
| 1014 | |||
| 1015 | pub extern fn ZigClangEnumConstantDecl_getInitExpr(*const ZigClangEnumConstantDecl) ?*const ZigClangExpr; | ||
| 1016 | pub extern fn ZigClangEnumConstantDecl_getInitVal(*const ZigClangEnumConstantDecl) *const ZigClangAPSInt; |
src-self-hosted/translate_c.zig+287-77| ... | @@ -15,7 +15,7 @@ pub const Error = error{OutOfMemory}; | ... | @@ -15,7 +15,7 @@ pub const Error = error{OutOfMemory}; |
| 15 | const TypeError = Error || error{UnsupportedType}; | 15 | const TypeError = Error || error{UnsupportedType}; |
| 16 | const TransError = TypeError || error{UnsupportedTranslation}; | 16 | const TransError = TypeError || error{UnsupportedTranslation}; |
| 17 | 17 | ||
| 18 | const DeclTable = std.HashMap(usize, void, addrHash, addrEql); | 18 | const DeclTable = std.HashMap(usize, []const u8, addrHash, addrEql); |
| 19 | 19 | ||
| 20 | fn addrHash(x: usize) u32 { | 20 | fn addrHash(x: usize) u32 { |
| 21 | switch (@typeInfo(usize).Int.bits) { | 21 | switch (@typeInfo(usize).Int.bits) { |
| ... | @@ -109,6 +109,12 @@ const Context = struct { | ... | @@ -109,6 +109,12 @@ const Context = struct { |
| 109 | global_scope: *Scope.Root, | 109 | global_scope: *Scope.Root, |
| 110 | ptr_params: std.BufSet, | 110 | ptr_params: std.BufSet, |
| 111 | clang_context: *ZigClangASTContext, | 111 | clang_context: *ZigClangASTContext, |
| 112 | mangle_count: u64 = 0, | ||
| 113 | |||
| 114 | fn getMangle(c: *Context) u64 { | ||
| 115 | c.mangle_count += 1; | ||
| 116 | return c.mangle_count; | ||
| 117 | } | ||
| 112 | 118 | ||
| 113 | fn a(c: *Context) *std.mem.Allocator { | 119 | fn a(c: *Context) *std.mem.Allocator { |
| 114 | return &c.tree.arena_allocator.allocator; | 120 | return &c.tree.arena_allocator.allocator; |
| ... | @@ -239,7 +245,7 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { | ... | @@ -239,7 +245,7 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { |
| 239 | return resolveTypeDef(c, @ptrCast(*const ZigClangTypedefNameDecl, decl)); | 245 | return resolveTypeDef(c, @ptrCast(*const ZigClangTypedefNameDecl, decl)); |
| 240 | }, | 246 | }, |
| 241 | .Enum => { | 247 | .Enum => { |
| 242 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums", .{}); | 248 | _ = try transEnumDecl(c, @ptrCast(*const ZigClangEnumDecl, decl)); |
| 243 | }, | 249 | }, |
| 244 | .Record => { | 250 | .Record => { |
| 245 | return resolveRecordDecl(c, @ptrCast(*const ZigClangRecordDecl, decl)); | 251 | return resolveRecordDecl(c, @ptrCast(*const ZigClangRecordDecl, decl)); |
| ... | @@ -255,9 +261,10 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { | ... | @@ -255,9 +261,10 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { |
| 255 | } | 261 | } |
| 256 | 262 | ||
| 257 | fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | 263 | fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 258 | if (try c.decl_table.put(@ptrToInt(fn_decl), {})) |_| return; // Avoid processing this decl twice | 264 | if (c.decl_table.contains(@ptrToInt(fn_decl))) return; // Avoid processing this decl twice |
| 259 | const rp = makeRestorePoint(c); | 265 | const rp = makeRestorePoint(c); |
| 260 | const fn_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, fn_decl))); | 266 | const fn_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, fn_decl))); |
| 267 | _ = try c.decl_table.put(@ptrToInt(fn_decl), fn_name); | ||
| 261 | const fn_decl_loc = ZigClangFunctionDecl_getLocation(fn_decl); | 268 | const fn_decl_loc = ZigClangFunctionDecl_getLocation(fn_decl); |
| 262 | const fn_qt = ZigClangFunctionDecl_getType(fn_decl); | 269 | const fn_qt = ZigClangFunctionDecl_getType(fn_decl); |
| 263 | const fn_type = ZigClangQualType_getTypePtr(fn_qt); | 270 | const fn_type = ZigClangQualType_getTypePtr(fn_qt); |
| ... | @@ -319,7 +326,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -319,7 +326,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 319 | } | 326 | } |
| 320 | 327 | ||
| 321 | fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { | 328 | fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { |
| 322 | if (try c.decl_table.put(@ptrToInt(var_decl), {})) |_| return; // Avoid processing this decl twice | 329 | if (c.decl_table.contains(@ptrToInt(var_decl))) return; // Avoid processing this decl twice |
| 323 | const rp = makeRestorePoint(c); | 330 | const rp = makeRestorePoint(c); |
| 324 | const visib_tok = try appendToken(c, .Keyword_pub, "pub"); | 331 | const visib_tok = try appendToken(c, .Keyword_pub, "pub"); |
| 325 | 332 | ||
| ... | @@ -330,6 +337,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { | ... | @@ -330,6 +337,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { |
| 330 | 337 | ||
| 331 | var scope = &c.global_scope.base; | 338 | var scope = &c.global_scope.base; |
| 332 | const var_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, var_decl))); | 339 | const var_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, var_decl))); |
| 340 | _ = try c.decl_table.put(@ptrToInt(var_decl), var_name); | ||
| 333 | const var_decl_loc = ZigClangVarDecl_getLocation(var_decl); | 341 | const var_decl_loc = ZigClangVarDecl_getLocation(var_decl); |
| 334 | 342 | ||
| 335 | const qual_type = ZigClangVarDecl_getTypeSourceInfo_getType(var_decl); | 343 | const qual_type = ZigClangVarDecl_getTypeSourceInfo_getType(var_decl); |
| ... | @@ -348,7 +356,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { | ... | @@ -348,7 +356,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { |
| 348 | else | 356 | else |
| 349 | try appendToken(c, .Keyword_var, "var"); | 357 | try appendToken(c, .Keyword_var, "var"); |
| 350 | 358 | ||
| 351 | const name_tok = try appendToken(c, .Identifier, var_name); | 359 | const name_tok = try appendIdentifier(c, var_name); |
| 352 | 360 | ||
| 353 | _ = try appendToken(c, .Colon, ":"); | 361 | _ = try appendToken(c, .Colon, ":"); |
| 354 | const type_node = transQualType(rp, qual_type, var_decl_loc) catch |err| switch (err) { | 362 | const type_node = transQualType(rp, qual_type, var_decl_loc) catch |err| switch (err) { |
| ... | @@ -381,7 +389,6 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { | ... | @@ -381,7 +389,6 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { |
| 381 | 389 | ||
| 382 | const node = try c.a().create(ast.Node.VarDecl); | 390 | const node = try c.a().create(ast.Node.VarDecl); |
| 383 | node.* = ast.Node.VarDecl{ | 391 | node.* = ast.Node.VarDecl{ |
| 384 | .base = ast.Node{ .id = .VarDecl }, | ||
| 385 | .doc_comments = null, | 392 | .doc_comments = null, |
| 386 | .visib_token = visib_tok, | 393 | .visib_token = visib_tok, |
| 387 | .thread_local_token = thread_local_token, | 394 | .thread_local_token = thread_local_token, |
| ... | @@ -401,13 +408,16 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { | ... | @@ -401,13 +408,16 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void { |
| 401 | } | 408 | } |
| 402 | 409 | ||
| 403 | fn resolveTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl) Error!void { | 410 | fn resolveTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl) Error!void { |
| 404 | if (try c.decl_table.put(@ptrToInt(ZigClangTypedefNameDecl_getCanonicalDecl(typedef_decl)), {})) |_| return; // Avoid processing this decl twice | 411 | if (c.decl_table.contains( |
| 412 | @ptrToInt(ZigClangTypedefNameDecl_getCanonicalDecl(typedef_decl)), | ||
| 413 | )) return; // Avoid processing this decl twice | ||
| 405 | const rp = makeRestorePoint(c); | 414 | const rp = makeRestorePoint(c); |
| 406 | const visib_tok = try appendToken(c, .Keyword_pub, "pub"); | 415 | const visib_tok = try appendToken(c, .Keyword_pub, "pub"); |
| 407 | const const_tok = try appendToken(c, .Keyword_const, "const"); | 416 | const const_tok = try appendToken(c, .Keyword_const, "const"); |
| 408 | 417 | ||
| 409 | const typedef_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, typedef_decl))); | 418 | const typedef_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, typedef_decl))); |
| 410 | const name_tok = try appendToken(c, .Identifier, typedef_name); | 419 | _ = try c.decl_table.put(@ptrToInt(ZigClangTypedefNameDecl_getCanonicalDecl(typedef_decl)), typedef_name); |
| 420 | const name_tok = try appendIdentifier(c, typedef_name); | ||
| 411 | const eq_tok = try appendToken(c, .Equal, "="); | 421 | const eq_tok = try appendToken(c, .Equal, "="); |
| 412 | 422 | ||
| 413 | const child_qt = ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl); | 423 | const child_qt = ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl); |
| ... | @@ -421,7 +431,6 @@ fn resolveTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl) Err | ... | @@ -421,7 +431,6 @@ fn resolveTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl) Err |
| 421 | 431 | ||
| 422 | const node = try c.a().create(ast.Node.VarDecl); | 432 | const node = try c.a().create(ast.Node.VarDecl); |
| 423 | node.* = ast.Node.VarDecl{ | 433 | node.* = ast.Node.VarDecl{ |
| 424 | .base = ast.Node{ .id = .VarDecl }, | ||
| 425 | .doc_comments = null, | 434 | .doc_comments = null, |
| 426 | .visib_token = visib_tok, | 435 | .visib_token = visib_tok, |
| 427 | .thread_local_token = null, | 436 | .thread_local_token = null, |
| ... | @@ -441,7 +450,7 @@ fn resolveTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl) Err | ... | @@ -441,7 +450,7 @@ fn resolveTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl) Err |
| 441 | } | 450 | } |
| 442 | 451 | ||
| 443 | fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!void { | 452 | fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!void { |
| 444 | if (try c.decl_table.put(@ptrToInt(ZigClangRecordDecl_getCanonicalDecl(record_decl)), {})) |_| return; // Avoid processing this decl twice | 453 | if (c.decl_table.contains(@ptrToInt(ZigClangRecordDecl_getCanonicalDecl(record_decl)))) return; // Avoid processing this decl twice |
| 445 | const rp = makeRestorePoint(c); | 454 | const rp = makeRestorePoint(c); |
| 446 | 455 | ||
| 447 | const bare_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, record_decl))); | 456 | const bare_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, record_decl))); |
| ... | @@ -451,7 +460,7 @@ fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error! | ... | @@ -451,7 +460,7 @@ fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error! |
| 451 | else if (ZigClangRecordDecl_isStruct(record_decl)) | 460 | else if (ZigClangRecordDecl_isStruct(record_decl)) |
| 452 | "struct" | 461 | "struct" |
| 453 | else | 462 | else |
| 454 | return failDecl(c, ZigClangRecordDecl_getLocation(record_decl), bare_name, "record {} is not a struct or union", .{bare_name}); | 463 | return emitWarning(c, ZigClangRecordDecl_getLocation(record_decl), "record {} is not a struct or union", .{bare_name}); |
| 455 | 464 | ||
| 456 | if (ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl) or bare_name.len == 0) | 465 | if (ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl) or bare_name.len == 0) |
| 457 | return; | 466 | return; |
| ... | @@ -460,7 +469,8 @@ fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error! | ... | @@ -460,7 +469,8 @@ fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error! |
| 460 | const const_tok = try appendToken(c, .Keyword_const, "const"); | 469 | const const_tok = try appendToken(c, .Keyword_const, "const"); |
| 461 | 470 | ||
| 462 | const name = try std.fmt.allocPrint(c.a(), "{}_{}", .{ container_kind_name, bare_name }); | 471 | const name = try std.fmt.allocPrint(c.a(), "{}_{}", .{ container_kind_name, bare_name }); |
| 463 | const name_tok = try appendToken(c, .Identifier, name); | 472 | _ = try c.decl_table.put(@ptrToInt(ZigClangRecordDecl_getCanonicalDecl(record_decl)), name); |
| 473 | const name_tok = try appendIdentifier(c, name); | ||
| 464 | 474 | ||
| 465 | const eq_tok = try appendToken(c, .Equal, "="); | 475 | const eq_tok = try appendToken(c, .Equal, "="); |
| 466 | const init_node = transRecordDecl(c, record_decl) catch |err| switch (err) { | 476 | const init_node = transRecordDecl(c, record_decl) catch |err| switch (err) { |
| ... | @@ -473,7 +483,6 @@ fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error! | ... | @@ -473,7 +483,6 @@ fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error! |
| 473 | 483 | ||
| 474 | const node = try c.a().create(ast.Node.VarDecl); | 484 | const node = try c.a().create(ast.Node.VarDecl); |
| 475 | node.* = ast.Node.VarDecl{ | 485 | node.* = ast.Node.VarDecl{ |
| 476 | .base = ast.Node{ .id = .VarDecl }, | ||
| 477 | .doc_comments = null, | 486 | .doc_comments = null, |
| 478 | .visib_token = visib_tok, | 487 | .visib_token = visib_tok, |
| 479 | .thread_local_token = null, | 488 | .thread_local_token = null, |
| ... | @@ -497,14 +506,13 @@ fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error! | ... | @@ -497,14 +506,13 @@ fn resolveRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error! |
| 497 | fn createAlias(c: *Context, alias: var) !void { | 506 | fn createAlias(c: *Context, alias: var) !void { |
| 498 | const visib_tok = try appendToken(c, .Keyword_pub, "pub"); | 507 | const visib_tok = try appendToken(c, .Keyword_pub, "pub"); |
| 499 | const mut_tok = try appendToken(c, .Keyword_const, "const"); | 508 | const mut_tok = try appendToken(c, .Keyword_const, "const"); |
| 500 | const name_tok = try appendToken(c, .Identifier, alias.alias); | 509 | const name_tok = try appendIdentifier(c, alias.alias); |
| 501 | 510 | ||
| 502 | const eq_tok = try appendToken(c, .Equal, "="); | 511 | const eq_tok = try appendToken(c, .Equal, "="); |
| 503 | const init_node = try appendIdentifier(c, alias.name); | 512 | const init_node = try transCreateNodeIdentifier(c, alias.name); |
| 504 | 513 | ||
| 505 | const node = try c.a().create(ast.Node.VarDecl); | 514 | const node = try c.a().create(ast.Node.VarDecl); |
| 506 | node.* = ast.Node.VarDecl{ | 515 | node.* = ast.Node.VarDecl{ |
| 507 | .base = ast.Node{ .id = .VarDecl }, | ||
| 508 | .doc_comments = null, | 516 | .doc_comments = null, |
| 509 | .visib_token = visib_tok, | 517 | .visib_token = visib_tok, |
| 510 | .thread_local_token = null, | 518 | .thread_local_token = null, |
| ... | @@ -787,7 +795,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe | ... | @@ -787,7 +795,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe |
| 787 | const c_name = try c.str(ZigClangDecl_getName_bytes_begin( | 795 | const c_name = try c.str(ZigClangDecl_getName_bytes_begin( |
| 788 | @ptrCast(*const ZigClangDecl, var_decl), | 796 | @ptrCast(*const ZigClangDecl, var_decl), |
| 789 | )); | 797 | )); |
| 790 | const name_token = try appendToken(c, .Identifier, c_name); | 798 | const name_token = try appendIdentifier(c, c_name); |
| 791 | 799 | ||
| 792 | const var_scope = try c.a().create(Scope.Var); | 800 | const var_scope = try c.a().create(Scope.Var); |
| 793 | var_scope.* = Scope.Var{ | 801 | var_scope.* = Scope.Var{ |
| ... | @@ -810,7 +818,6 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe | ... | @@ -810,7 +818,6 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe |
| 810 | 818 | ||
| 811 | const node = try c.a().create(ast.Node.VarDecl); | 819 | const node = try c.a().create(ast.Node.VarDecl); |
| 812 | node.* = ast.Node.VarDecl{ | 820 | node.* = ast.Node.VarDecl{ |
| 813 | .base = ast.Node{ .id = .VarDecl }, | ||
| 814 | .doc_comments = null, | 821 | .doc_comments = null, |
| 815 | .visib_token = null, | 822 | .visib_token = null, |
| 816 | .thread_local_token = thread_local_token, | 823 | .thread_local_token = thread_local_token, |
| ... | @@ -856,7 +863,7 @@ fn transDeclRefExpr( | ... | @@ -856,7 +863,7 @@ fn transDeclRefExpr( |
| 856 | const c_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, value_decl))); | 863 | const c_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, value_decl))); |
| 857 | const zig_name = transLookupZigIdentifier(scope, c_name); | 864 | const zig_name = transLookupZigIdentifier(scope, c_name); |
| 858 | if (lrvalue == .l_value) try rp.c.ptr_params.put(zig_name); | 865 | if (lrvalue == .l_value) try rp.c.ptr_params.put(zig_name); |
| 859 | const node = try appendIdentifier(rp.c, zig_name); | 866 | const node = try transCreateNodeIdentifier(rp.c, zig_name); |
| 860 | return TransResult{ | 867 | return TransResult{ |
| 861 | .node = node, | 868 | .node = node, |
| 862 | .node_scope = scope, | 869 | .node_scope = scope, |
| ... | @@ -978,7 +985,6 @@ fn transStringLiteral( | ... | @@ -978,7 +985,6 @@ fn transStringLiteral( |
| 978 | const token = try appendToken(rp.c, .StringLiteral, buf); | 985 | const token = try appendToken(rp.c, .StringLiteral, buf); |
| 979 | const node = try rp.c.a().create(ast.Node.StringLiteral); | 986 | const node = try rp.c.a().create(ast.Node.StringLiteral); |
| 980 | node.* = ast.Node.StringLiteral{ | 987 | node.* = ast.Node.StringLiteral{ |
| 981 | .base = ast.Node{ .id = .StringLiteral }, | ||
| 982 | .token = token, | 988 | .token = token, |
| 983 | }; | 989 | }; |
| 984 | const res = TransResult{ | 990 | const res = TransResult{ |
| ... | @@ -1145,7 +1151,6 @@ fn transInitListExpr( | ... | @@ -1145,7 +1151,6 @@ fn transInitListExpr( |
| 1145 | const mul_tok = try appendToken(rp.c, .AsteriskAsterisk, "**"); | 1151 | const mul_tok = try appendToken(rp.c, .AsteriskAsterisk, "**"); |
| 1146 | const mul_node = try rp.c.a().create(ast.Node.InfixOp); | 1152 | const mul_node = try rp.c.a().create(ast.Node.InfixOp); |
| 1147 | mul_node.* = .{ | 1153 | mul_node.* = .{ |
| 1148 | .base = .{ .id = .InfixOp }, | ||
| 1149 | .op_token = mul_tok, | 1154 | .op_token = mul_tok, |
| 1150 | .lhs = &filler_init_node.base, | 1155 | .lhs = &filler_init_node.base, |
| 1151 | .op = .ArrayMult, | 1156 | .op = .ArrayMult, |
| ... | @@ -1164,7 +1169,6 @@ fn transInitListExpr( | ... | @@ -1164,7 +1169,6 @@ fn transInitListExpr( |
| 1164 | 1169 | ||
| 1165 | const cat_node = try rp.c.a().create(ast.Node.InfixOp); | 1170 | const cat_node = try rp.c.a().create(ast.Node.InfixOp); |
| 1166 | cat_node.* = .{ | 1171 | cat_node.* = .{ |
| 1167 | .base = .{ .id = .InfixOp }, | ||
| 1168 | .op_token = cat_tok, | 1172 | .op_token = cat_tok, |
| 1169 | .lhs = &init_node.base, | 1173 | .lhs = &init_node.base, |
| 1170 | .op = .ArrayCat, | 1174 | .op = .ArrayCat, |
| ... | @@ -1292,11 +1296,10 @@ fn maybeSuppressResult( | ... | @@ -1292,11 +1296,10 @@ fn maybeSuppressResult( |
| 1292 | if (used == .used) return result; | 1296 | if (used == .used) return result; |
| 1293 | // NOTE: This is backwards, but the semicolon must immediately follow the node. | 1297 | // NOTE: This is backwards, but the semicolon must immediately follow the node. |
| 1294 | _ = try appendToken(rp.c, .Semicolon, ";"); | 1298 | _ = try appendToken(rp.c, .Semicolon, ";"); |
| 1295 | const lhs = try appendIdentifier(rp.c, "_"); | 1299 | const lhs = try transCreateNodeIdentifier(rp.c, "_"); |
| 1296 | const op_token = try appendToken(rp.c, .Equal, "="); | 1300 | const op_token = try appendToken(rp.c, .Equal, "="); |
| 1297 | const op_node = try rp.c.a().create(ast.Node.InfixOp); | 1301 | const op_node = try rp.c.a().create(ast.Node.InfixOp); |
| 1298 | op_node.* = ast.Node.InfixOp{ | 1302 | op_node.* = ast.Node.InfixOp{ |
| 1299 | .base = ast.Node{ .id = .InfixOp }, | ||
| 1300 | .op_token = op_token, | 1303 | .op_token = op_token, |
| 1301 | .lhs = lhs, | 1304 | .lhs = lhs, |
| 1302 | .op = .Assign, | 1305 | .op = .Assign, |
| ... | @@ -1352,7 +1355,6 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) TypeErro | ... | @@ -1352,7 +1355,6 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) TypeErro |
| 1352 | 1355 | ||
| 1353 | const container_node = try c.a().create(ast.Node.ContainerDecl); | 1356 | const container_node = try c.a().create(ast.Node.ContainerDecl); |
| 1354 | container_node.* = .{ | 1357 | container_node.* = .{ |
| 1355 | .base = ast.Node{ .id = .ContainerDecl }, | ||
| 1356 | .layout_token = extern_tok, | 1358 | .layout_token = extern_tok, |
| 1357 | .kind_token = container_tok, | 1359 | .kind_token = container_tok, |
| 1358 | .init_arg_expr = .None, | 1360 | .init_arg_expr = .None, |
| ... | @@ -1374,7 +1376,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) TypeErro | ... | @@ -1374,7 +1376,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) TypeErro |
| 1374 | return node; | 1376 | return node; |
| 1375 | } | 1377 | } |
| 1376 | 1378 | ||
| 1377 | const field_name = try appendToken(c, .Identifier, try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, field_decl)))); | 1379 | const field_name = try appendIdentifier(c, try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, field_decl)))); |
| 1378 | _ = try appendToken(c, .Colon, ":"); | 1380 | _ = try appendToken(c, .Colon, ":"); |
| 1379 | const field_type = try transQualType(rp, ZigClangFieldDecl_getType(field_decl), field_loc); | 1381 | const field_type = try transQualType(rp, ZigClangFieldDecl_getType(field_decl), field_loc); |
| 1380 | 1382 | ||
| ... | @@ -1396,6 +1398,195 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) TypeErro | ... | @@ -1396,6 +1398,195 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) TypeErro |
| 1396 | return &container_node.base; | 1398 | return &container_node.base; |
| 1397 | } | 1399 | } |
| 1398 | 1400 | ||
| 1401 | fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.Node { | ||
| 1402 | if (c.decl_table.get(@ptrToInt(ZigClangEnumDecl_getCanonicalDecl(enum_decl)))) |name| | ||
| 1403 | return try transCreateNodeIdentifier(c, name.value); // Avoid processing this decl twice | ||
| 1404 | const rp = makeRestorePoint(c); | ||
| 1405 | const enum_loc = ZigClangEnumDecl_getLocation(enum_decl); | ||
| 1406 | |||
| 1407 | const visib_tok = try appendToken(c, .Keyword_pub, "pub"); | ||
| 1408 | const const_tok = try appendToken(c, .Keyword_const, "const"); | ||
| 1409 | |||
| 1410 | var bare_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, enum_decl))); | ||
| 1411 | var is_unnamed = false; | ||
| 1412 | if (bare_name.len == 0) { | ||
| 1413 | bare_name = try std.fmt.allocPrint(c.a(), "unnamed_{}", .{c.getMangle()}); | ||
| 1414 | is_unnamed = true; | ||
| 1415 | } | ||
| 1416 | |||
| 1417 | const name = try std.fmt.allocPrint(c.a(), "enum_{}", .{bare_name}); | ||
| 1418 | _ = try c.decl_table.put(@ptrToInt(ZigClangEnumDecl_getCanonicalDecl(enum_decl)), name); | ||
| 1419 | const name_tok = try appendIdentifier(c, name); | ||
| 1420 | const eq_tok = try appendToken(c, .Equal, "="); | ||
| 1421 | |||
| 1422 | const init_node = if (ZigClangEnumDecl_getDefinition(enum_decl)) |enum_def| blk: { | ||
| 1423 | var pure_enum = true; | ||
| 1424 | var it = ZigClangEnumDecl_enumerator_begin(enum_def); | ||
| 1425 | var end_it = ZigClangEnumDecl_enumerator_end(enum_def); | ||
| 1426 | while (ZigClangEnumDecl_enumerator_iterator_neq(it, end_it)) : (it = ZigClangEnumDecl_enumerator_iterator_next(it)) { | ||
| 1427 | const enum_const = ZigClangEnumDecl_enumerator_iterator_deref(it); | ||
| 1428 | if (ZigClangEnumConstantDecl_getInitExpr(enum_const)) |_| { | ||
| 1429 | pure_enum = false; | ||
| 1430 | break; | ||
| 1431 | } | ||
| 1432 | } | ||
| 1433 | |||
| 1434 | const extern_tok = try appendToken(c, .Keyword_extern, "extern"); | ||
| 1435 | const container_tok = try appendToken(c, .Keyword_enum, "enum"); | ||
| 1436 | |||
| 1437 | const container_node = try c.a().create(ast.Node.ContainerDecl); | ||
| 1438 | container_node.* = .{ | ||
| 1439 | .layout_token = extern_tok, | ||
| 1440 | .kind_token = container_tok, | ||
| 1441 | .init_arg_expr = .None, | ||
| 1442 | .fields_and_decls = ast.Node.ContainerDecl.DeclList.init(c.a()), | ||
| 1443 | .lbrace_token = undefined, | ||
| 1444 | .rbrace_token = undefined, | ||
| 1445 | }; | ||
| 1446 | |||
| 1447 | const int_type = ZigClangEnumDecl_getIntegerType(enum_decl); | ||
| 1448 | |||
| 1449 | // TODO only emit this tag type if the enum tag type is not the default. | ||
| 1450 | // I don't know what the default is, need to figure out how clang is deciding. | ||
| 1451 | // it appears to at least be different across gcc/msvc | ||
| 1452 | if (!isCBuiltinType(int_type, .UInt) and | ||
| 1453 | !isCBuiltinType(int_type, .Int)) | ||
| 1454 | { | ||
| 1455 | _ = try appendToken(c, .LParen, "("); | ||
| 1456 | container_node.init_arg_expr = .{ | ||
| 1457 | .Type = transQualType(rp, int_type, enum_loc) catch |err| switch (err) { | ||
| 1458 | error.UnsupportedType => { | ||
| 1459 | if (is_unnamed) { | ||
| 1460 | try emitWarning(c, enum_loc, "unable to translate enum tag type", .{}); | ||
| 1461 | } else { | ||
| 1462 | try failDecl(c, enum_loc, name, "unable to translate enum tag type", .{}); | ||
| 1463 | } | ||
| 1464 | return null; | ||
| 1465 | }, | ||
| 1466 | else => |e| return e, | ||
| 1467 | }, | ||
| 1468 | }; | ||
| 1469 | _ = try appendToken(c, .RParen, ")"); | ||
| 1470 | } | ||
| 1471 | |||
| 1472 | container_node.lbrace_token = try appendToken(c, .LBrace, "{"); | ||
| 1473 | |||
| 1474 | it = ZigClangEnumDecl_enumerator_begin(enum_def); | ||
| 1475 | end_it = ZigClangEnumDecl_enumerator_end(enum_def); | ||
| 1476 | while (ZigClangEnumDecl_enumerator_iterator_neq(it, end_it)) : (it = ZigClangEnumDecl_enumerator_iterator_next(it)) { | ||
| 1477 | const enum_const = ZigClangEnumDecl_enumerator_iterator_deref(it); | ||
| 1478 | |||
| 1479 | const enum_val_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, enum_const))); | ||
| 1480 | |||
| 1481 | const field_name = if (!is_unnamed and std.mem.startsWith(u8, enum_val_name, bare_name)) | ||
| 1482 | enum_val_name[bare_name.len..] | ||
| 1483 | else | ||
| 1484 | enum_val_name; | ||
| 1485 | |||
| 1486 | const field_name_tok = try appendIdentifier(c, field_name); | ||
| 1487 | |||
| 1488 | const int_node = if (!pure_enum) blk: { | ||
| 1489 | _ = try appendToken(c, .Colon, "="); | ||
| 1490 | break :blk try transCreateNodeAPInt(c, ZigClangEnumConstantDecl_getInitVal(enum_const)); | ||
| 1491 | } else | ||
| 1492 | null; | ||
| 1493 | |||
| 1494 | const field_node = try c.a().create(ast.Node.ContainerField); | ||
| 1495 | field_node.* = .{ | ||
| 1496 | .doc_comments = null, | ||
| 1497 | .comptime_token = null, | ||
| 1498 | .name_token = field_name_tok, | ||
| 1499 | .type_expr = null, | ||
| 1500 | .value_expr = int_node, | ||
| 1501 | .align_expr = null, | ||
| 1502 | }; | ||
| 1503 | |||
| 1504 | try container_node.fields_and_decls.push(&field_node.base); | ||
| 1505 | _ = try appendToken(c, .Comma, ","); | ||
| 1506 | // In C each enum value is in the global namespace. So we put them there too. | ||
| 1507 | // At this point we can rely on the enum emitting successfully. | ||
| 1508 | try addEnumTopLevel(c, name, field_name, enum_val_name); | ||
| 1509 | } | ||
| 1510 | container_node.rbrace_token = try appendToken(c, .RBrace, "}"); | ||
| 1511 | |||
| 1512 | break :blk &container_node.base; | ||
| 1513 | } else | ||
| 1514 | try transCreateNodeOpaqueType(c); | ||
| 1515 | |||
| 1516 | const semicolon_token = try appendToken(c, .Semicolon, ";"); | ||
| 1517 | |||
| 1518 | const node = try c.a().create(ast.Node.VarDecl); | ||
| 1519 | node.* = ast.Node.VarDecl{ | ||
| 1520 | .visib_token = visib_tok, | ||
| 1521 | .mut_token = const_tok, | ||
| 1522 | .name_token = name_tok, | ||
| 1523 | .eq_token = eq_tok, | ||
| 1524 | .init_node = init_node, | ||
| 1525 | .semicolon_token = semicolon_token, | ||
| 1526 | .doc_comments = null, | ||
| 1527 | .comptime_token = null, | ||
| 1528 | .extern_export_token = null, | ||
| 1529 | .thread_local_token = null, | ||
| 1530 | .lib_name = null, | ||
| 1531 | .type_node = null, | ||
| 1532 | .align_node = null, | ||
| 1533 | .section_node = null, | ||
| 1534 | }; | ||
| 1535 | |||
| 1536 | try addTopLevelDecl(c, name, &node.base); | ||
| 1537 | if (!is_unnamed) | ||
| 1538 | try c.alias_list.push(.{ .alias = bare_name, .name = name }); | ||
| 1539 | return transCreateNodeIdentifier(c, name); | ||
| 1540 | } | ||
| 1541 | |||
| 1542 | fn addEnumTopLevel(c: *Context, enum_name: []const u8, field_name: []const u8, enum_val_name: []const u8) !void { | ||
| 1543 | const visib_tok = try appendToken(c, .Keyword_pub, "pub"); | ||
| 1544 | const const_tok = try appendToken(c, .Keyword_const, "const"); | ||
| 1545 | const name_tok = try appendIdentifier(c, enum_val_name); | ||
| 1546 | const eq_tok = try appendToken(c, .Equal, "="); | ||
| 1547 | |||
| 1548 | const enum_ident = try transCreateNodeIdentifier(c, enum_name); | ||
| 1549 | const period_tok = try appendToken(c, .Period, "."); | ||
| 1550 | const field_ident = try transCreateNodeIdentifier(c, field_name); | ||
| 1551 | |||
| 1552 | const field_access_node = try c.a().create(ast.Node.InfixOp); | ||
| 1553 | field_access_node.* = .{ | ||
| 1554 | .op_token = period_tok, | ||
| 1555 | .lhs = enum_ident, | ||
| 1556 | .op = .Period, | ||
| 1557 | .rhs = field_ident, | ||
| 1558 | }; | ||
| 1559 | const semicolon_token = try appendToken(c, .Semicolon, ";"); | ||
| 1560 | |||
| 1561 | const node = try c.a().create(ast.Node.VarDecl); | ||
| 1562 | node.* = ast.Node.VarDecl{ | ||
| 1563 | .visib_token = visib_tok, | ||
| 1564 | .mut_token = const_tok, | ||
| 1565 | .name_token = name_tok, | ||
| 1566 | .eq_token = eq_tok, | ||
| 1567 | .init_node = &field_access_node.base, | ||
| 1568 | .semicolon_token = semicolon_token, | ||
| 1569 | .thread_local_token = null, | ||
| 1570 | .doc_comments = null, | ||
| 1571 | .comptime_token = null, | ||
| 1572 | .extern_export_token = null, | ||
| 1573 | .lib_name = null, | ||
| 1574 | .type_node = null, | ||
| 1575 | .align_node = null, | ||
| 1576 | .section_node = null, | ||
| 1577 | }; | ||
| 1578 | |||
| 1579 | try addTopLevelDecl(c, field_name, &node.base); | ||
| 1580 | } | ||
| 1581 | |||
| 1582 | fn isCBuiltinType(qt: ZigClangQualType, kind: ZigClangBuiltinTypeKind) bool { | ||
| 1583 | const c_type = qualTypeCanon(qt); | ||
| 1584 | if (ZigClangType_getTypeClass(c_type) != .Builtin) | ||
| 1585 | return false; | ||
| 1586 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, c_type); | ||
| 1587 | return ZigClangBuiltinType_getKind(builtin_ty) == kind; | ||
| 1588 | } | ||
| 1589 | |||
| 1399 | fn qualTypeIsPtr(qt: ZigClangQualType) bool { | 1590 | fn qualTypeIsPtr(qt: ZigClangQualType) bool { |
| 1400 | return ZigClangType_getTypeClass(qualTypeCanon(qt)) == .Pointer; | 1591 | return ZigClangType_getTypeClass(qualTypeCanon(qt)) == .Pointer; |
| 1401 | } | 1592 | } |
| ... | @@ -1523,7 +1714,6 @@ fn transCreateNodeAssign( | ... | @@ -1523,7 +1714,6 @@ fn transCreateNodeAssign( |
| 1523 | 1714 | ||
| 1524 | const node = try rp.c.a().create(ast.Node.InfixOp); | 1715 | const node = try rp.c.a().create(ast.Node.InfixOp); |
| 1525 | node.* = ast.Node.InfixOp{ | 1716 | node.* = ast.Node.InfixOp{ |
| 1526 | .base = ast.Node{ .id = .InfixOp }, | ||
| 1527 | .op_token = eq_token, | 1717 | .op_token = eq_token, |
| 1528 | .lhs = lhs_node.node, | 1718 | .lhs = lhs_node.node, |
| 1529 | .op = .Assign, | 1719 | .op = .Assign, |
| ... | @@ -1553,7 +1743,6 @@ fn transCreateNodeBuiltinFnCall(c: *Context, name: []const u8) !*ast.Node.Builti | ... | @@ -1553,7 +1743,6 @@ fn transCreateNodeBuiltinFnCall(c: *Context, name: []const u8) !*ast.Node.Builti |
| 1553 | _ = try appendToken(c, .LParen, "("); | 1743 | _ = try appendToken(c, .LParen, "("); |
| 1554 | const node = try c.a().create(ast.Node.BuiltinCall); | 1744 | const node = try c.a().create(ast.Node.BuiltinCall); |
| 1555 | node.* = ast.Node.BuiltinCall{ | 1745 | node.* = ast.Node.BuiltinCall{ |
| 1556 | .base = ast.Node{ .id = .BuiltinCall }, | ||
| 1557 | .builtin_token = builtin_token, | 1746 | .builtin_token = builtin_token, |
| 1558 | .params = ast.Node.BuiltinCall.ParamList.init(c.a()), | 1747 | .params = ast.Node.BuiltinCall.ParamList.init(c.a()), |
| 1559 | .rparen_token = undefined, // set after appending args | 1748 | .rparen_token = undefined, // set after appending args |
| ... | @@ -1565,7 +1754,6 @@ fn transCreateNodeFnCall(c: *Context, fn_expr: *ast.Node) !*ast.Node.SuffixOp { | ... | @@ -1565,7 +1754,6 @@ fn transCreateNodeFnCall(c: *Context, fn_expr: *ast.Node) !*ast.Node.SuffixOp { |
| 1565 | _ = try appendToken(c, .LParen, "("); | 1754 | _ = try appendToken(c, .LParen, "("); |
| 1566 | const node = try c.a().create(ast.Node.SuffixOp); | 1755 | const node = try c.a().create(ast.Node.SuffixOp); |
| 1567 | node.* = ast.Node.SuffixOp{ | 1756 | node.* = ast.Node.SuffixOp{ |
| 1568 | .base = ast.Node{ .id = .SuffixOp }, | ||
| 1569 | .lhs = fn_expr, | 1757 | .lhs = fn_expr, |
| 1570 | .op = ast.Node.SuffixOp.Op{ | 1758 | .op = ast.Node.SuffixOp.Op{ |
| 1571 | .Call = ast.Node.SuffixOp.Op.Call{ | 1759 | .Call = ast.Node.SuffixOp.Op.Call{ |
| ... | @@ -1586,7 +1774,6 @@ fn transCreateNodePrefixOp( | ... | @@ -1586,7 +1774,6 @@ fn transCreateNodePrefixOp( |
| 1586 | ) !*ast.Node.PrefixOp { | 1774 | ) !*ast.Node.PrefixOp { |
| 1587 | const node = try c.a().create(ast.Node.PrefixOp); | 1775 | const node = try c.a().create(ast.Node.PrefixOp); |
| 1588 | node.* = ast.Node.PrefixOp{ | 1776 | node.* = ast.Node.PrefixOp{ |
| 1589 | .base = ast.Node{ .id = .PrefixOp }, | ||
| 1590 | .op_token = try appendToken(c, op_tok_id, bytes), | 1777 | .op_token = try appendToken(c, op_tok_id, bytes), |
| 1591 | .op = op, | 1778 | .op = op, |
| 1592 | .rhs = undefined, // translate and set afterward | 1779 | .rhs = undefined, // translate and set afterward |
| ... | @@ -1609,7 +1796,6 @@ fn transCreateNodeInfixOp( | ... | @@ -1609,7 +1796,6 @@ fn transCreateNodeInfixOp( |
| 1609 | const rhs = try transExpr(rp, scope, ZigClangBinaryOperator_getRHS(stmt), .used, .r_value); | 1796 | const rhs = try transExpr(rp, scope, ZigClangBinaryOperator_getRHS(stmt), .used, .r_value); |
| 1610 | const node = try rp.c.a().create(ast.Node.InfixOp); | 1797 | const node = try rp.c.a().create(ast.Node.InfixOp); |
| 1611 | node.* = ast.Node.InfixOp{ | 1798 | node.* = ast.Node.InfixOp{ |
| 1612 | .base = ast.Node{ .id = .InfixOp }, | ||
| 1613 | .op_token = op_token, | 1799 | .op_token = op_token, |
| 1614 | .lhs = lhs.node, | 1800 | .lhs = lhs.node, |
| 1615 | .op = op, | 1801 | .op = op, |
| ... | @@ -1619,7 +1805,6 @@ fn transCreateNodeInfixOp( | ... | @@ -1619,7 +1805,6 @@ fn transCreateNodeInfixOp( |
| 1619 | const rparen = try appendToken(rp.c, .RParen, ")"); | 1805 | const rparen = try appendToken(rp.c, .RParen, ")"); |
| 1620 | const grouped_expr = try rp.c.a().create(ast.Node.GroupedExpression); | 1806 | const grouped_expr = try rp.c.a().create(ast.Node.GroupedExpression); |
| 1621 | grouped_expr.* = ast.Node.GroupedExpression{ | 1807 | grouped_expr.* = ast.Node.GroupedExpression{ |
| 1622 | .base = ast.Node{ .id = .GroupedExpression }, | ||
| 1623 | .lparen = lparen, | 1808 | .lparen = lparen, |
| 1624 | .expr = &node.base, | 1809 | .expr = &node.base, |
| 1625 | .rparen = rparen, | 1810 | .rparen = rparen, |
| ... | @@ -1644,7 +1829,7 @@ fn transCreateNodePtrType( | ... | @@ -1644,7 +1829,7 @@ fn transCreateNodePtrType( |
| 1644 | .Identifier => blk: { | 1829 | .Identifier => blk: { |
| 1645 | const lbracket = try appendToken(c, .LBracket, "["); // Rendering checks if this token + 2 == .Identifier, so needs to return this token | 1830 | const lbracket = try appendToken(c, .LBracket, "["); // Rendering checks if this token + 2 == .Identifier, so needs to return this token |
| 1646 | _ = try appendToken(c, .Asterisk, "*"); | 1831 | _ = try appendToken(c, .Asterisk, "*"); |
| 1647 | _ = try appendToken(c, .Identifier, "c"); | 1832 | _ = try appendIdentifier(c, "c"); |
| 1648 | _ = try appendToken(c, .RBracket, "]"); | 1833 | _ = try appendToken(c, .RBracket, "]"); |
| 1649 | break :blk lbracket; | 1834 | break :blk lbracket; |
| 1650 | }, | 1835 | }, |
| ... | @@ -1652,7 +1837,6 @@ fn transCreateNodePtrType( | ... | @@ -1652,7 +1837,6 @@ fn transCreateNodePtrType( |
| 1652 | else => unreachable, | 1837 | else => unreachable, |
| 1653 | }; | 1838 | }; |
| 1654 | node.* = ast.Node.PrefixOp{ | 1839 | node.* = ast.Node.PrefixOp{ |
| 1655 | .base = ast.Node{ .id = .PrefixOp }, | ||
| 1656 | .op_token = op_token, | 1840 | .op_token = op_token, |
| 1657 | .op = ast.Node.PrefixOp.Op{ | 1841 | .op = ast.Node.PrefixOp.Op{ |
| 1658 | .PtrType = .{ | 1842 | .PtrType = .{ |
| ... | @@ -1679,7 +1863,6 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node { | ... | @@ -1679,7 +1863,6 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node { |
| 1679 | const token = try appendToken(c, .IntegerLiteral, str); | 1863 | const token = try appendToken(c, .IntegerLiteral, str); |
| 1680 | const node = try c.a().create(ast.Node.IntegerLiteral); | 1864 | const node = try c.a().create(ast.Node.IntegerLiteral); |
| 1681 | node.* = ast.Node.IntegerLiteral{ | 1865 | node.* = ast.Node.IntegerLiteral{ |
| 1682 | .base = ast.Node{ .id = .IntegerLiteral }, | ||
| 1683 | .token = token, | 1866 | .token = token, |
| 1684 | }; | 1867 | }; |
| 1685 | return &node.base; | 1868 | return &node.base; |
| ... | @@ -1689,7 +1872,6 @@ fn transCreateNodeReturnExpr(c: *Context) !*ast.Node { | ... | @@ -1689,7 +1872,6 @@ fn transCreateNodeReturnExpr(c: *Context) !*ast.Node { |
| 1689 | const ltoken = try appendToken(c, .Keyword_return, "return"); | 1872 | const ltoken = try appendToken(c, .Keyword_return, "return"); |
| 1690 | const node = try c.a().create(ast.Node.ControlFlowExpression); | 1873 | const node = try c.a().create(ast.Node.ControlFlowExpression); |
| 1691 | node.* = ast.Node.ControlFlowExpression{ | 1874 | node.* = ast.Node.ControlFlowExpression{ |
| 1692 | .base = ast.Node{ .id = .ControlFlowExpression }, | ||
| 1693 | .ltoken = ltoken, | 1875 | .ltoken = ltoken, |
| 1694 | .kind = .Return, | 1876 | .kind = .Return, |
| 1695 | .rhs = null, | 1877 | .rhs = null, |
| ... | @@ -1701,7 +1883,6 @@ fn transCreateNodeUndefinedLiteral(c: *Context) !*ast.Node { | ... | @@ -1701,7 +1883,6 @@ fn transCreateNodeUndefinedLiteral(c: *Context) !*ast.Node { |
| 1701 | const token = try appendToken(c, .Keyword_undefined, "undefined"); | 1883 | const token = try appendToken(c, .Keyword_undefined, "undefined"); |
| 1702 | const node = try c.a().create(ast.Node.UndefinedLiteral); | 1884 | const node = try c.a().create(ast.Node.UndefinedLiteral); |
| 1703 | node.* = ast.Node.UndefinedLiteral{ | 1885 | node.* = ast.Node.UndefinedLiteral{ |
| 1704 | .base = ast.Node{ .id = .UndefinedLiteral }, | ||
| 1705 | .token = token, | 1886 | .token = token, |
| 1706 | }; | 1887 | }; |
| 1707 | return &node.base; | 1888 | return &node.base; |
| ... | @@ -1711,7 +1892,6 @@ fn transCreateNodeNullLiteral(c: *Context) !*ast.Node { | ... | @@ -1711,7 +1892,6 @@ fn transCreateNodeNullLiteral(c: *Context) !*ast.Node { |
| 1711 | const token = try appendToken(c, .Keyword_null, "null"); | 1892 | const token = try appendToken(c, .Keyword_null, "null"); |
| 1712 | const node = try c.a().create(ast.Node.NullLiteral); | 1893 | const node = try c.a().create(ast.Node.NullLiteral); |
| 1713 | node.* = ast.Node.NullLiteral{ | 1894 | node.* = ast.Node.NullLiteral{ |
| 1714 | .base = ast.Node{ .id = .NullLiteral }, | ||
| 1715 | .token = token, | 1895 | .token = token, |
| 1716 | }; | 1896 | }; |
| 1717 | return &node.base; | 1897 | return &node.base; |
| ... | @@ -1724,7 +1904,6 @@ fn transCreateNodeBoolLiteral(c: *Context, value: bool) !*ast.Node { | ... | @@ -1724,7 +1904,6 @@ fn transCreateNodeBoolLiteral(c: *Context, value: bool) !*ast.Node { |
| 1724 | try appendToken(c, .Keyword_false, "false"); | 1904 | try appendToken(c, .Keyword_false, "false"); |
| 1725 | const node = try c.a().create(ast.Node.BoolLiteral); | 1905 | const node = try c.a().create(ast.Node.BoolLiteral); |
| 1726 | node.* = ast.Node.BoolLiteral{ | 1906 | node.* = ast.Node.BoolLiteral{ |
| 1727 | .base = ast.Node{ .id = .BoolLiteral }, | ||
| 1728 | .token = token, | 1907 | .token = token, |
| 1729 | }; | 1908 | }; |
| 1730 | return &node.base; | 1909 | return &node.base; |
| ... | @@ -1734,7 +1913,6 @@ fn transCreateNodeArrayInitializer(c: *Context, dot_tok: ast.TokenIndex) !*ast.N | ... | @@ -1734,7 +1913,6 @@ fn transCreateNodeArrayInitializer(c: *Context, dot_tok: ast.TokenIndex) !*ast.N |
| 1734 | _ = try appendToken(c, .LBrace, "{"); | 1913 | _ = try appendToken(c, .LBrace, "{"); |
| 1735 | const node = try c.a().create(ast.Node.SuffixOp); | 1914 | const node = try c.a().create(ast.Node.SuffixOp); |
| 1736 | node.* = ast.Node.SuffixOp{ | 1915 | node.* = ast.Node.SuffixOp{ |
| 1737 | .base = ast.Node{ .id = .SuffixOp }, | ||
| 1738 | .lhs = .{ .dot = dot_tok }, | 1916 | .lhs = .{ .dot = dot_tok }, |
| 1739 | .op = .{ | 1917 | .op = .{ |
| 1740 | .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(c.a()), | 1918 | .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(c.a()), |
| ... | @@ -1748,7 +1926,6 @@ fn transCreateNodeInt(c: *Context, int: var) !*ast.Node { | ... | @@ -1748,7 +1926,6 @@ fn transCreateNodeInt(c: *Context, int: var) !*ast.Node { |
| 1748 | const token = try appendTokenFmt(c, .IntegerLiteral, "{}", .{int}); | 1926 | const token = try appendTokenFmt(c, .IntegerLiteral, "{}", .{int}); |
| 1749 | const node = try c.a().create(ast.Node.IntegerLiteral); | 1927 | const node = try c.a().create(ast.Node.IntegerLiteral); |
| 1750 | node.* = ast.Node.IntegerLiteral{ | 1928 | node.* = ast.Node.IntegerLiteral{ |
| 1751 | .base = ast.Node{ .id = .IntegerLiteral }, | ||
| 1752 | .token = token, | 1929 | .token = token, |
| 1753 | }; | 1930 | }; |
| 1754 | return &node.base; | 1931 | return &node.base; |
| ... | @@ -1793,25 +1970,25 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour | ... | @@ -1793,25 +1970,25 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour |
| 1793 | .Builtin => { | 1970 | .Builtin => { |
| 1794 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); | 1971 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); |
| 1795 | switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 1972 | switch (ZigClangBuiltinType_getKind(builtin_ty)) { |
| 1796 | .Void => return appendIdentifier(rp.c, "c_void"), | 1973 | .Void => return transCreateNodeIdentifier(rp.c, "c_void"), |
| 1797 | .Bool => return appendIdentifier(rp.c, "bool"), | 1974 | .Bool => return transCreateNodeIdentifier(rp.c, "bool"), |
| 1798 | .Char_U, .UChar, .Char_S, .Char8 => return appendIdentifier(rp.c, "u8"), | 1975 | .Char_U, .UChar, .Char_S, .Char8 => return transCreateNodeIdentifier(rp.c, "u8"), |
| 1799 | .SChar => return appendIdentifier(rp.c, "i8"), | 1976 | .SChar => return transCreateNodeIdentifier(rp.c, "i8"), |
| 1800 | .UShort => return appendIdentifier(rp.c, "c_ushort"), | 1977 | .UShort => return transCreateNodeIdentifier(rp.c, "c_ushort"), |
| 1801 | .UInt => return appendIdentifier(rp.c, "c_uint"), | 1978 | .UInt => return transCreateNodeIdentifier(rp.c, "c_uint"), |
| 1802 | .ULong => return appendIdentifier(rp.c, "c_ulong"), | 1979 | .ULong => return transCreateNodeIdentifier(rp.c, "c_ulong"), |
| 1803 | .ULongLong => return appendIdentifier(rp.c, "c_ulonglong"), | 1980 | .ULongLong => return transCreateNodeIdentifier(rp.c, "c_ulonglong"), |
| 1804 | .Short => return appendIdentifier(rp.c, "c_short"), | 1981 | .Short => return transCreateNodeIdentifier(rp.c, "c_short"), |
| 1805 | .Int => return appendIdentifier(rp.c, "c_int"), | 1982 | .Int => return transCreateNodeIdentifier(rp.c, "c_int"), |
| 1806 | .Long => return appendIdentifier(rp.c, "c_long"), | 1983 | .Long => return transCreateNodeIdentifier(rp.c, "c_long"), |
| 1807 | .LongLong => return appendIdentifier(rp.c, "c_longlong"), | 1984 | .LongLong => return transCreateNodeIdentifier(rp.c, "c_longlong"), |
| 1808 | .UInt128 => return appendIdentifier(rp.c, "u128"), | 1985 | .UInt128 => return transCreateNodeIdentifier(rp.c, "u128"), |
| 1809 | .Int128 => return appendIdentifier(rp.c, "i128"), | 1986 | .Int128 => return transCreateNodeIdentifier(rp.c, "i128"), |
| 1810 | .Float => return appendIdentifier(rp.c, "f32"), | 1987 | .Float => return transCreateNodeIdentifier(rp.c, "f32"), |
| 1811 | .Double => return appendIdentifier(rp.c, "f64"), | 1988 | .Double => return transCreateNodeIdentifier(rp.c, "f64"), |
| 1812 | .Float128 => return appendIdentifier(rp.c, "f128"), | 1989 | .Float128 => return transCreateNodeIdentifier(rp.c, "f128"), |
| 1813 | .Float16 => return appendIdentifier(rp.c, "f16"), | 1990 | .Float16 => return transCreateNodeIdentifier(rp.c, "f16"), |
| 1814 | .LongDouble => return appendIdentifier(rp.c, "c_longdouble"), | 1991 | .LongDouble => return transCreateNodeIdentifier(rp.c, "c_longdouble"), |
| 1815 | else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type", .{}), | 1992 | else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type", .{}), |
| 1816 | } | 1993 | } |
| 1817 | }, | 1994 | }, |
| ... | @@ -1891,21 +2068,36 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour | ... | @@ -1891,21 +2068,36 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour |
| 1891 | 2068 | ||
| 1892 | const typedef_decl = ZigClangTypedefType_getDecl(typedef_ty); | 2069 | const typedef_decl = ZigClangTypedefType_getDecl(typedef_ty); |
| 1893 | const typedef_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, typedef_decl))); | 2070 | const typedef_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, typedef_decl))); |
| 1894 | return appendIdentifier(rp.c, typedef_name); | 2071 | return transCreateNodeIdentifier(rp.c, typedef_name); |
| 1895 | }, | 2072 | }, |
| 1896 | .Record => { | 2073 | .Record => { |
| 1897 | const record_ty = @ptrCast(*const ZigClangRecordType, ty); | 2074 | const record_ty = @ptrCast(*const ZigClangRecordType, ty); |
| 1898 | 2075 | ||
| 1899 | const record_decl = ZigClangRecordType_getDecl(record_ty); | 2076 | const record_decl = ZigClangRecordType_getDecl(record_ty); |
| 1900 | if (try getContainerName(rp.c, record_decl)) |name| | 2077 | if (try getContainerName(rp, record_decl)) |name| |
| 1901 | return appendIdentifier(rp.c, name) | 2078 | return transCreateNodeIdentifier(rp.c, name) |
| 1902 | else | 2079 | else |
| 1903 | return transRecordDecl(rp.c, record_decl); | 2080 | return transRecordDecl(rp.c, record_decl); |
| 1904 | }, | 2081 | }, |
| 2082 | .Enum => { | ||
| 2083 | const enum_ty = @ptrCast(*const ZigClangEnumType, ty); | ||
| 2084 | |||
| 2085 | const enum_decl = ZigClangEnumType_getDecl(enum_ty); | ||
| 2086 | return (try transEnumDecl(rp.c, enum_decl)) orelse | ||
| 2087 | revertAndWarn(rp, error.UnsupportedType, source_loc, "unable to translate enum declaration", .{}); | ||
| 2088 | }, | ||
| 1905 | .Elaborated => { | 2089 | .Elaborated => { |
| 1906 | const elaborated_ty = @ptrCast(*const ZigClangElaboratedType, ty); | 2090 | const elaborated_ty = @ptrCast(*const ZigClangElaboratedType, ty); |
| 1907 | return transQualType(rp, ZigClangElaboratedType_getNamedType(elaborated_ty), source_loc); | 2091 | return transQualType(rp, ZigClangElaboratedType_getNamedType(elaborated_ty), source_loc); |
| 1908 | }, | 2092 | }, |
| 2093 | .Decayed => { | ||
| 2094 | const decayed_ty = @ptrCast(*const ZigClangDecayedType, ty); | ||
| 2095 | return transQualType(rp, ZigClangDecayedType_getDecayedType(decayed_ty), source_loc); | ||
| 2096 | }, | ||
| 2097 | .Attributed => { | ||
| 2098 | const attributed_ty = @ptrCast(*const ZigClangAttributedType, ty); | ||
| 2099 | return transQualType(rp, ZigClangAttributedType_getEquivalentType(attributed_ty), source_loc); | ||
| 2100 | }, | ||
| 1909 | else => { | 2101 | else => { |
| 1910 | const type_name = rp.c.str(ZigClangType_getTypeClassName(ty)); | 2102 | const type_name = rp.c.str(ZigClangType_getTypeClassName(ty)); |
| 1911 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name}); | 2103 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name}); |
| ... | @@ -1913,22 +2105,20 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour | ... | @@ -1913,22 +2105,20 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour |
| 1913 | } | 2105 | } |
| 1914 | } | 2106 | } |
| 1915 | 2107 | ||
| 1916 | fn getContainerName(c: *Context, record_decl: *const ZigClangRecordDecl) !?[]const u8 { | 2108 | fn getContainerName(rp: RestorePoint, record_decl: *const ZigClangRecordDecl) !?[]const u8 { |
| 1917 | const bare_name = try c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, record_decl))); | 2109 | const bare_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, record_decl))); |
| 1918 | 2110 | ||
| 1919 | const container_kind_name = if (ZigClangRecordDecl_isUnion(record_decl)) | 2111 | const container_kind_name = if (ZigClangRecordDecl_isUnion(record_decl)) |
| 1920 | "union" | 2112 | "union" |
| 1921 | else if (ZigClangRecordDecl_isStruct(record_decl)) | 2113 | else if (ZigClangRecordDecl_isStruct(record_decl)) |
| 1922 | "struct" | 2114 | "struct" |
| 1923 | else { | 2115 | else |
| 1924 | try emitWarning(c, ZigClangRecordDecl_getLocation(record_decl), "record {} is not a struct or union", .{bare_name}); | 2116 | return revertAndWarn(rp, error.UnsupportedType, ZigClangRecordDecl_getLocation(record_decl), "record {} is not a struct or union", .{bare_name}); |
| 1925 | return null; | ||
| 1926 | }; | ||
| 1927 | 2117 | ||
| 1928 | if (ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl) or bare_name.len == 0) | 2118 | if (ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl) or bare_name.len == 0) |
| 1929 | return null; | 2119 | return null; |
| 1930 | 2120 | ||
| 1931 | return try std.fmt.allocPrint(c.a(), "{}_{}", .{ container_kind_name, bare_name }); | 2121 | return try std.fmt.allocPrint(rp.c.a(), "{}_{}", .{ container_kind_name, bare_name }); |
| 1932 | } | 2122 | } |
| 1933 | 2123 | ||
| 1934 | fn isCVoid(qt: ZigClangQualType) bool { | 2124 | fn isCVoid(qt: ZigClangQualType) bool { |
| ... | @@ -2020,7 +2210,7 @@ fn finishTransFnProto( | ... | @@ -2020,7 +2210,7 @@ fn finishTransFnProto( |
| 2020 | else | 2210 | else |
| 2021 | null; | 2211 | null; |
| 2022 | const fn_tok = try appendToken(rp.c, .Keyword_fn, "fn"); | 2212 | const fn_tok = try appendToken(rp.c, .Keyword_fn, "fn"); |
| 2023 | const name_tok = if (fn_decl_context) |ctx| try appendToken(rp.c, .Identifier, ctx.fn_name) else null; | 2213 | const name_tok = if (fn_decl_context) |ctx| try appendIdentifier(rp.c, ctx.fn_name) else null; |
| 2024 | const lparen_tok = try appendToken(rp.c, .LParen, "("); | 2214 | const lparen_tok = try appendToken(rp.c, .LParen, "("); |
| 2025 | 2215 | ||
| 2026 | var fn_params = ast.Node.FnProto.ParamList.init(rp.c.a()); | 2216 | var fn_params = ast.Node.FnProto.ParamList.init(rp.c.a()); |
| ... | @@ -2038,7 +2228,7 @@ fn finishTransFnProto( | ... | @@ -2038,7 +2228,7 @@ fn finishTransFnProto( |
| 2038 | const param_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, param))); | 2228 | const param_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, param))); |
| 2039 | if (param_name.len > 0) { | 2229 | if (param_name.len > 0) { |
| 2040 | // TODO: If len == 0, auto-generate arg1, arg2, etc? Or leave the name blank? | 2230 | // TODO: If len == 0, auto-generate arg1, arg2, etc? Or leave the name blank? |
| 2041 | const result = try appendToken(rp.c, .Identifier, param_name); | 2231 | const result = try appendIdentifier(rp.c, param_name); |
| 2042 | _ = try appendToken(rp.c, .Colon, ":"); | 2232 | _ = try appendToken(rp.c, .Colon, ":"); |
| 2043 | break :blk result; | 2233 | break :blk result; |
| 2044 | } | 2234 | } |
| ... | @@ -2087,12 +2277,12 @@ fn finishTransFnProto( | ... | @@ -2087,12 +2277,12 @@ fn finishTransFnProto( |
| 2087 | 2277 | ||
| 2088 | const return_type_node = blk: { | 2278 | const return_type_node = blk: { |
| 2089 | if (ZigClangFunctionType_getNoReturnAttr(fn_ty)) { | 2279 | if (ZigClangFunctionType_getNoReturnAttr(fn_ty)) { |
| 2090 | break :blk try appendIdentifier(rp.c, "noreturn"); | 2280 | break :blk try transCreateNodeIdentifier(rp.c, "noreturn"); |
| 2091 | } else { | 2281 | } else { |
| 2092 | const return_qt = ZigClangFunctionType_getReturnType(fn_ty); | 2282 | const return_qt = ZigClangFunctionType_getReturnType(fn_ty); |
| 2093 | if (isCVoid(return_qt)) { | 2283 | if (isCVoid(return_qt)) { |
| 2094 | // convert primitive c_void to actual void (only for return type) | 2284 | // convert primitive c_void to actual void (only for return type) |
| 2095 | break :blk try appendIdentifier(rp.c, "void"); | 2285 | break :blk try transCreateNodeIdentifier(rp.c, "void"); |
| 2096 | } else { | 2286 | } else { |
| 2097 | break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) { | 2287 | break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) { |
| 2098 | error.UnsupportedType => { | 2288 | error.UnsupportedType => { |
| ... | @@ -2145,7 +2335,7 @@ fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []cons | ... | @@ -2145,7 +2335,7 @@ fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []cons |
| 2145 | fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: var) !void { | 2335 | fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: var) !void { |
| 2146 | // const name = @compileError(msg); | 2336 | // const name = @compileError(msg); |
| 2147 | const const_tok = try appendToken(c, .Keyword_const, "const"); | 2337 | const const_tok = try appendToken(c, .Keyword_const, "const"); |
| 2148 | const name_tok = try appendToken(c, .Identifier, name); | 2338 | const name_tok = try appendIdentifier(c, name); |
| 2149 | const eq_tok = try appendToken(c, .Equal, "="); | 2339 | const eq_tok = try appendToken(c, .Equal, "="); |
| 2150 | const builtin_tok = try appendToken(c, .Builtin, "@compileError"); | 2340 | const builtin_tok = try appendToken(c, .Builtin, "@compileError"); |
| 2151 | const lparen_tok = try appendToken(c, .LParen, "("); | 2341 | const lparen_tok = try appendToken(c, .LParen, "("); |
| ... | @@ -2190,6 +2380,7 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime | ... | @@ -2190,6 +2380,7 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime |
| 2190 | } | 2380 | } |
| 2191 | 2381 | ||
| 2192 | fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex { | 2382 | fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex { |
| 2383 | std.debug.assert(token_id != .Identifier); // use appendIdentifier | ||
| 2193 | return appendTokenFmt(c, token_id, "{}", .{bytes}); | 2384 | return appendTokenFmt(c, token_id, "{}", .{bytes}); |
| 2194 | } | 2385 | } |
| 2195 | 2386 | ||
| ... | @@ -2218,8 +2409,27 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, | ... | @@ -2218,8 +2409,27 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, |
| 2218 | return token_index; | 2409 | return token_index; |
| 2219 | } | 2410 | } |
| 2220 | 2411 | ||
| 2221 | fn appendIdentifier(c: *Context, name: []const u8) !*ast.Node { | 2412 | fn isValidZigIdentifier(name: []const u8) bool { |
| 2222 | const token_index = try appendToken(c, .Identifier, name); | 2413 | for (name) |c, i| { |
| 2414 | switch (c) { | ||
| 2415 | '_', 'a'...'z', 'A'...'Z' => {}, | ||
| 2416 | '0'...'9' => if (i == 0) return false, | ||
| 2417 | else => return false, | ||
| 2418 | } | ||
| 2419 | } | ||
| 2420 | return true; | ||
| 2421 | } | ||
| 2422 | |||
| 2423 | fn appendIdentifier(c: *Context, name: []const u8) !ast.TokenIndex { | ||
| 2424 | if (!isValidZigIdentifier(name) or std.zig.Token.getKeyword(name) != null) { | ||
| 2425 | return appendTokenFmt(c, .Identifier, "@\"{}\"", .{name}); | ||
| 2426 | } else { | ||
| 2427 | return appendTokenFmt(c, .Identifier, "{}", .{name}); | ||
| 2428 | } | ||
| 2429 | } | ||
| 2430 | |||
| 2431 | fn transCreateNodeIdentifier(c: *Context, name: []const u8) !*ast.Node { | ||
| 2432 | const token_index = try appendIdentifier(c, name); | ||
| 2223 | const identifier = try c.a().create(ast.Node.Identifier); | 2433 | const identifier = try c.a().create(ast.Node.Identifier); |
| 2224 | identifier.* = ast.Node.Identifier{ | 2434 | identifier.* = ast.Node.Identifier{ |
| 2225 | .base = ast.Node{ .id = ast.Node.Id.Identifier }, | 2435 | .base = ast.Node{ .id = ast.Node.Id.Identifier }, |
test/translate_c.zig+69-3| ... | @@ -217,6 +217,72 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -217,6 +217,72 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 217 | \\pub const OpenGLProcs = union_OpenGLProcs; | 217 | \\pub const OpenGLProcs = union_OpenGLProcs; |
| 218 | }); | 218 | }); |
| 219 | 219 | ||
| 220 | cases.add_2("enums", | ||
| 221 | \\typedef enum { | ||
| 222 | \\ a, | ||
| 223 | \\ b, | ||
| 224 | \\ c, | ||
| 225 | \\} d; | ||
| 226 | \\enum { | ||
| 227 | \\ e, | ||
| 228 | \\ f = 4, | ||
| 229 | \\ g, | ||
| 230 | \\} h = e; | ||
| 231 | \\struct Baz { | ||
| 232 | \\ enum { | ||
| 233 | \\ i, | ||
| 234 | \\ j, | ||
| 235 | \\ k, | ||
| 236 | \\ } l; | ||
| 237 | \\ d m; | ||
| 238 | \\}; | ||
| 239 | \\enum i { | ||
| 240 | \\ n, | ||
| 241 | \\ o, | ||
| 242 | \\ p, | ||
| 243 | \\}; | ||
| 244 | , &[_][]const u8{ | ||
| 245 | \\pub const a = enum_unnamed_1.a; | ||
| 246 | \\pub const b = enum_unnamed_1.b; | ||
| 247 | \\pub const c = enum_unnamed_1.c; | ||
| 248 | \\pub const enum_unnamed_1 = extern enum { | ||
| 249 | \\ a, | ||
| 250 | \\ b, | ||
| 251 | \\ c, | ||
| 252 | \\}; | ||
| 253 | \\pub const d = enum_unnamed_1; | ||
| 254 | \\pub const e = enum_unnamed_2.e; | ||
| 255 | \\pub const f = enum_unnamed_2.f; | ||
| 256 | \\pub const g = enum_unnamed_2.g; | ||
| 257 | \\pub const enum_unnamed_2 = extern enum { | ||
| 258 | \\ e = 0, | ||
| 259 | \\ f = 4, | ||
| 260 | \\ g = 5, | ||
| 261 | \\}; | ||
| 262 | \\pub export var h: enum_unnamed_2 = @as(enum_unnamed_2, e); | ||
| 263 | \\pub const i = enum_unnamed_3.i; | ||
| 264 | \\pub const j = enum_unnamed_3.j; | ||
| 265 | \\pub const k = enum_unnamed_3.k; | ||
| 266 | \\pub const enum_unnamed_3 = extern enum { | ||
| 267 | \\ i, | ||
| 268 | \\ j, | ||
| 269 | \\ k, | ||
| 270 | \\}; | ||
| 271 | \\pub const struct_Baz = extern struct { | ||
| 272 | \\ l: enum_unnamed_3, | ||
| 273 | \\ m: d, | ||
| 274 | \\}; | ||
| 275 | \\pub const n = enum_i.n; | ||
| 276 | \\pub const o = enum_i.o; | ||
| 277 | \\pub const p = enum_i.p; | ||
| 278 | \\pub const enum_i = extern enum { | ||
| 279 | \\ n, | ||
| 280 | \\ o, | ||
| 281 | \\ p, | ||
| 282 | \\}; | ||
| 283 | \\pub const Baz = struct_Baz; | ||
| 284 | }); | ||
| 285 | |||
| 220 | /////////////// Cases for only stage1 which are TODO items for stage2 //////////////// | 286 | /////////////// Cases for only stage1 which are TODO items for stage2 //////////////// |
| 221 | 287 | ||
| 222 | cases.add_both("typedef of function in struct field", | 288 | cases.add_both("typedef of function in struct field", |
| ... | @@ -440,7 +506,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -440,7 +506,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 440 | \\} | 506 | \\} |
| 441 | }); | 507 | }); |
| 442 | 508 | ||
| 443 | cases.add("enums", | 509 | cases.add_both("enums", |
| 444 | \\enum Foo { | 510 | \\enum Foo { |
| 445 | \\ FooA, | 511 | \\ FooA, |
| 446 | \\ FooB, | 512 | \\ FooB, |
| ... | @@ -462,7 +528,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -462,7 +528,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 462 | \\pub const Foo = enum_Foo; | 528 | \\pub const Foo = enum_Foo; |
| 463 | }); | 529 | }); |
| 464 | 530 | ||
| 465 | cases.add("enums", | 531 | cases.add_both("enums", |
| 466 | \\enum Foo { | 532 | \\enum Foo { |
| 467 | \\ FooA = 2, | 533 | \\ FooA = 2, |
| 468 | \\ FooB = 5, | 534 | \\ FooB = 5, |
| ... | @@ -686,7 +752,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -686,7 +752,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 686 | \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32); | 752 | \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32); |
| 687 | }); | 753 | }); |
| 688 | 754 | ||
| 689 | cases.add("zig keywords in C code", | 755 | cases.add_both("zig keywords in C code", |
| 690 | \\struct comptime { | 756 | \\struct comptime { |
| 691 | \\ int defer; | 757 | \\ int defer; |
| 692 | \\}; | 758 | \\}; |