| author | |
| committer | |
| log | 59cc7072e22d03ba40456a58eaf3b37b239b420e |
| tree | 5acdaf8eed445c9269791fab8420a7b93c102d57 |
| parent | 1a3633d78664701557ddf47651ea2d9d408859c5 |
| signature | Commit is signed but in an unrecognized format. |
3 files changed, 101 insertions(+), 109 deletions(-)
lib/std/zig/ast.zig+46-46| ... | ... | @@ -584,7 +584,7 @@ pub const Node = struct { |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | pub const Root = struct { |
| 587 | base: Node = Node {.id = .Root}, | |
| 587 | base: Node = Node{ .id = .Root }, | |
| 588 | 588 | decls: DeclList, |
| 589 | 589 | eof_token: TokenIndex, |
| 590 | 590 | |
| ... | ... | @@ -607,7 +607,7 @@ pub const Node = struct { |
| 607 | 607 | }; |
| 608 | 608 | |
| 609 | 609 | pub const VarDecl = struct { |
| 610 | base: Node = Node {.id = .VarDecl}, | |
| 610 | base: Node = Node{ .id = .VarDecl }, | |
| 611 | 611 | doc_comments: ?*DocComment, |
| 612 | 612 | visib_token: ?TokenIndex, |
| 613 | 613 | thread_local_token: ?TokenIndex, |
| ... | ... | @@ -664,7 +664,7 @@ pub const Node = struct { |
| 664 | 664 | }; |
| 665 | 665 | |
| 666 | 666 | pub const Use = struct { |
| 667 | base: Node = Node {.id = .Use}, | |
| 667 | base: Node = Node{ .id = .Use }, | |
| 668 | 668 | doc_comments: ?*DocComment, |
| 669 | 669 | visib_token: ?TokenIndex, |
| 670 | 670 | use_token: TokenIndex, |
| ... | ... | @@ -691,7 +691,7 @@ pub const Node = struct { |
| 691 | 691 | }; |
| 692 | 692 | |
| 693 | 693 | pub const ErrorSetDecl = struct { |
| 694 | base: Node = Node {.id = .ErrorSetDecl}, | |
| 694 | base: Node = Node{ .id = .ErrorSetDecl }, | |
| 695 | 695 | error_token: TokenIndex, |
| 696 | 696 | decls: DeclList, |
| 697 | 697 | rbrace_token: TokenIndex, |
| ... | ... | @@ -717,7 +717,7 @@ pub const Node = struct { |
| 717 | 717 | }; |
| 718 | 718 | |
| 719 | 719 | pub const ContainerDecl = struct { |
| 720 | base: Node = Node {.id = .ContainerDecl}, | |
| 720 | base: Node = Node{ .id = .ContainerDecl }, | |
| 721 | 721 | layout_token: ?TokenIndex, |
| 722 | 722 | kind_token: TokenIndex, |
| 723 | 723 | init_arg_expr: InitArg, |
| ... | ... | @@ -804,7 +804,7 @@ pub const Node = struct { |
| 804 | 804 | }; |
| 805 | 805 | |
| 806 | 806 | pub const ErrorTag = struct { |
| 807 | base: Node = Node {.id = .ErrorTag}, | |
| 807 | base: Node = Node{ .id = .ErrorTag }, | |
| 808 | 808 | doc_comments: ?*DocComment, |
| 809 | 809 | name_token: TokenIndex, |
| 810 | 810 | |
| ... | ... | @@ -829,7 +829,7 @@ pub const Node = struct { |
| 829 | 829 | }; |
| 830 | 830 | |
| 831 | 831 | pub const Identifier = struct { |
| 832 | base: Node = Node {.id = .Identifier}, | |
| 832 | base: Node = Node{ .id = .Identifier }, | |
| 833 | 833 | token: TokenIndex, |
| 834 | 834 | |
| 835 | 835 | pub fn iterate(self: *Identifier, index: usize) ?*Node { |
| ... | ... | @@ -846,7 +846,7 @@ pub const Node = struct { |
| 846 | 846 | }; |
| 847 | 847 | |
| 848 | 848 | pub const FnProto = struct { |
| 849 | base: Node = Node {.id = .FnProto}, | |
| 849 | base: Node = Node{ .id = .FnProto }, | |
| 850 | 850 | doc_comments: ?*DocComment, |
| 851 | 851 | visib_token: ?TokenIndex, |
| 852 | 852 | fn_token: TokenIndex, |
| ... | ... | @@ -928,7 +928,7 @@ pub const Node = struct { |
| 928 | 928 | }; |
| 929 | 929 | |
| 930 | 930 | pub const AnyFrameType = struct { |
| 931 | base: Node = Node {.id = .AnyFrameType}, | |
| 931 | base: Node = Node{ .id = .AnyFrameType }, | |
| 932 | 932 | anyframe_token: TokenIndex, |
| 933 | 933 | result: ?Result, |
| 934 | 934 | |
| ... | ... | @@ -959,7 +959,7 @@ pub const Node = struct { |
| 959 | 959 | }; |
| 960 | 960 | |
| 961 | 961 | pub const ParamDecl = struct { |
| 962 | base: Node = Node {.id = .ParamDecl}, | |
| 962 | base: Node = Node{ .id = .ParamDecl }, | |
| 963 | 963 | doc_comments: ?*DocComment, |
| 964 | 964 | comptime_token: ?TokenIndex, |
| 965 | 965 | noalias_token: ?TokenIndex, |
| ... | ... | @@ -992,7 +992,7 @@ pub const Node = struct { |
| 992 | 992 | }; |
| 993 | 993 | |
| 994 | 994 | pub const Block = struct { |
| 995 | base: Node = Node {.id = .Block}, | |
| 995 | base: Node = Node{ .id = .Block }, | |
| 996 | 996 | label: ?TokenIndex, |
| 997 | 997 | lbrace: TokenIndex, |
| 998 | 998 | statements: StatementList, |
| ... | ... | @@ -1023,7 +1023,7 @@ pub const Node = struct { |
| 1023 | 1023 | }; |
| 1024 | 1024 | |
| 1025 | 1025 | pub const Defer = struct { |
| 1026 | base: Node = Node {.id = .Defer}, | |
| 1026 | base: Node = Node{ .id = .Defer }, | |
| 1027 | 1027 | defer_token: TokenIndex, |
| 1028 | 1028 | expr: *Node, |
| 1029 | 1029 | |
| ... | ... | @@ -1046,7 +1046,7 @@ pub const Node = struct { |
| 1046 | 1046 | }; |
| 1047 | 1047 | |
| 1048 | 1048 | pub const Comptime = struct { |
| 1049 | base: Node = Node {.id = .Comptime}, | |
| 1049 | base: Node = Node{ .id = .Comptime }, | |
| 1050 | 1050 | doc_comments: ?*DocComment, |
| 1051 | 1051 | comptime_token: TokenIndex, |
| 1052 | 1052 | expr: *Node, |
| ... | ... | @@ -1070,7 +1070,7 @@ pub const Node = struct { |
| 1070 | 1070 | }; |
| 1071 | 1071 | |
| 1072 | 1072 | pub const Payload = struct { |
| 1073 | base: Node = Node {.id = .Payload}, | |
| 1073 | base: Node = Node{ .id = .Payload }, | |
| 1074 | 1074 | lpipe: TokenIndex, |
| 1075 | 1075 | error_symbol: *Node, |
| 1076 | 1076 | rpipe: TokenIndex, |
| ... | ... | @@ -1094,7 +1094,7 @@ pub const Node = struct { |
| 1094 | 1094 | }; |
| 1095 | 1095 | |
| 1096 | 1096 | pub const PointerPayload = struct { |
| 1097 | base: Node = Node {.id = .PointerPayload}, | |
| 1097 | base: Node = Node{ .id = .PointerPayload }, | |
| 1098 | 1098 | lpipe: TokenIndex, |
| 1099 | 1099 | ptr_token: ?TokenIndex, |
| 1100 | 1100 | value_symbol: *Node, |
| ... | ... | @@ -1119,7 +1119,7 @@ pub const Node = struct { |
| 1119 | 1119 | }; |
| 1120 | 1120 | |
| 1121 | 1121 | pub const PointerIndexPayload = struct { |
| 1122 | base: Node = Node {.id = .PointerIndexPayload}, | |
| 1122 | base: Node = Node{ .id = .PointerIndexPayload }, | |
| 1123 | 1123 | lpipe: TokenIndex, |
| 1124 | 1124 | ptr_token: ?TokenIndex, |
| 1125 | 1125 | value_symbol: *Node, |
| ... | ... | @@ -1150,7 +1150,7 @@ pub const Node = struct { |
| 1150 | 1150 | }; |
| 1151 | 1151 | |
| 1152 | 1152 | pub const Else = struct { |
| 1153 | base: Node = Node {.id = .Else}, | |
| 1153 | base: Node = Node{ .id = .Else }, | |
| 1154 | 1154 | else_token: TokenIndex, |
| 1155 | 1155 | payload: ?*Node, |
| 1156 | 1156 | body: *Node, |
| ... | ... | @@ -1179,7 +1179,7 @@ pub const Node = struct { |
| 1179 | 1179 | }; |
| 1180 | 1180 | |
| 1181 | 1181 | pub const Switch = struct { |
| 1182 | base: Node = Node {.id = .Switch}, | |
| 1182 | base: Node = Node{ .id = .Switch }, | |
| 1183 | 1183 | switch_token: TokenIndex, |
| 1184 | 1184 | expr: *Node, |
| 1185 | 1185 | |
| ... | ... | @@ -1211,7 +1211,7 @@ pub const Node = struct { |
| 1211 | 1211 | }; |
| 1212 | 1212 | |
| 1213 | 1213 | pub const SwitchCase = struct { |
| 1214 | base: Node = Node {.id = .SwitchCase}, | |
| 1214 | base: Node = Node{ .id = .SwitchCase }, | |
| 1215 | 1215 | items: ItemList, |
| 1216 | 1216 | arrow_token: TokenIndex, |
| 1217 | 1217 | payload: ?*Node, |
| ... | ... | @@ -1246,7 +1246,7 @@ pub const Node = struct { |
| 1246 | 1246 | }; |
| 1247 | 1247 | |
| 1248 | 1248 | pub const SwitchElse = struct { |
| 1249 | base: Node = Node {.id = .SwitchElse}, | |
| 1249 | base: Node = Node{ .id = .SwitchElse }, | |
| 1250 | 1250 | token: TokenIndex, |
| 1251 | 1251 | |
| 1252 | 1252 | pub fn iterate(self: *SwitchElse, index: usize) ?*Node { |
| ... | ... | @@ -1263,7 +1263,7 @@ pub const Node = struct { |
| 1263 | 1263 | }; |
| 1264 | 1264 | |
| 1265 | 1265 | pub const While = struct { |
| 1266 | base: Node = Node {.id = .While}, | |
| 1266 | base: Node = Node{ .id = .While }, | |
| 1267 | 1267 | label: ?TokenIndex, |
| 1268 | 1268 | inline_token: ?TokenIndex, |
| 1269 | 1269 | while_token: TokenIndex, |
| ... | ... | @@ -1322,7 +1322,7 @@ pub const Node = struct { |
| 1322 | 1322 | }; |
| 1323 | 1323 | |
| 1324 | 1324 | pub const For = struct { |
| 1325 | base: Node = Node {.id = .For}, | |
| 1325 | base: Node = Node{ .id = .For }, | |
| 1326 | 1326 | label: ?TokenIndex, |
| 1327 | 1327 | inline_token: ?TokenIndex, |
| 1328 | 1328 | for_token: TokenIndex, |
| ... | ... | @@ -1373,7 +1373,7 @@ pub const Node = struct { |
| 1373 | 1373 | }; |
| 1374 | 1374 | |
| 1375 | 1375 | pub const If = struct { |
| 1376 | base: Node = Node {.id = .If}, | |
| 1376 | base: Node = Node{ .id = .If }, | |
| 1377 | 1377 | if_token: TokenIndex, |
| 1378 | 1378 | condition: *Node, |
| 1379 | 1379 | payload: ?*Node, |
| ... | ... | @@ -1416,7 +1416,7 @@ pub const Node = struct { |
| 1416 | 1416 | }; |
| 1417 | 1417 | |
| 1418 | 1418 | pub const InfixOp = struct { |
| 1419 | base: Node = Node {.id = .InfixOp}, | |
| 1419 | base: Node = Node{ .id = .InfixOp }, | |
| 1420 | 1420 | op_token: TokenIndex, |
| 1421 | 1421 | lhs: *Node, |
| 1422 | 1422 | op: Op, |
| ... | ... | @@ -1649,7 +1649,7 @@ pub const Node = struct { |
| 1649 | 1649 | }; |
| 1650 | 1650 | |
| 1651 | 1651 | pub const FieldInitializer = struct { |
| 1652 | base: Node = Node {.id = .FieldInitializer}, | |
| 1652 | base: Node = Node{ .id = .FieldInitializer }, | |
| 1653 | 1653 | period_token: TokenIndex, |
| 1654 | 1654 | name_token: TokenIndex, |
| 1655 | 1655 | expr: *Node, |
| ... | ... | @@ -1673,7 +1673,7 @@ pub const Node = struct { |
| 1673 | 1673 | }; |
| 1674 | 1674 | |
| 1675 | 1675 | pub const SuffixOp = struct { |
| 1676 | base: Node = Node {.id = .SuffixOp}, | |
| 1676 | base: Node = Node{ .id = .SuffixOp }, | |
| 1677 | 1677 | lhs: Lhs, |
| 1678 | 1678 | op: Op, |
| 1679 | 1679 | rtoken: TokenIndex, |
| ... | ... | @@ -1774,7 +1774,7 @@ pub const Node = struct { |
| 1774 | 1774 | }; |
| 1775 | 1775 | |
| 1776 | 1776 | pub const GroupedExpression = struct { |
| 1777 | base: Node = Node {.id = .GroupedExpression}, | |
| 1777 | base: Node = Node{ .id = .GroupedExpression }, | |
| 1778 | 1778 | lparen: TokenIndex, |
| 1779 | 1779 | expr: *Node, |
| 1780 | 1780 | rparen: TokenIndex, |
| ... | ... | @@ -1798,7 +1798,7 @@ pub const Node = struct { |
| 1798 | 1798 | }; |
| 1799 | 1799 | |
| 1800 | 1800 | pub const ControlFlowExpression = struct { |
| 1801 | base: Node = Node {.id = .ControlFlowExpression}, | |
| 1801 | base: Node = Node{ .id = .ControlFlowExpression }, | |
| 1802 | 1802 | ltoken: TokenIndex, |
| 1803 | 1803 | kind: Kind, |
| 1804 | 1804 | rhs: ?*Node, |
| ... | ... | @@ -1864,7 +1864,7 @@ pub const Node = struct { |
| 1864 | 1864 | }; |
| 1865 | 1865 | |
| 1866 | 1866 | pub const Suspend = struct { |
| 1867 | base: Node = Node {.id = .Suspend}, | |
| 1867 | base: Node = Node{ .id = .Suspend }, | |
| 1868 | 1868 | suspend_token: TokenIndex, |
| 1869 | 1869 | body: ?*Node, |
| 1870 | 1870 | |
| ... | ... | @@ -1893,7 +1893,7 @@ pub const Node = struct { |
| 1893 | 1893 | }; |
| 1894 | 1894 | |
| 1895 | 1895 | pub const IntegerLiteral = struct { |
| 1896 | base: Node = Node {.id = .IntegerLiteral}, | |
| 1896 | base: Node = Node{ .id = .IntegerLiteral }, | |
| 1897 | 1897 | token: TokenIndex, |
| 1898 | 1898 | |
| 1899 | 1899 | pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node { |
| ... | ... | @@ -1910,7 +1910,7 @@ pub const Node = struct { |
| 1910 | 1910 | }; |
| 1911 | 1911 | |
| 1912 | 1912 | pub const EnumLiteral = struct { |
| 1913 | base: Node = Node {.id = .EnumLiteral}, | |
| 1913 | base: Node = Node{ .id = .EnumLiteral }, | |
| 1914 | 1914 | dot: TokenIndex, |
| 1915 | 1915 | name: TokenIndex, |
| 1916 | 1916 | |
| ... | ... | @@ -1928,7 +1928,7 @@ pub const Node = struct { |
| 1928 | 1928 | }; |
| 1929 | 1929 | |
| 1930 | 1930 | pub const FloatLiteral = struct { |
| 1931 | base: Node = Node {.id = .FloatLiteral}, | |
| 1931 | base: Node = Node{ .id = .FloatLiteral }, | |
| 1932 | 1932 | token: TokenIndex, |
| 1933 | 1933 | |
| 1934 | 1934 | pub fn iterate(self: *FloatLiteral, index: usize) ?*Node { |
| ... | ... | @@ -1945,7 +1945,7 @@ pub const Node = struct { |
| 1945 | 1945 | }; |
| 1946 | 1946 | |
| 1947 | 1947 | pub const BuiltinCall = struct { |
| 1948 | base: Node = Node {.id = .BuiltinCall}, | |
| 1948 | base: Node = Node{ .id = .BuiltinCall }, | |
| 1949 | 1949 | builtin_token: TokenIndex, |
| 1950 | 1950 | params: ParamList, |
| 1951 | 1951 | rparen_token: TokenIndex, |
| ... | ... | @@ -1971,7 +1971,7 @@ pub const Node = struct { |
| 1971 | 1971 | }; |
| 1972 | 1972 | |
| 1973 | 1973 | pub const StringLiteral = struct { |
| 1974 | base: Node = Node {.id = .StringLiteral}, | |
| 1974 | base: Node = Node{ .id = .StringLiteral }, | |
| 1975 | 1975 | token: TokenIndex, |
| 1976 | 1976 | |
| 1977 | 1977 | pub fn iterate(self: *StringLiteral, index: usize) ?*Node { |
| ... | ... | @@ -1988,7 +1988,7 @@ pub const Node = struct { |
| 1988 | 1988 | }; |
| 1989 | 1989 | |
| 1990 | 1990 | pub const MultilineStringLiteral = struct { |
| 1991 | base: Node = Node {.id = .MultilineStringLiteral}, | |
| 1991 | base: Node = Node{ .id = .MultilineStringLiteral }, | |
| 1992 | 1992 | lines: LineList, |
| 1993 | 1993 | |
| 1994 | 1994 | pub const LineList = SegmentedList(TokenIndex, 4); |
| ... | ... | @@ -2007,7 +2007,7 @@ pub const Node = struct { |
| 2007 | 2007 | }; |
| 2008 | 2008 | |
| 2009 | 2009 | pub const CharLiteral = struct { |
| 2010 | base: Node = Node {.id = .CharLiteral}, | |
| 2010 | base: Node = Node{ .id = .CharLiteral }, | |
| 2011 | 2011 | token: TokenIndex, |
| 2012 | 2012 | |
| 2013 | 2013 | pub fn iterate(self: *CharLiteral, index: usize) ?*Node { |
| ... | ... | @@ -2024,7 +2024,7 @@ pub const Node = struct { |
| 2024 | 2024 | }; |
| 2025 | 2025 | |
| 2026 | 2026 | pub const BoolLiteral = struct { |
| 2027 | base: Node = Node {.id = .BoolLiteral}, | |
| 2027 | base: Node = Node{ .id = .BoolLiteral }, | |
| 2028 | 2028 | token: TokenIndex, |
| 2029 | 2029 | |
| 2030 | 2030 | pub fn iterate(self: *BoolLiteral, index: usize) ?*Node { |
| ... | ... | @@ -2041,7 +2041,7 @@ pub const Node = struct { |
| 2041 | 2041 | }; |
| 2042 | 2042 | |
| 2043 | 2043 | pub const NullLiteral = struct { |
| 2044 | base: Node = Node {.id = .NullLiteral}, | |
| 2044 | base: Node = Node{ .id = .NullLiteral }, | |
| 2045 | 2045 | token: TokenIndex, |
| 2046 | 2046 | |
| 2047 | 2047 | pub fn iterate(self: *NullLiteral, index: usize) ?*Node { |
| ... | ... | @@ -2058,7 +2058,7 @@ pub const Node = struct { |
| 2058 | 2058 | }; |
| 2059 | 2059 | |
| 2060 | 2060 | pub const UndefinedLiteral = struct { |
| 2061 | base: Node = Node {.id = .UndefinedLiteral}, | |
| 2061 | base: Node = Node{ .id = .UndefinedLiteral }, | |
| 2062 | 2062 | token: TokenIndex, |
| 2063 | 2063 | |
| 2064 | 2064 | pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node { |
| ... | ... | @@ -2075,7 +2075,7 @@ pub const Node = struct { |
| 2075 | 2075 | }; |
| 2076 | 2076 | |
| 2077 | 2077 | pub const AsmOutput = struct { |
| 2078 | base: Node = Node {.id = .AsmOutput}, | |
| 2078 | base: Node = Node{ .id = .AsmOutput }, | |
| 2079 | 2079 | lbracket: TokenIndex, |
| 2080 | 2080 | symbolic_name: *Node, |
| 2081 | 2081 | constraint: *Node, |
| ... | ... | @@ -2120,7 +2120,7 @@ pub const Node = struct { |
| 2120 | 2120 | }; |
| 2121 | 2121 | |
| 2122 | 2122 | pub const AsmInput = struct { |
| 2123 | base: Node = Node {.id = .AsmInput}, | |
| 2123 | base: Node = Node{ .id = .AsmInput }, | |
| 2124 | 2124 | lbracket: TokenIndex, |
| 2125 | 2125 | symbolic_name: *Node, |
| 2126 | 2126 | constraint: *Node, |
| ... | ... | @@ -2152,7 +2152,7 @@ pub const Node = struct { |
| 2152 | 2152 | }; |
| 2153 | 2153 | |
| 2154 | 2154 | pub const Asm = struct { |
| 2155 | base: Node = Node {.id = .Asm}, | |
| 2155 | base: Node = Node{ .id = .Asm }, | |
| 2156 | 2156 | asm_token: TokenIndex, |
| 2157 | 2157 | volatile_token: ?TokenIndex, |
| 2158 | 2158 | template: *Node, |
| ... | ... | @@ -2187,7 +2187,7 @@ pub const Node = struct { |
| 2187 | 2187 | }; |
| 2188 | 2188 | |
| 2189 | 2189 | pub const Unreachable = struct { |
| 2190 | base: Node = Node {.id = .Unreachable}, | |
| 2190 | base: Node = Node{ .id = .Unreachable }, | |
| 2191 | 2191 | token: TokenIndex, |
| 2192 | 2192 | |
| 2193 | 2193 | pub fn iterate(self: *Unreachable, index: usize) ?*Node { |
| ... | ... | @@ -2204,7 +2204,7 @@ pub const Node = struct { |
| 2204 | 2204 | }; |
| 2205 | 2205 | |
| 2206 | 2206 | pub const ErrorType = struct { |
| 2207 | base: Node = Node {.id = .ErrorType}, | |
| 2207 | base: Node = Node{ .id = .ErrorType }, | |
| 2208 | 2208 | token: TokenIndex, |
| 2209 | 2209 | |
| 2210 | 2210 | pub fn iterate(self: *ErrorType, index: usize) ?*Node { |
| ... | ... | @@ -2238,7 +2238,7 @@ pub const Node = struct { |
| 2238 | 2238 | }; |
| 2239 | 2239 | |
| 2240 | 2240 | pub const DocComment = struct { |
| 2241 | base: Node = Node {.id = .DocComment}, | |
| 2241 | base: Node = Node{ .id = .DocComment }, | |
| 2242 | 2242 | lines: LineList, |
| 2243 | 2243 | |
| 2244 | 2244 | pub const LineList = SegmentedList(TokenIndex, 4); |
| ... | ... | @@ -2257,7 +2257,7 @@ pub const Node = struct { |
| 2257 | 2257 | }; |
| 2258 | 2258 | |
| 2259 | 2259 | pub const TestDecl = struct { |
| 2260 | base: Node = Node {.id = .TestDecl}, | |
| 2260 | base: Node = Node{ .id = .TestDecl }, | |
| 2261 | 2261 | doc_comments: ?*DocComment, |
| 2262 | 2262 | test_token: TokenIndex, |
| 2263 | 2263 | name: *Node, |
src-self-hosted/translate_c.zig+19-27| ... | ... | @@ -1194,7 +1194,7 @@ fn transImplicitCastExpr( |
| 1194 | 1194 | const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr)); |
| 1195 | 1195 | const src_type = getExprQualType(c, sub_expr); |
| 1196 | 1196 | switch (ZigClangImplicitCastExpr_getCastKind(expr)) { |
| 1197 | .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast => { | |
| 1197 | .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => { | |
| 1198 | 1198 | return transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, sub_expr_node); |
| 1199 | 1199 | }, |
| 1200 | 1200 | .LValueToRValue, .NoOp, .FunctionToPointerDecay, .ArrayToPointerDecay => { |
| ... | ... | @@ -1221,29 +1221,6 @@ fn transImplicitCastExpr( |
| 1221 | 1221 | const rhs_node = try transCreateNodeInt(rp.c, 0); |
| 1222 | 1222 | return transCreateNodeInfixOp(rp, scope, node, .BangEqual, op_token, rhs_node, result_used, false); |
| 1223 | 1223 | }, |
| 1224 | .PointerToIntegral => { | |
| 1225 | // @intCast(dest_type, @ptrToInt(val)) | |
| 1226 | const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@intCast"); | |
| 1227 | try cast_node.params.push(try transQualType(rp, dest_type, ZigClangImplicitCastExpr_getBeginLoc(expr))); | |
| 1228 | _ = try appendToken(rp.c, .Comma, ","); | |
| 1229 | ||
| 1230 | const ptr_to_int = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt"); | |
| 1231 | try ptr_to_int.params.push(try transExpr(rp, scope, sub_expr, .used, .r_value)); | |
| 1232 | ptr_to_int.rparen_token = try appendToken(rp.c, .RParen, ")"); | |
| 1233 | try cast_node.params.push(&ptr_to_int.base); | |
| 1234 | cast_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | |
| 1235 | return maybeSuppressResult(rp, scope, result_used, &cast_node.base); | |
| 1236 | }, | |
| 1237 | .IntegralToPointer => { | |
| 1238 | // @intToPtr(dest_type, val) | |
| 1239 | const int_to_ptr = try transCreateNodeBuiltinFnCall(rp.c, "@intToPtr"); | |
| 1240 | try int_to_ptr.params.push(try transQualType(rp, dest_type, ZigClangImplicitCastExpr_getBeginLoc(expr))); | |
| 1241 | _ = try appendToken(rp.c, .Comma, ","); | |
| 1242 | ||
| 1243 | try int_to_ptr.params.push(try transExpr(rp, scope, sub_expr, .used, .r_value)); | |
| 1244 | int_to_ptr.rparen_token = try appendToken(rp.c, .RParen, ")"); | |
| 1245 | return maybeSuppressResult(rp, scope, result_used, &int_to_ptr.base); | |
| 1246 | }, | |
| 1247 | 1224 | else => |kind| return revertAndWarn( |
| 1248 | 1225 | rp, |
| 1249 | 1226 | error.UnsupportedTranslation, |
| ... | ... | @@ -1509,8 +1486,18 @@ fn transCCast( |
| 1509 | 1486 | if (ZigClangQualType_eq(dst_type, src_type)) return expr; |
| 1510 | 1487 | if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type)) |
| 1511 | 1488 | return transCPtrCast(rp, loc, dst_type, src_type, expr); |
| 1512 | if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) { | |
| 1513 | const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as"); | |
| 1489 | if (cIsInteger(dst_type) and cIsInteger(src_type)) { | |
| 1490 | // @intCast(dest_type, val) | |
| 1491 | const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@intCast"); | |
| 1492 | try cast_node.params.push(try transQualType(rp, dst_type, loc)); | |
| 1493 | _ = try appendToken(rp.c, .Comma, ","); | |
| 1494 | try cast_node.params.push(expr); | |
| 1495 | cast_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | |
| 1496 | return &cast_node.base; | |
| 1497 | } | |
| 1498 | if (cIsInteger(dst_type) and qualTypeIsPtr(src_type)) { | |
| 1499 | // @intCast(dest_type, @ptrToInt(val)) | |
| 1500 | const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@intCast"); | |
| 1514 | 1501 | try cast_node.params.push(try transQualType(rp, dst_type, loc)); |
| 1515 | 1502 | _ = try appendToken(rp.c, .Comma, ","); |
| 1516 | 1503 | const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt"); |
| ... | ... | @@ -1520,7 +1507,8 @@ fn transCCast( |
| 1520 | 1507 | cast_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| 1521 | 1508 | return &cast_node.base; |
| 1522 | 1509 | } |
| 1523 | if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) { | |
| 1510 | if (cIsInteger(src_type) and qualTypeIsPtr(dst_type)) { | |
| 1511 | // @intToPtr(dest_type, val) | |
| 1524 | 1512 | const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@intToPtr"); |
| 1525 | 1513 | try builtin_node.params.push(try transQualType(rp, dst_type, loc)); |
| 1526 | 1514 | _ = try appendToken(rp.c, .Comma, ","); |
| ... | ... | @@ -2870,6 +2858,10 @@ fn typeIsOpaque(c: *Context, ty: *const ZigClangType, loc: ZigClangSourceLocatio |
| 2870 | 2858 | } |
| 2871 | 2859 | } |
| 2872 | 2860 | |
| 2861 | fn cIsInteger(qt: ZigClangQualType) bool { | |
| 2862 | return cIsSignedInteger(qt) or cIsUnsignedInteger(qt); | |
| 2863 | } | |
| 2864 | ||
| 2873 | 2865 | fn cIsUnsignedInteger(qt: ZigClangQualType) bool { |
| 2874 | 2866 | const c_type = qualTypeCanon(qt); |
| 2875 | 2867 | if (ZigClangType_getTypeClass(c_type) != .Builtin) return false; |
test/translate_c.zig+36-36| ... | ... | @@ -21,9 +21,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 21 | 21 | , &[_][]const u8{ |
| 22 | 22 | \\pub export fn foo() void { |
| 23 | 23 | \\ var a: c_int = undefined; |
| 24 | \\ var b: u8 = @as(u8, 123); | |
| 24 | \\ var b: u8 = @intCast(u8, 123); | |
| 25 | 25 | \\ const c: c_int = undefined; |
| 26 | \\ const d: c_uint = @as(c_uint, 440); | |
| 26 | \\ const d: c_uint = @intCast(c_uint, 440); | |
| 27 | 27 | \\} |
| 28 | 28 | }); |
| 29 | 29 | |
| ... | ... | @@ -110,7 +110,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 110 | 110 | \\pub extern fn foo() void; |
| 111 | 111 | \\pub export fn bar() void { |
| 112 | 112 | \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo); |
| 113 | \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr))); | |
| 113 | \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @intCast(c_ulong, @ptrToInt(func_ptr))); | |
| 114 | 114 | \\} |
| 115 | 115 | }); |
| 116 | 116 | |
| ... | ... | @@ -855,7 +855,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 855 | 855 | , &[_][]const u8{ |
| 856 | 856 | \\pub fn foo() void { |
| 857 | 857 | \\ var arr: [10]u8 = .{ |
| 858 | \\ @as(u8, 1), | |
| 858 | \\ @intCast(u8, 1), | |
| 859 | 859 | \\ } ++ .{0} ** 9; |
| 860 | 860 | \\ var arr1: [10][*c]u8 = .{ |
| 861 | 861 | \\ null, |
| ... | ... | @@ -1082,18 +1082,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1082 | 1082 | \\ unsigned d = 440; |
| 1083 | 1083 | \\} |
| 1084 | 1084 | , &[_][]const u8{ |
| 1085 | \\pub var a: c_long = @as(c_long, 2); | |
| 1086 | \\pub var b: c_long = @as(c_long, 2); | |
| 1085 | \\pub var a: c_long = @intCast(c_long, 2); | |
| 1086 | \\pub var b: c_long = @intCast(c_long, 2); | |
| 1087 | 1087 | \\pub var c: c_int = 4; |
| 1088 | 1088 | \\pub export fn foo(_arg_c_1: u8) void { |
| 1089 | 1089 | \\ var c_1 = _arg_c_1; |
| 1090 | 1090 | \\ var a_2: c_int = undefined; |
| 1091 | \\ var b_3: u8 = @as(u8, 123); | |
| 1092 | \\ b_3 = @as(u8, a_2); | |
| 1091 | \\ var b_3: u8 = @intCast(u8, 123); | |
| 1092 | \\ b_3 = @intCast(u8, a_2); | |
| 1093 | 1093 | \\ { |
| 1094 | 1094 | \\ var d: c_int = 5; |
| 1095 | 1095 | \\ } |
| 1096 | \\ var d: c_uint = @as(c_uint, 440); | |
| 1096 | \\ var d: c_uint = @intCast(c_uint, 440); | |
| 1097 | 1097 | \\} |
| 1098 | 1098 | }); |
| 1099 | 1099 | |
| ... | ... | @@ -1216,14 +1216,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1216 | 1216 | \\ _ = 7; |
| 1217 | 1217 | \\ } |
| 1218 | 1218 | \\ } |
| 1219 | \\ var i: u8 = @as(u8, 2); | |
| 1219 | \\ var i: u8 = @intCast(u8, 2); | |
| 1220 | 1220 | \\} |
| 1221 | 1221 | }); |
| 1222 | 1222 | |
| 1223 | 1223 | cases.add("shadowing primitive types", |
| 1224 | 1224 | \\unsigned anyerror = 2; |
| 1225 | 1225 | , &[_][]const u8{ |
| 1226 | \\pub export var _anyerror: c_uint = @as(c_uint, 2); | |
| 1226 | \\pub export var _anyerror: c_uint = @intCast(c_uint, 2); | |
| 1227 | 1227 | }); |
| 1228 | 1228 | |
| 1229 | 1229 | cases.add("floats", |
| ... | ... | @@ -1397,17 +1397,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1397 | 1397 | \\ |
| 1398 | 1398 | , &[_][]const u8{ |
| 1399 | 1399 | \\pub export fn escapes() [*c]const u8 { |
| 1400 | \\ var a: u8 = @as(u8, '\''); | |
| 1401 | \\ var b: u8 = @as(u8, '\\'); | |
| 1402 | \\ var c: u8 = @as(u8, '\x07'); | |
| 1403 | \\ var d: u8 = @as(u8, '\x08'); | |
| 1404 | \\ var e: u8 = @as(u8, '\x0c'); | |
| 1405 | \\ var f: u8 = @as(u8, '\n'); | |
| 1406 | \\ var g: u8 = @as(u8, '\r'); | |
| 1407 | \\ var h: u8 = @as(u8, '\t'); | |
| 1408 | \\ var i: u8 = @as(u8, '\x0b'); | |
| 1409 | \\ var j: u8 = @as(u8, '\x00'); | |
| 1410 | \\ var k: u8 = @as(u8, '\"'); | |
| 1400 | \\ var a: u8 = @intCast(u8, '\''); | |
| 1401 | \\ var b: u8 = @intCast(u8, '\\'); | |
| 1402 | \\ var c: u8 = @intCast(u8, '\x07'); | |
| 1403 | \\ var d: u8 = @intCast(u8, '\x08'); | |
| 1404 | \\ var e: u8 = @intCast(u8, '\x0c'); | |
| 1405 | \\ var f: u8 = @intCast(u8, '\n'); | |
| 1406 | \\ var g: u8 = @intCast(u8, '\r'); | |
| 1407 | \\ var h: u8 = @intCast(u8, '\t'); | |
| 1408 | \\ var i: u8 = @intCast(u8, '\x0b'); | |
| 1409 | \\ var j: u8 = @intCast(u8, '\x00'); | |
| 1410 | \\ var k: u8 = @intCast(u8, '\"'); | |
| 1411 | 1411 | \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\""; |
| 1412 | 1412 | \\} |
| 1413 | 1413 | }); |
| ... | ... | @@ -1818,7 +1818,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1818 | 1818 | , &[_][]const u8{ |
| 1819 | 1819 | \\pub export fn foo() void { |
| 1820 | 1820 | \\ var i: c_int = 0; |
| 1821 | \\ var u: c_uint = @as(c_uint, 0); | |
| 1821 | \\ var u: c_uint = @intCast(c_uint, 0); | |
| 1822 | 1822 | \\ i += 1; |
| 1823 | 1823 | \\ i -= 1; |
| 1824 | 1824 | \\ u +%= 1; |
| ... | ... | @@ -1858,7 +1858,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1858 | 1858 | \\pub export fn log2(_arg_a: c_uint) c_int { |
| 1859 | 1859 | \\ var a = _arg_a; |
| 1860 | 1860 | \\ var i: c_int = 0; |
| 1861 | \\ while (a > @as(c_uint, 0)) { | |
| 1861 | \\ while (a > @intCast(c_uint, 0)) { | |
| 1862 | 1862 | \\ a >>= @as(@import("std").math.Log2Int(c_int), 1); |
| 1863 | 1863 | \\ } |
| 1864 | 1864 | \\ return i; |
| ... | ... | @@ -1878,7 +1878,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1878 | 1878 | \\pub export fn log2(_arg_a: u32) c_int { |
| 1879 | 1879 | \\ var a = _arg_a; |
| 1880 | 1880 | \\ var i: c_int = 0; |
| 1881 | \\ while (a > @as(c_uint, 0)) { | |
| 1881 | \\ while (a > @intCast(c_uint, 0)) { | |
| 1882 | 1882 | \\ a >>= @as(@import("std").math.Log2Int(c_int), 1); |
| 1883 | 1883 | \\ } |
| 1884 | 1884 | \\ return i; |
| ... | ... | @@ -1957,35 +1957,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1957 | 1957 | \\} |
| 1958 | 1958 | , &[_][]const u8{ |
| 1959 | 1959 | \\pub export fn foo() void { |
| 1960 | \\ var a: c_uint = @as(c_uint, 0); | |
| 1960 | \\ var a: c_uint = @intCast(c_uint, 0); | |
| 1961 | 1961 | \\ a +%= (blk: { |
| 1962 | 1962 | \\ const _ref_1 = &a; |
| 1963 | \\ _ref_1.* = _ref_1.* +% @as(c_uint, 1); | |
| 1963 | \\ _ref_1.* = _ref_1.* +% @intCast(c_uint, 1); | |
| 1964 | 1964 | \\ break :blk _ref_1.*; |
| 1965 | 1965 | \\ }); |
| 1966 | 1966 | \\ a -%= (blk: { |
| 1967 | 1967 | \\ const _ref_2 = &a; |
| 1968 | \\ _ref_2.* = _ref_2.* -% @as(c_uint, 1); | |
| 1968 | \\ _ref_2.* = _ref_2.* -% @intCast(c_uint, 1); | |
| 1969 | 1969 | \\ break :blk _ref_2.*; |
| 1970 | 1970 | \\ }); |
| 1971 | 1971 | \\ a *%= (blk: { |
| 1972 | 1972 | \\ const _ref_3 = &a; |
| 1973 | \\ _ref_3.* = _ref_3.* *% @as(c_uint, 1); | |
| 1973 | \\ _ref_3.* = _ref_3.* *% @intCast(c_uint, 1); | |
| 1974 | 1974 | \\ break :blk _ref_3.*; |
| 1975 | 1975 | \\ }); |
| 1976 | 1976 | \\ a &= (blk: { |
| 1977 | 1977 | \\ const _ref_4 = &a; |
| 1978 | \\ _ref_4.* = _ref_4.* & @as(c_uint, 1); | |
| 1978 | \\ _ref_4.* = _ref_4.* & @intCast(c_uint, 1); | |
| 1979 | 1979 | \\ break :blk _ref_4.*; |
| 1980 | 1980 | \\ }); |
| 1981 | 1981 | \\ a |= (blk: { |
| 1982 | 1982 | \\ const _ref_5 = &a; |
| 1983 | \\ _ref_5.* = _ref_5.* | @as(c_uint, 1); | |
| 1983 | \\ _ref_5.* = _ref_5.* | @intCast(c_uint, 1); | |
| 1984 | 1984 | \\ break :blk _ref_5.*; |
| 1985 | 1985 | \\ }); |
| 1986 | 1986 | \\ a ^= (blk: { |
| 1987 | 1987 | \\ const _ref_6 = &a; |
| 1988 | \\ _ref_6.* = _ref_6.* ^ @as(c_uint, 1); | |
| 1988 | \\ _ref_6.* = _ref_6.* ^ @intCast(c_uint, 1); | |
| 1989 | 1989 | \\ break :blk _ref_6.*; |
| 1990 | 1990 | \\ }); |
| 1991 | 1991 | \\ a >>= @as(@import("std").math.Log2Int(c_uint), (blk: { |
| ... | ... | @@ -2017,7 +2017,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2017 | 2017 | , &[_][]const u8{ |
| 2018 | 2018 | \\pub export fn foo() void { |
| 2019 | 2019 | \\ var i: c_int = 0; |
| 2020 | \\ var u: c_uint = @as(c_uint, 0); | |
| 2020 | \\ var u: c_uint = @intCast(c_uint, 0); | |
| 2021 | 2021 | \\ i += 1; |
| 2022 | 2022 | \\ i -= 1; |
| 2023 | 2023 | \\ u +%= 1; |
| ... | ... | @@ -2092,9 +2092,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2092 | 2092 | \\ fn_int(1094861636); |
| 2093 | 2093 | \\ fn_f32(@intToFloat(f32, 3)); |
| 2094 | 2094 | \\ fn_f64(@intToFloat(f64, 3)); |
| 2095 | \\ fn_char(@as(u8, '3')); | |
| 2096 | \\ fn_char(@as(u8, '\x01')); | |
| 2097 | \\ fn_char(@as(u8, 0)); | |
| 2095 | \\ fn_char(@intCast(u8, '3')); | |
| 2096 | \\ fn_char(@intCast(u8, '\x01')); | |
| 2097 | \\ fn_char(@intCast(u8, 0)); | |
| 2098 | 2098 | \\ fn_f32(3); |
| 2099 | 2099 | \\ fn_f64(3); |
| 2100 | 2100 | \\ fn_bool(123 != 0); |