authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-12-23 09:47:31+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-12-29 11:04:59+02:00
log59cc7072e22d03ba40456a58eaf3b37b239b420e
tree5acdaf8eed445c9269791fab8420a7b93c102d57
parent1a3633d78664701557ddf47651ea2d9d408859c5
signature Commit is signed but in an unrecognized format.

translate-c-2 use `intCast` in most places


3 files changed, 101 insertions(+), 109 deletions(-)

lib/std/zig/ast.zig+46-46
...@@ -584,7 +584,7 @@ pub const Node = struct {...@@ -584,7 +584,7 @@ pub const Node = struct {
584 }584 }
585585
586 pub const Root = struct {586 pub const Root = struct {
587 base: Node = Node {.id = .Root},587 base: Node = Node{ .id = .Root },
588 decls: DeclList,588 decls: DeclList,
589 eof_token: TokenIndex,589 eof_token: TokenIndex,
590590
...@@ -607,7 +607,7 @@ pub const Node = struct {...@@ -607,7 +607,7 @@ pub const Node = struct {
607 };607 };
608608
609 pub const VarDecl = struct {609 pub const VarDecl = struct {
610 base: Node = Node {.id = .VarDecl},610 base: Node = Node{ .id = .VarDecl },
611 doc_comments: ?*DocComment,611 doc_comments: ?*DocComment,
612 visib_token: ?TokenIndex,612 visib_token: ?TokenIndex,
613 thread_local_token: ?TokenIndex,613 thread_local_token: ?TokenIndex,
...@@ -664,7 +664,7 @@ pub const Node = struct {...@@ -664,7 +664,7 @@ pub const Node = struct {
664 };664 };
665665
666 pub const Use = struct {666 pub const Use = struct {
667 base: Node = Node {.id = .Use},667 base: Node = Node{ .id = .Use },
668 doc_comments: ?*DocComment,668 doc_comments: ?*DocComment,
669 visib_token: ?TokenIndex,669 visib_token: ?TokenIndex,
670 use_token: TokenIndex,670 use_token: TokenIndex,
...@@ -691,7 +691,7 @@ pub const Node = struct {...@@ -691,7 +691,7 @@ pub const Node = struct {
691 };691 };
692692
693 pub const ErrorSetDecl = struct {693 pub const ErrorSetDecl = struct {
694 base: Node = Node {.id = .ErrorSetDecl},694 base: Node = Node{ .id = .ErrorSetDecl },
695 error_token: TokenIndex,695 error_token: TokenIndex,
696 decls: DeclList,696 decls: DeclList,
697 rbrace_token: TokenIndex,697 rbrace_token: TokenIndex,
...@@ -717,7 +717,7 @@ pub const Node = struct {...@@ -717,7 +717,7 @@ pub const Node = struct {
717 };717 };
718718
719 pub const ContainerDecl = struct {719 pub const ContainerDecl = struct {
720 base: Node = Node {.id = .ContainerDecl},720 base: Node = Node{ .id = .ContainerDecl },
721 layout_token: ?TokenIndex,721 layout_token: ?TokenIndex,
722 kind_token: TokenIndex,722 kind_token: TokenIndex,
723 init_arg_expr: InitArg,723 init_arg_expr: InitArg,
...@@ -804,7 +804,7 @@ pub const Node = struct {...@@ -804,7 +804,7 @@ pub const Node = struct {
804 };804 };
805805
806 pub const ErrorTag = struct {806 pub const ErrorTag = struct {
807 base: Node = Node {.id = .ErrorTag},807 base: Node = Node{ .id = .ErrorTag },
808 doc_comments: ?*DocComment,808 doc_comments: ?*DocComment,
809 name_token: TokenIndex,809 name_token: TokenIndex,
810810
...@@ -829,7 +829,7 @@ pub const Node = struct {...@@ -829,7 +829,7 @@ pub const Node = struct {
829 };829 };
830830
831 pub const Identifier = struct {831 pub const Identifier = struct {
832 base: Node = Node {.id = .Identifier},832 base: Node = Node{ .id = .Identifier },
833 token: TokenIndex,833 token: TokenIndex,
834834
835 pub fn iterate(self: *Identifier, index: usize) ?*Node {835 pub fn iterate(self: *Identifier, index: usize) ?*Node {
...@@ -846,7 +846,7 @@ pub const Node = struct {...@@ -846,7 +846,7 @@ pub const Node = struct {
846 };846 };
847847
848 pub const FnProto = struct {848 pub const FnProto = struct {
849 base: Node = Node {.id = .FnProto},849 base: Node = Node{ .id = .FnProto },
850 doc_comments: ?*DocComment,850 doc_comments: ?*DocComment,
851 visib_token: ?TokenIndex,851 visib_token: ?TokenIndex,
852 fn_token: TokenIndex,852 fn_token: TokenIndex,
...@@ -928,7 +928,7 @@ pub const Node = struct {...@@ -928,7 +928,7 @@ pub const Node = struct {
928 };928 };
929929
930 pub const AnyFrameType = struct {930 pub const AnyFrameType = struct {
931 base: Node = Node {.id = .AnyFrameType},931 base: Node = Node{ .id = .AnyFrameType },
932 anyframe_token: TokenIndex,932 anyframe_token: TokenIndex,
933 result: ?Result,933 result: ?Result,
934934
...@@ -959,7 +959,7 @@ pub const Node = struct {...@@ -959,7 +959,7 @@ pub const Node = struct {
959 };959 };
960960
961 pub const ParamDecl = struct {961 pub const ParamDecl = struct {
962 base: Node = Node {.id = .ParamDecl},962 base: Node = Node{ .id = .ParamDecl },
963 doc_comments: ?*DocComment,963 doc_comments: ?*DocComment,
964 comptime_token: ?TokenIndex,964 comptime_token: ?TokenIndex,
965 noalias_token: ?TokenIndex,965 noalias_token: ?TokenIndex,
...@@ -992,7 +992,7 @@ pub const Node = struct {...@@ -992,7 +992,7 @@ pub const Node = struct {
992 };992 };
993993
994 pub const Block = struct {994 pub const Block = struct {
995 base: Node = Node {.id = .Block},995 base: Node = Node{ .id = .Block },
996 label: ?TokenIndex,996 label: ?TokenIndex,
997 lbrace: TokenIndex,997 lbrace: TokenIndex,
998 statements: StatementList,998 statements: StatementList,
...@@ -1023,7 +1023,7 @@ pub const Node = struct {...@@ -1023,7 +1023,7 @@ pub const Node = struct {
1023 };1023 };
10241024
1025 pub const Defer = struct {1025 pub const Defer = struct {
1026 base: Node = Node {.id = .Defer},1026 base: Node = Node{ .id = .Defer },
1027 defer_token: TokenIndex,1027 defer_token: TokenIndex,
1028 expr: *Node,1028 expr: *Node,
10291029
...@@ -1046,7 +1046,7 @@ pub const Node = struct {...@@ -1046,7 +1046,7 @@ pub const Node = struct {
1046 };1046 };
10471047
1048 pub const Comptime = struct {1048 pub const Comptime = struct {
1049 base: Node = Node {.id = .Comptime},1049 base: Node = Node{ .id = .Comptime },
1050 doc_comments: ?*DocComment,1050 doc_comments: ?*DocComment,
1051 comptime_token: TokenIndex,1051 comptime_token: TokenIndex,
1052 expr: *Node,1052 expr: *Node,
...@@ -1070,7 +1070,7 @@ pub const Node = struct {...@@ -1070,7 +1070,7 @@ pub const Node = struct {
1070 };1070 };
10711071
1072 pub const Payload = struct {1072 pub const Payload = struct {
1073 base: Node = Node {.id = .Payload},1073 base: Node = Node{ .id = .Payload },
1074 lpipe: TokenIndex,1074 lpipe: TokenIndex,
1075 error_symbol: *Node,1075 error_symbol: *Node,
1076 rpipe: TokenIndex,1076 rpipe: TokenIndex,
...@@ -1094,7 +1094,7 @@ pub const Node = struct {...@@ -1094,7 +1094,7 @@ pub const Node = struct {
1094 };1094 };
10951095
1096 pub const PointerPayload = struct {1096 pub const PointerPayload = struct {
1097 base: Node = Node {.id = .PointerPayload},1097 base: Node = Node{ .id = .PointerPayload },
1098 lpipe: TokenIndex,1098 lpipe: TokenIndex,
1099 ptr_token: ?TokenIndex,1099 ptr_token: ?TokenIndex,
1100 value_symbol: *Node,1100 value_symbol: *Node,
...@@ -1119,7 +1119,7 @@ pub const Node = struct {...@@ -1119,7 +1119,7 @@ pub const Node = struct {
1119 };1119 };
11201120
1121 pub const PointerIndexPayload = struct {1121 pub const PointerIndexPayload = struct {
1122 base: Node = Node {.id = .PointerIndexPayload},1122 base: Node = Node{ .id = .PointerIndexPayload },
1123 lpipe: TokenIndex,1123 lpipe: TokenIndex,
1124 ptr_token: ?TokenIndex,1124 ptr_token: ?TokenIndex,
1125 value_symbol: *Node,1125 value_symbol: *Node,
...@@ -1150,7 +1150,7 @@ pub const Node = struct {...@@ -1150,7 +1150,7 @@ pub const Node = struct {
1150 };1150 };
11511151
1152 pub const Else = struct {1152 pub const Else = struct {
1153 base: Node = Node {.id = .Else},1153 base: Node = Node{ .id = .Else },
1154 else_token: TokenIndex,1154 else_token: TokenIndex,
1155 payload: ?*Node,1155 payload: ?*Node,
1156 body: *Node,1156 body: *Node,
...@@ -1179,7 +1179,7 @@ pub const Node = struct {...@@ -1179,7 +1179,7 @@ pub const Node = struct {
1179 };1179 };
11801180
1181 pub const Switch = struct {1181 pub const Switch = struct {
1182 base: Node = Node {.id = .Switch},1182 base: Node = Node{ .id = .Switch },
1183 switch_token: TokenIndex,1183 switch_token: TokenIndex,
1184 expr: *Node,1184 expr: *Node,
11851185
...@@ -1211,7 +1211,7 @@ pub const Node = struct {...@@ -1211,7 +1211,7 @@ pub const Node = struct {
1211 };1211 };
12121212
1213 pub const SwitchCase = struct {1213 pub const SwitchCase = struct {
1214 base: Node = Node {.id = .SwitchCase},1214 base: Node = Node{ .id = .SwitchCase },
1215 items: ItemList,1215 items: ItemList,
1216 arrow_token: TokenIndex,1216 arrow_token: TokenIndex,
1217 payload: ?*Node,1217 payload: ?*Node,
...@@ -1246,7 +1246,7 @@ pub const Node = struct {...@@ -1246,7 +1246,7 @@ pub const Node = struct {
1246 };1246 };
12471247
1248 pub const SwitchElse = struct {1248 pub const SwitchElse = struct {
1249 base: Node = Node {.id = .SwitchElse},1249 base: Node = Node{ .id = .SwitchElse },
1250 token: TokenIndex,1250 token: TokenIndex,
12511251
1252 pub fn iterate(self: *SwitchElse, index: usize) ?*Node {1252 pub fn iterate(self: *SwitchElse, index: usize) ?*Node {
...@@ -1263,7 +1263,7 @@ pub const Node = struct {...@@ -1263,7 +1263,7 @@ pub const Node = struct {
1263 };1263 };
12641264
1265 pub const While = struct {1265 pub const While = struct {
1266 base: Node = Node {.id = .While},1266 base: Node = Node{ .id = .While },
1267 label: ?TokenIndex,1267 label: ?TokenIndex,
1268 inline_token: ?TokenIndex,1268 inline_token: ?TokenIndex,
1269 while_token: TokenIndex,1269 while_token: TokenIndex,
...@@ -1322,7 +1322,7 @@ pub const Node = struct {...@@ -1322,7 +1322,7 @@ pub const Node = struct {
1322 };1322 };
13231323
1324 pub const For = struct {1324 pub const For = struct {
1325 base: Node = Node {.id = .For},1325 base: Node = Node{ .id = .For },
1326 label: ?TokenIndex,1326 label: ?TokenIndex,
1327 inline_token: ?TokenIndex,1327 inline_token: ?TokenIndex,
1328 for_token: TokenIndex,1328 for_token: TokenIndex,
...@@ -1373,7 +1373,7 @@ pub const Node = struct {...@@ -1373,7 +1373,7 @@ pub const Node = struct {
1373 };1373 };
13741374
1375 pub const If = struct {1375 pub const If = struct {
1376 base: Node = Node {.id = .If},1376 base: Node = Node{ .id = .If },
1377 if_token: TokenIndex,1377 if_token: TokenIndex,
1378 condition: *Node,1378 condition: *Node,
1379 payload: ?*Node,1379 payload: ?*Node,
...@@ -1416,7 +1416,7 @@ pub const Node = struct {...@@ -1416,7 +1416,7 @@ pub const Node = struct {
1416 };1416 };
14171417
1418 pub const InfixOp = struct {1418 pub const InfixOp = struct {
1419 base: Node = Node {.id = .InfixOp},1419 base: Node = Node{ .id = .InfixOp },
1420 op_token: TokenIndex,1420 op_token: TokenIndex,
1421 lhs: *Node,1421 lhs: *Node,
1422 op: Op,1422 op: Op,
...@@ -1649,7 +1649,7 @@ pub const Node = struct {...@@ -1649,7 +1649,7 @@ pub const Node = struct {
1649 };1649 };
16501650
1651 pub const FieldInitializer = struct {1651 pub const FieldInitializer = struct {
1652 base: Node = Node {.id = .FieldInitializer},1652 base: Node = Node{ .id = .FieldInitializer },
1653 period_token: TokenIndex,1653 period_token: TokenIndex,
1654 name_token: TokenIndex,1654 name_token: TokenIndex,
1655 expr: *Node,1655 expr: *Node,
...@@ -1673,7 +1673,7 @@ pub const Node = struct {...@@ -1673,7 +1673,7 @@ pub const Node = struct {
1673 };1673 };
16741674
1675 pub const SuffixOp = struct {1675 pub const SuffixOp = struct {
1676 base: Node = Node {.id = .SuffixOp},1676 base: Node = Node{ .id = .SuffixOp },
1677 lhs: Lhs,1677 lhs: Lhs,
1678 op: Op,1678 op: Op,
1679 rtoken: TokenIndex,1679 rtoken: TokenIndex,
...@@ -1774,7 +1774,7 @@ pub const Node = struct {...@@ -1774,7 +1774,7 @@ pub const Node = struct {
1774 };1774 };
17751775
1776 pub const GroupedExpression = struct {1776 pub const GroupedExpression = struct {
1777 base: Node = Node {.id = .GroupedExpression},1777 base: Node = Node{ .id = .GroupedExpression },
1778 lparen: TokenIndex,1778 lparen: TokenIndex,
1779 expr: *Node,1779 expr: *Node,
1780 rparen: TokenIndex,1780 rparen: TokenIndex,
...@@ -1798,7 +1798,7 @@ pub const Node = struct {...@@ -1798,7 +1798,7 @@ pub const Node = struct {
1798 };1798 };
17991799
1800 pub const ControlFlowExpression = struct {1800 pub const ControlFlowExpression = struct {
1801 base: Node = Node {.id = .ControlFlowExpression},1801 base: Node = Node{ .id = .ControlFlowExpression },
1802 ltoken: TokenIndex,1802 ltoken: TokenIndex,
1803 kind: Kind,1803 kind: Kind,
1804 rhs: ?*Node,1804 rhs: ?*Node,
...@@ -1864,7 +1864,7 @@ pub const Node = struct {...@@ -1864,7 +1864,7 @@ pub const Node = struct {
1864 };1864 };
18651865
1866 pub const Suspend = struct {1866 pub const Suspend = struct {
1867 base: Node = Node {.id = .Suspend},1867 base: Node = Node{ .id = .Suspend },
1868 suspend_token: TokenIndex,1868 suspend_token: TokenIndex,
1869 body: ?*Node,1869 body: ?*Node,
18701870
...@@ -1893,7 +1893,7 @@ pub const Node = struct {...@@ -1893,7 +1893,7 @@ pub const Node = struct {
1893 };1893 };
18941894
1895 pub const IntegerLiteral = struct {1895 pub const IntegerLiteral = struct {
1896 base: Node = Node {.id = .IntegerLiteral},1896 base: Node = Node{ .id = .IntegerLiteral },
1897 token: TokenIndex,1897 token: TokenIndex,
18981898
1899 pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node {1899 pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node {
...@@ -1910,7 +1910,7 @@ pub const Node = struct {...@@ -1910,7 +1910,7 @@ pub const Node = struct {
1910 };1910 };
19111911
1912 pub const EnumLiteral = struct {1912 pub const EnumLiteral = struct {
1913 base: Node = Node {.id = .EnumLiteral},1913 base: Node = Node{ .id = .EnumLiteral },
1914 dot: TokenIndex,1914 dot: TokenIndex,
1915 name: TokenIndex,1915 name: TokenIndex,
19161916
...@@ -1928,7 +1928,7 @@ pub const Node = struct {...@@ -1928,7 +1928,7 @@ pub const Node = struct {
1928 };1928 };
19291929
1930 pub const FloatLiteral = struct {1930 pub const FloatLiteral = struct {
1931 base: Node = Node {.id = .FloatLiteral},1931 base: Node = Node{ .id = .FloatLiteral },
1932 token: TokenIndex,1932 token: TokenIndex,
19331933
1934 pub fn iterate(self: *FloatLiteral, index: usize) ?*Node {1934 pub fn iterate(self: *FloatLiteral, index: usize) ?*Node {
...@@ -1945,7 +1945,7 @@ pub const Node = struct {...@@ -1945,7 +1945,7 @@ pub const Node = struct {
1945 };1945 };
19461946
1947 pub const BuiltinCall = struct {1947 pub const BuiltinCall = struct {
1948 base: Node = Node {.id = .BuiltinCall},1948 base: Node = Node{ .id = .BuiltinCall },
1949 builtin_token: TokenIndex,1949 builtin_token: TokenIndex,
1950 params: ParamList,1950 params: ParamList,
1951 rparen_token: TokenIndex,1951 rparen_token: TokenIndex,
...@@ -1971,7 +1971,7 @@ pub const Node = struct {...@@ -1971,7 +1971,7 @@ pub const Node = struct {
1971 };1971 };
19721972
1973 pub const StringLiteral = struct {1973 pub const StringLiteral = struct {
1974 base: Node = Node {.id = .StringLiteral},1974 base: Node = Node{ .id = .StringLiteral },
1975 token: TokenIndex,1975 token: TokenIndex,
19761976
1977 pub fn iterate(self: *StringLiteral, index: usize) ?*Node {1977 pub fn iterate(self: *StringLiteral, index: usize) ?*Node {
...@@ -1988,7 +1988,7 @@ pub const Node = struct {...@@ -1988,7 +1988,7 @@ pub const Node = struct {
1988 };1988 };
19891989
1990 pub const MultilineStringLiteral = struct {1990 pub const MultilineStringLiteral = struct {
1991 base: Node = Node {.id = .MultilineStringLiteral},1991 base: Node = Node{ .id = .MultilineStringLiteral },
1992 lines: LineList,1992 lines: LineList,
19931993
1994 pub const LineList = SegmentedList(TokenIndex, 4);1994 pub const LineList = SegmentedList(TokenIndex, 4);
...@@ -2007,7 +2007,7 @@ pub const Node = struct {...@@ -2007,7 +2007,7 @@ pub const Node = struct {
2007 };2007 };
20082008
2009 pub const CharLiteral = struct {2009 pub const CharLiteral = struct {
2010 base: Node = Node {.id = .CharLiteral},2010 base: Node = Node{ .id = .CharLiteral },
2011 token: TokenIndex,2011 token: TokenIndex,
20122012
2013 pub fn iterate(self: *CharLiteral, index: usize) ?*Node {2013 pub fn iterate(self: *CharLiteral, index: usize) ?*Node {
...@@ -2024,7 +2024,7 @@ pub const Node = struct {...@@ -2024,7 +2024,7 @@ pub const Node = struct {
2024 };2024 };
20252025
2026 pub const BoolLiteral = struct {2026 pub const BoolLiteral = struct {
2027 base: Node = Node {.id = .BoolLiteral},2027 base: Node = Node{ .id = .BoolLiteral },
2028 token: TokenIndex,2028 token: TokenIndex,
20292029
2030 pub fn iterate(self: *BoolLiteral, index: usize) ?*Node {2030 pub fn iterate(self: *BoolLiteral, index: usize) ?*Node {
...@@ -2041,7 +2041,7 @@ pub const Node = struct {...@@ -2041,7 +2041,7 @@ pub const Node = struct {
2041 };2041 };
20422042
2043 pub const NullLiteral = struct {2043 pub const NullLiteral = struct {
2044 base: Node = Node {.id = .NullLiteral},2044 base: Node = Node{ .id = .NullLiteral },
2045 token: TokenIndex,2045 token: TokenIndex,
20462046
2047 pub fn iterate(self: *NullLiteral, index: usize) ?*Node {2047 pub fn iterate(self: *NullLiteral, index: usize) ?*Node {
...@@ -2058,7 +2058,7 @@ pub const Node = struct {...@@ -2058,7 +2058,7 @@ pub const Node = struct {
2058 };2058 };
20592059
2060 pub const UndefinedLiteral = struct {2060 pub const UndefinedLiteral = struct {
2061 base: Node = Node {.id = .UndefinedLiteral},2061 base: Node = Node{ .id = .UndefinedLiteral },
2062 token: TokenIndex,2062 token: TokenIndex,
20632063
2064 pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node {2064 pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node {
...@@ -2075,7 +2075,7 @@ pub const Node = struct {...@@ -2075,7 +2075,7 @@ pub const Node = struct {
2075 };2075 };
20762076
2077 pub const AsmOutput = struct {2077 pub const AsmOutput = struct {
2078 base: Node = Node {.id = .AsmOutput},2078 base: Node = Node{ .id = .AsmOutput },
2079 lbracket: TokenIndex,2079 lbracket: TokenIndex,
2080 symbolic_name: *Node,2080 symbolic_name: *Node,
2081 constraint: *Node,2081 constraint: *Node,
...@@ -2120,7 +2120,7 @@ pub const Node = struct {...@@ -2120,7 +2120,7 @@ pub const Node = struct {
2120 };2120 };
21212121
2122 pub const AsmInput = struct {2122 pub const AsmInput = struct {
2123 base: Node = Node {.id = .AsmInput},2123 base: Node = Node{ .id = .AsmInput },
2124 lbracket: TokenIndex,2124 lbracket: TokenIndex,
2125 symbolic_name: *Node,2125 symbolic_name: *Node,
2126 constraint: *Node,2126 constraint: *Node,
...@@ -2152,7 +2152,7 @@ pub const Node = struct {...@@ -2152,7 +2152,7 @@ pub const Node = struct {
2152 };2152 };
21532153
2154 pub const Asm = struct {2154 pub const Asm = struct {
2155 base: Node = Node {.id = .Asm},2155 base: Node = Node{ .id = .Asm },
2156 asm_token: TokenIndex,2156 asm_token: TokenIndex,
2157 volatile_token: ?TokenIndex,2157 volatile_token: ?TokenIndex,
2158 template: *Node,2158 template: *Node,
...@@ -2187,7 +2187,7 @@ pub const Node = struct {...@@ -2187,7 +2187,7 @@ pub const Node = struct {
2187 };2187 };
21882188
2189 pub const Unreachable = struct {2189 pub const Unreachable = struct {
2190 base: Node = Node {.id = .Unreachable},2190 base: Node = Node{ .id = .Unreachable },
2191 token: TokenIndex,2191 token: TokenIndex,
21922192
2193 pub fn iterate(self: *Unreachable, index: usize) ?*Node {2193 pub fn iterate(self: *Unreachable, index: usize) ?*Node {
...@@ -2204,7 +2204,7 @@ pub const Node = struct {...@@ -2204,7 +2204,7 @@ pub const Node = struct {
2204 };2204 };
22052205
2206 pub const ErrorType = struct {2206 pub const ErrorType = struct {
2207 base: Node = Node {.id = .ErrorType},2207 base: Node = Node{ .id = .ErrorType },
2208 token: TokenIndex,2208 token: TokenIndex,
22092209
2210 pub fn iterate(self: *ErrorType, index: usize) ?*Node {2210 pub fn iterate(self: *ErrorType, index: usize) ?*Node {
...@@ -2238,7 +2238,7 @@ pub const Node = struct {...@@ -2238,7 +2238,7 @@ pub const Node = struct {
2238 };2238 };
22392239
2240 pub const DocComment = struct {2240 pub const DocComment = struct {
2241 base: Node = Node {.id = .DocComment},2241 base: Node = Node{ .id = .DocComment },
2242 lines: LineList,2242 lines: LineList,
22432243
2244 pub const LineList = SegmentedList(TokenIndex, 4);2244 pub const LineList = SegmentedList(TokenIndex, 4);
...@@ -2257,7 +2257,7 @@ pub const Node = struct {...@@ -2257,7 +2257,7 @@ pub const Node = struct {
2257 };2257 };
22582258
2259 pub const TestDecl = struct {2259 pub const TestDecl = struct {
2260 base: Node = Node {.id = .TestDecl},2260 base: Node = Node{ .id = .TestDecl },
2261 doc_comments: ?*DocComment,2261 doc_comments: ?*DocComment,
2262 test_token: TokenIndex,2262 test_token: TokenIndex,
2263 name: *Node,2263 name: *Node,
src-self-hosted/translate_c.zig+19-27
...@@ -1194,7 +1194,7 @@ fn transImplicitCastExpr(...@@ -1194,7 +1194,7 @@ fn transImplicitCastExpr(
1194 const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr));1194 const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr));
1195 const src_type = getExprQualType(c, sub_expr);1195 const src_type = getExprQualType(c, sub_expr);
1196 switch (ZigClangImplicitCastExpr_getCastKind(expr)) {1196 switch (ZigClangImplicitCastExpr_getCastKind(expr)) {
1197 .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast => {1197 .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => {
1198 return transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, sub_expr_node);1198 return transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, sub_expr_node);
1199 },1199 },
1200 .LValueToRValue, .NoOp, .FunctionToPointerDecay, .ArrayToPointerDecay => {1200 .LValueToRValue, .NoOp, .FunctionToPointerDecay, .ArrayToPointerDecay => {
...@@ -1221,29 +1221,6 @@ fn transImplicitCastExpr(...@@ -1221,29 +1221,6 @@ fn transImplicitCastExpr(
1221 const rhs_node = try transCreateNodeInt(rp.c, 0);1221 const rhs_node = try transCreateNodeInt(rp.c, 0);
1222 return transCreateNodeInfixOp(rp, scope, node, .BangEqual, op_token, rhs_node, result_used, false);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 else => |kind| return revertAndWarn(1224 else => |kind| return revertAndWarn(
1248 rp,1225 rp,
1249 error.UnsupportedTranslation,1226 error.UnsupportedTranslation,
...@@ -1509,8 +1486,18 @@ fn transCCast(...@@ -1509,8 +1486,18 @@ fn transCCast(
1509 if (ZigClangQualType_eq(dst_type, src_type)) return expr;1486 if (ZigClangQualType_eq(dst_type, src_type)) return expr;
1510 if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type))1487 if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type))
1511 return transCPtrCast(rp, loc, dst_type, src_type, expr);1488 return transCPtrCast(rp, loc, dst_type, src_type, expr);
1512 if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) {1489 if (cIsInteger(dst_type) and cIsInteger(src_type)) {
1513 const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");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 try cast_node.params.push(try transQualType(rp, dst_type, loc));1501 try cast_node.params.push(try transQualType(rp, dst_type, loc));
1515 _ = try appendToken(rp.c, .Comma, ",");1502 _ = try appendToken(rp.c, .Comma, ",");
1516 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt");1503 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt");
...@@ -1520,7 +1507,8 @@ fn transCCast(...@@ -1520,7 +1507,8 @@ fn transCCast(
1520 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");1507 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
1521 return &cast_node.base;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 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@intToPtr");1512 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@intToPtr");
1525 try builtin_node.params.push(try transQualType(rp, dst_type, loc));1513 try builtin_node.params.push(try transQualType(rp, dst_type, loc));
1526 _ = try appendToken(rp.c, .Comma, ",");1514 _ = try appendToken(rp.c, .Comma, ",");
...@@ -2870,6 +2858,10 @@ fn typeIsOpaque(c: *Context, ty: *const ZigClangType, loc: ZigClangSourceLocatio...@@ -2870,6 +2858,10 @@ fn typeIsOpaque(c: *Context, ty: *const ZigClangType, loc: ZigClangSourceLocatio
2870 }2858 }
2871}2859}
28722860
2861fn cIsInteger(qt: ZigClangQualType) bool {
2862 return cIsSignedInteger(qt) or cIsUnsignedInteger(qt);
2863}
2864
2873fn cIsUnsignedInteger(qt: ZigClangQualType) bool {2865fn cIsUnsignedInteger(qt: ZigClangQualType) bool {
2874 const c_type = qualTypeCanon(qt);2866 const c_type = qualTypeCanon(qt);
2875 if (ZigClangType_getTypeClass(c_type) != .Builtin) return false;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,9 +21,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21 , &[_][]const u8{21 , &[_][]const u8{
22 \\pub export fn foo() void {22 \\pub export fn foo() void {
23 \\ var a: c_int = undefined;23 \\ var a: c_int = undefined;
24 \\ var b: u8 = @as(u8, 123);24 \\ var b: u8 = @intCast(u8, 123);
25 \\ const c: c_int = undefined;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 });
2929
...@@ -110,7 +110,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -110,7 +110,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
110 \\pub extern fn foo() void;110 \\pub extern fn foo() void;
111 \\pub export fn bar() void {111 \\pub export fn bar() void {
112 \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);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 });
116116
...@@ -855,7 +855,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -855,7 +855,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
855 , &[_][]const u8{855 , &[_][]const u8{
856 \\pub fn foo() void {856 \\pub fn foo() void {
857 \\ var arr: [10]u8 = .{857 \\ var arr: [10]u8 = .{
858 \\ @as(u8, 1),858 \\ @intCast(u8, 1),
859 \\ } ++ .{0} ** 9;859 \\ } ++ .{0} ** 9;
860 \\ var arr1: [10][*c]u8 = .{860 \\ var arr1: [10][*c]u8 = .{
861 \\ null,861 \\ null,
...@@ -1082,18 +1082,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1082,18 +1082,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1082 \\ unsigned d = 440;1082 \\ unsigned d = 440;
1083 \\}1083 \\}
1084 , &[_][]const u8{1084 , &[_][]const u8{
1085 \\pub var a: c_long = @as(c_long, 2);1085 \\pub var a: c_long = @intCast(c_long, 2);
1086 \\pub var b: c_long = @as(c_long, 2);1086 \\pub var b: c_long = @intCast(c_long, 2);
1087 \\pub var c: c_int = 4;1087 \\pub var c: c_int = 4;
1088 \\pub export fn foo(_arg_c_1: u8) void {1088 \\pub export fn foo(_arg_c_1: u8) void {
1089 \\ var c_1 = _arg_c_1;1089 \\ var c_1 = _arg_c_1;
1090 \\ var a_2: c_int = undefined;1090 \\ var a_2: c_int = undefined;
1091 \\ var b_3: u8 = @as(u8, 123);1091 \\ var b_3: u8 = @intCast(u8, 123);
1092 \\ b_3 = @as(u8, a_2);1092 \\ b_3 = @intCast(u8, a_2);
1093 \\ {1093 \\ {
1094 \\ var d: c_int = 5;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 });
10991099
...@@ -1216,14 +1216,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1216,14 +1216,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1216 \\ _ = 7;1216 \\ _ = 7;
1217 \\ }1217 \\ }
1218 \\ }1218 \\ }
1219 \\ var i: u8 = @as(u8, 2);1219 \\ var i: u8 = @intCast(u8, 2);
1220 \\}1220 \\}
1221 });1221 });
12221222
1223 cases.add("shadowing primitive types",1223 cases.add("shadowing primitive types",
1224 \\unsigned anyerror = 2;1224 \\unsigned anyerror = 2;
1225 , &[_][]const u8{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 });
12281228
1229 cases.add("floats",1229 cases.add("floats",
...@@ -1397,17 +1397,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1397,17 +1397,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1397 \\1397 \\
1398 , &[_][]const u8{1398 , &[_][]const u8{
1399 \\pub export fn escapes() [*c]const u8 {1399 \\pub export fn escapes() [*c]const u8 {
1400 \\ var a: u8 = @as(u8, '\'');1400 \\ var a: u8 = @intCast(u8, '\'');
1401 \\ var b: u8 = @as(u8, '\\');1401 \\ var b: u8 = @intCast(u8, '\\');
1402 \\ var c: u8 = @as(u8, '\x07');1402 \\ var c: u8 = @intCast(u8, '\x07');
1403 \\ var d: u8 = @as(u8, '\x08');1403 \\ var d: u8 = @intCast(u8, '\x08');
1404 \\ var e: u8 = @as(u8, '\x0c');1404 \\ var e: u8 = @intCast(u8, '\x0c');
1405 \\ var f: u8 = @as(u8, '\n');1405 \\ var f: u8 = @intCast(u8, '\n');
1406 \\ var g: u8 = @as(u8, '\r');1406 \\ var g: u8 = @intCast(u8, '\r');
1407 \\ var h: u8 = @as(u8, '\t');1407 \\ var h: u8 = @intCast(u8, '\t');
1408 \\ var i: u8 = @as(u8, '\x0b');1408 \\ var i: u8 = @intCast(u8, '\x0b');
1409 \\ var j: u8 = @as(u8, '\x00');1409 \\ var j: u8 = @intCast(u8, '\x00');
1410 \\ var k: u8 = @as(u8, '\"');1410 \\ var k: u8 = @intCast(u8, '\"');
1411 \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";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,7 +1818,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1818 , &[_][]const u8{1818 , &[_][]const u8{
1819 \\pub export fn foo() void {1819 \\pub export fn foo() void {
1820 \\ var i: c_int = 0;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 \\ i += 1;1822 \\ i += 1;
1823 \\ i -= 1;1823 \\ i -= 1;
1824 \\ u +%= 1;1824 \\ u +%= 1;
...@@ -1858,7 +1858,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1858,7 +1858,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1858 \\pub export fn log2(_arg_a: c_uint) c_int {1858 \\pub export fn log2(_arg_a: c_uint) c_int {
1859 \\ var a = _arg_a;1859 \\ var a = _arg_a;
1860 \\ var i: c_int = 0;1860 \\ var i: c_int = 0;
1861 \\ while (a > @as(c_uint, 0)) {1861 \\ while (a > @intCast(c_uint, 0)) {
1862 \\ a >>= @as(@import("std").math.Log2Int(c_int), 1);1862 \\ a >>= @as(@import("std").math.Log2Int(c_int), 1);
1863 \\ }1863 \\ }
1864 \\ return i;1864 \\ return i;
...@@ -1878,7 +1878,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1878,7 +1878,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1878 \\pub export fn log2(_arg_a: u32) c_int {1878 \\pub export fn log2(_arg_a: u32) c_int {
1879 \\ var a = _arg_a;1879 \\ var a = _arg_a;
1880 \\ var i: c_int = 0;1880 \\ var i: c_int = 0;
1881 \\ while (a > @as(c_uint, 0)) {1881 \\ while (a > @intCast(c_uint, 0)) {
1882 \\ a >>= @as(@import("std").math.Log2Int(c_int), 1);1882 \\ a >>= @as(@import("std").math.Log2Int(c_int), 1);
1883 \\ }1883 \\ }
1884 \\ return i;1884 \\ return i;
...@@ -1957,35 +1957,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1957,35 +1957,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1957 \\}1957 \\}
1958 , &[_][]const u8{1958 , &[_][]const u8{
1959 \\pub export fn foo() void {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 \\ a +%= (blk: {1961 \\ a +%= (blk: {
1962 \\ const _ref_1 = &a;1962 \\ const _ref_1 = &a;
1963 \\ _ref_1.* = _ref_1.* +% @as(c_uint, 1);1963 \\ _ref_1.* = _ref_1.* +% @intCast(c_uint, 1);
1964 \\ break :blk _ref_1.*;1964 \\ break :blk _ref_1.*;
1965 \\ });1965 \\ });
1966 \\ a -%= (blk: {1966 \\ a -%= (blk: {
1967 \\ const _ref_2 = &a;1967 \\ const _ref_2 = &a;
1968 \\ _ref_2.* = _ref_2.* -% @as(c_uint, 1);1968 \\ _ref_2.* = _ref_2.* -% @intCast(c_uint, 1);
1969 \\ break :blk _ref_2.*;1969 \\ break :blk _ref_2.*;
1970 \\ });1970 \\ });
1971 \\ a *%= (blk: {1971 \\ a *%= (blk: {
1972 \\ const _ref_3 = &a;1972 \\ const _ref_3 = &a;
1973 \\ _ref_3.* = _ref_3.* *% @as(c_uint, 1);1973 \\ _ref_3.* = _ref_3.* *% @intCast(c_uint, 1);
1974 \\ break :blk _ref_3.*;1974 \\ break :blk _ref_3.*;
1975 \\ });1975 \\ });
1976 \\ a &= (blk: {1976 \\ a &= (blk: {
1977 \\ const _ref_4 = &a;1977 \\ const _ref_4 = &a;
1978 \\ _ref_4.* = _ref_4.* & @as(c_uint, 1);1978 \\ _ref_4.* = _ref_4.* & @intCast(c_uint, 1);
1979 \\ break :blk _ref_4.*;1979 \\ break :blk _ref_4.*;
1980 \\ });1980 \\ });
1981 \\ a |= (blk: {1981 \\ a |= (blk: {
1982 \\ const _ref_5 = &a;1982 \\ const _ref_5 = &a;
1983 \\ _ref_5.* = _ref_5.* | @as(c_uint, 1);1983 \\ _ref_5.* = _ref_5.* | @intCast(c_uint, 1);
1984 \\ break :blk _ref_5.*;1984 \\ break :blk _ref_5.*;
1985 \\ });1985 \\ });
1986 \\ a ^= (blk: {1986 \\ a ^= (blk: {
1987 \\ const _ref_6 = &a;1987 \\ const _ref_6 = &a;
1988 \\ _ref_6.* = _ref_6.* ^ @as(c_uint, 1);1988 \\ _ref_6.* = _ref_6.* ^ @intCast(c_uint, 1);
1989 \\ break :blk _ref_6.*;1989 \\ break :blk _ref_6.*;
1990 \\ });1990 \\ });
1991 \\ a >>= @as(@import("std").math.Log2Int(c_uint), (blk: {1991 \\ a >>= @as(@import("std").math.Log2Int(c_uint), (blk: {
...@@ -2017,7 +2017,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2017,7 +2017,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2017 , &[_][]const u8{2017 , &[_][]const u8{
2018 \\pub export fn foo() void {2018 \\pub export fn foo() void {
2019 \\ var i: c_int = 0;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 \\ i += 1;2021 \\ i += 1;
2022 \\ i -= 1;2022 \\ i -= 1;
2023 \\ u +%= 1;2023 \\ u +%= 1;
...@@ -2092,9 +2092,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2092,9 +2092,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2092 \\ fn_int(1094861636);2092 \\ fn_int(1094861636);
2093 \\ fn_f32(@intToFloat(f32, 3));2093 \\ fn_f32(@intToFloat(f32, 3));
2094 \\ fn_f64(@intToFloat(f64, 3));2094 \\ fn_f64(@intToFloat(f64, 3));
2095 \\ fn_char(@as(u8, '3'));2095 \\ fn_char(@intCast(u8, '3'));
2096 \\ fn_char(@as(u8, '\x01'));2096 \\ fn_char(@intCast(u8, '\x01'));
2097 \\ fn_char(@as(u8, 0));2097 \\ fn_char(@intCast(u8, 0));
2098 \\ fn_f32(3);2098 \\ fn_f32(3);
2099 \\ fn_f64(3);2099 \\ fn_f64(3);
2100 \\ fn_bool(123 != 0);2100 \\ fn_bool(123 != 0);