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 {
584584 }
585585
586586 pub const Root = struct {
587 base: Node = Node {.id = .Root},
587 base: Node = Node{ .id = .Root },
588588 decls: DeclList,
589589 eof_token: TokenIndex,
590590
......@@ -607,7 +607,7 @@ pub const Node = struct {
607607 };
608608
609609 pub const VarDecl = struct {
610 base: Node = Node {.id = .VarDecl},
610 base: Node = Node{ .id = .VarDecl },
611611 doc_comments: ?*DocComment,
612612 visib_token: ?TokenIndex,
613613 thread_local_token: ?TokenIndex,
......@@ -664,7 +664,7 @@ pub const Node = struct {
664664 };
665665
666666 pub const Use = struct {
667 base: Node = Node {.id = .Use},
667 base: Node = Node{ .id = .Use },
668668 doc_comments: ?*DocComment,
669669 visib_token: ?TokenIndex,
670670 use_token: TokenIndex,
......@@ -691,7 +691,7 @@ pub const Node = struct {
691691 };
692692
693693 pub const ErrorSetDecl = struct {
694 base: Node = Node {.id = .ErrorSetDecl},
694 base: Node = Node{ .id = .ErrorSetDecl },
695695 error_token: TokenIndex,
696696 decls: DeclList,
697697 rbrace_token: TokenIndex,
......@@ -717,7 +717,7 @@ pub const Node = struct {
717717 };
718718
719719 pub const ContainerDecl = struct {
720 base: Node = Node {.id = .ContainerDecl},
720 base: Node = Node{ .id = .ContainerDecl },
721721 layout_token: ?TokenIndex,
722722 kind_token: TokenIndex,
723723 init_arg_expr: InitArg,
......@@ -804,7 +804,7 @@ pub const Node = struct {
804804 };
805805
806806 pub const ErrorTag = struct {
807 base: Node = Node {.id = .ErrorTag},
807 base: Node = Node{ .id = .ErrorTag },
808808 doc_comments: ?*DocComment,
809809 name_token: TokenIndex,
810810
......@@ -829,7 +829,7 @@ pub const Node = struct {
829829 };
830830
831831 pub const Identifier = struct {
832 base: Node = Node {.id = .Identifier},
832 base: Node = Node{ .id = .Identifier },
833833 token: TokenIndex,
834834
835835 pub fn iterate(self: *Identifier, index: usize) ?*Node {
......@@ -846,7 +846,7 @@ pub const Node = struct {
846846 };
847847
848848 pub const FnProto = struct {
849 base: Node = Node {.id = .FnProto},
849 base: Node = Node{ .id = .FnProto },
850850 doc_comments: ?*DocComment,
851851 visib_token: ?TokenIndex,
852852 fn_token: TokenIndex,
......@@ -928,7 +928,7 @@ pub const Node = struct {
928928 };
929929
930930 pub const AnyFrameType = struct {
931 base: Node = Node {.id = .AnyFrameType},
931 base: Node = Node{ .id = .AnyFrameType },
932932 anyframe_token: TokenIndex,
933933 result: ?Result,
934934
......@@ -959,7 +959,7 @@ pub const Node = struct {
959959 };
960960
961961 pub const ParamDecl = struct {
962 base: Node = Node {.id = .ParamDecl},
962 base: Node = Node{ .id = .ParamDecl },
963963 doc_comments: ?*DocComment,
964964 comptime_token: ?TokenIndex,
965965 noalias_token: ?TokenIndex,
......@@ -992,7 +992,7 @@ pub const Node = struct {
992992 };
993993
994994 pub const Block = struct {
995 base: Node = Node {.id = .Block},
995 base: Node = Node{ .id = .Block },
996996 label: ?TokenIndex,
997997 lbrace: TokenIndex,
998998 statements: StatementList,
......@@ -1023,7 +1023,7 @@ pub const Node = struct {
10231023 };
10241024
10251025 pub const Defer = struct {
1026 base: Node = Node {.id = .Defer},
1026 base: Node = Node{ .id = .Defer },
10271027 defer_token: TokenIndex,
10281028 expr: *Node,
10291029
......@@ -1046,7 +1046,7 @@ pub const Node = struct {
10461046 };
10471047
10481048 pub const Comptime = struct {
1049 base: Node = Node {.id = .Comptime},
1049 base: Node = Node{ .id = .Comptime },
10501050 doc_comments: ?*DocComment,
10511051 comptime_token: TokenIndex,
10521052 expr: *Node,
......@@ -1070,7 +1070,7 @@ pub const Node = struct {
10701070 };
10711071
10721072 pub const Payload = struct {
1073 base: Node = Node {.id = .Payload},
1073 base: Node = Node{ .id = .Payload },
10741074 lpipe: TokenIndex,
10751075 error_symbol: *Node,
10761076 rpipe: TokenIndex,
......@@ -1094,7 +1094,7 @@ pub const Node = struct {
10941094 };
10951095
10961096 pub const PointerPayload = struct {
1097 base: Node = Node {.id = .PointerPayload},
1097 base: Node = Node{ .id = .PointerPayload },
10981098 lpipe: TokenIndex,
10991099 ptr_token: ?TokenIndex,
11001100 value_symbol: *Node,
......@@ -1119,7 +1119,7 @@ pub const Node = struct {
11191119 };
11201120
11211121 pub const PointerIndexPayload = struct {
1122 base: Node = Node {.id = .PointerIndexPayload},
1122 base: Node = Node{ .id = .PointerIndexPayload },
11231123 lpipe: TokenIndex,
11241124 ptr_token: ?TokenIndex,
11251125 value_symbol: *Node,
......@@ -1150,7 +1150,7 @@ pub const Node = struct {
11501150 };
11511151
11521152 pub const Else = struct {
1153 base: Node = Node {.id = .Else},
1153 base: Node = Node{ .id = .Else },
11541154 else_token: TokenIndex,
11551155 payload: ?*Node,
11561156 body: *Node,
......@@ -1179,7 +1179,7 @@ pub const Node = struct {
11791179 };
11801180
11811181 pub const Switch = struct {
1182 base: Node = Node {.id = .Switch},
1182 base: Node = Node{ .id = .Switch },
11831183 switch_token: TokenIndex,
11841184 expr: *Node,
11851185
......@@ -1211,7 +1211,7 @@ pub const Node = struct {
12111211 };
12121212
12131213 pub const SwitchCase = struct {
1214 base: Node = Node {.id = .SwitchCase},
1214 base: Node = Node{ .id = .SwitchCase },
12151215 items: ItemList,
12161216 arrow_token: TokenIndex,
12171217 payload: ?*Node,
......@@ -1246,7 +1246,7 @@ pub const Node = struct {
12461246 };
12471247
12481248 pub const SwitchElse = struct {
1249 base: Node = Node {.id = .SwitchElse},
1249 base: Node = Node{ .id = .SwitchElse },
12501250 token: TokenIndex,
12511251
12521252 pub fn iterate(self: *SwitchElse, index: usize) ?*Node {
......@@ -1263,7 +1263,7 @@ pub const Node = struct {
12631263 };
12641264
12651265 pub const While = struct {
1266 base: Node = Node {.id = .While},
1266 base: Node = Node{ .id = .While },
12671267 label: ?TokenIndex,
12681268 inline_token: ?TokenIndex,
12691269 while_token: TokenIndex,
......@@ -1322,7 +1322,7 @@ pub const Node = struct {
13221322 };
13231323
13241324 pub const For = struct {
1325 base: Node = Node {.id = .For},
1325 base: Node = Node{ .id = .For },
13261326 label: ?TokenIndex,
13271327 inline_token: ?TokenIndex,
13281328 for_token: TokenIndex,
......@@ -1373,7 +1373,7 @@ pub const Node = struct {
13731373 };
13741374
13751375 pub const If = struct {
1376 base: Node = Node {.id = .If},
1376 base: Node = Node{ .id = .If },
13771377 if_token: TokenIndex,
13781378 condition: *Node,
13791379 payload: ?*Node,
......@@ -1416,7 +1416,7 @@ pub const Node = struct {
14161416 };
14171417
14181418 pub const InfixOp = struct {
1419 base: Node = Node {.id = .InfixOp},
1419 base: Node = Node{ .id = .InfixOp },
14201420 op_token: TokenIndex,
14211421 lhs: *Node,
14221422 op: Op,
......@@ -1649,7 +1649,7 @@ pub const Node = struct {
16491649 };
16501650
16511651 pub const FieldInitializer = struct {
1652 base: Node = Node {.id = .FieldInitializer},
1652 base: Node = Node{ .id = .FieldInitializer },
16531653 period_token: TokenIndex,
16541654 name_token: TokenIndex,
16551655 expr: *Node,
......@@ -1673,7 +1673,7 @@ pub const Node = struct {
16731673 };
16741674
16751675 pub const SuffixOp = struct {
1676 base: Node = Node {.id = .SuffixOp},
1676 base: Node = Node{ .id = .SuffixOp },
16771677 lhs: Lhs,
16781678 op: Op,
16791679 rtoken: TokenIndex,
......@@ -1774,7 +1774,7 @@ pub const Node = struct {
17741774 };
17751775
17761776 pub const GroupedExpression = struct {
1777 base: Node = Node {.id = .GroupedExpression},
1777 base: Node = Node{ .id = .GroupedExpression },
17781778 lparen: TokenIndex,
17791779 expr: *Node,
17801780 rparen: TokenIndex,
......@@ -1798,7 +1798,7 @@ pub const Node = struct {
17981798 };
17991799
18001800 pub const ControlFlowExpression = struct {
1801 base: Node = Node {.id = .ControlFlowExpression},
1801 base: Node = Node{ .id = .ControlFlowExpression },
18021802 ltoken: TokenIndex,
18031803 kind: Kind,
18041804 rhs: ?*Node,
......@@ -1864,7 +1864,7 @@ pub const Node = struct {
18641864 };
18651865
18661866 pub const Suspend = struct {
1867 base: Node = Node {.id = .Suspend},
1867 base: Node = Node{ .id = .Suspend },
18681868 suspend_token: TokenIndex,
18691869 body: ?*Node,
18701870
......@@ -1893,7 +1893,7 @@ pub const Node = struct {
18931893 };
18941894
18951895 pub const IntegerLiteral = struct {
1896 base: Node = Node {.id = .IntegerLiteral},
1896 base: Node = Node{ .id = .IntegerLiteral },
18971897 token: TokenIndex,
18981898
18991899 pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node {
......@@ -1910,7 +1910,7 @@ pub const Node = struct {
19101910 };
19111911
19121912 pub const EnumLiteral = struct {
1913 base: Node = Node {.id = .EnumLiteral},
1913 base: Node = Node{ .id = .EnumLiteral },
19141914 dot: TokenIndex,
19151915 name: TokenIndex,
19161916
......@@ -1928,7 +1928,7 @@ pub const Node = struct {
19281928 };
19291929
19301930 pub const FloatLiteral = struct {
1931 base: Node = Node {.id = .FloatLiteral},
1931 base: Node = Node{ .id = .FloatLiteral },
19321932 token: TokenIndex,
19331933
19341934 pub fn iterate(self: *FloatLiteral, index: usize) ?*Node {
......@@ -1945,7 +1945,7 @@ pub const Node = struct {
19451945 };
19461946
19471947 pub const BuiltinCall = struct {
1948 base: Node = Node {.id = .BuiltinCall},
1948 base: Node = Node{ .id = .BuiltinCall },
19491949 builtin_token: TokenIndex,
19501950 params: ParamList,
19511951 rparen_token: TokenIndex,
......@@ -1971,7 +1971,7 @@ pub const Node = struct {
19711971 };
19721972
19731973 pub const StringLiteral = struct {
1974 base: Node = Node {.id = .StringLiteral},
1974 base: Node = Node{ .id = .StringLiteral },
19751975 token: TokenIndex,
19761976
19771977 pub fn iterate(self: *StringLiteral, index: usize) ?*Node {
......@@ -1988,7 +1988,7 @@ pub const Node = struct {
19881988 };
19891989
19901990 pub const MultilineStringLiteral = struct {
1991 base: Node = Node {.id = .MultilineStringLiteral},
1991 base: Node = Node{ .id = .MultilineStringLiteral },
19921992 lines: LineList,
19931993
19941994 pub const LineList = SegmentedList(TokenIndex, 4);
......@@ -2007,7 +2007,7 @@ pub const Node = struct {
20072007 };
20082008
20092009 pub const CharLiteral = struct {
2010 base: Node = Node {.id = .CharLiteral},
2010 base: Node = Node{ .id = .CharLiteral },
20112011 token: TokenIndex,
20122012
20132013 pub fn iterate(self: *CharLiteral, index: usize) ?*Node {
......@@ -2024,7 +2024,7 @@ pub const Node = struct {
20242024 };
20252025
20262026 pub const BoolLiteral = struct {
2027 base: Node = Node {.id = .BoolLiteral},
2027 base: Node = Node{ .id = .BoolLiteral },
20282028 token: TokenIndex,
20292029
20302030 pub fn iterate(self: *BoolLiteral, index: usize) ?*Node {
......@@ -2041,7 +2041,7 @@ pub const Node = struct {
20412041 };
20422042
20432043 pub const NullLiteral = struct {
2044 base: Node = Node {.id = .NullLiteral},
2044 base: Node = Node{ .id = .NullLiteral },
20452045 token: TokenIndex,
20462046
20472047 pub fn iterate(self: *NullLiteral, index: usize) ?*Node {
......@@ -2058,7 +2058,7 @@ pub const Node = struct {
20582058 };
20592059
20602060 pub const UndefinedLiteral = struct {
2061 base: Node = Node {.id = .UndefinedLiteral},
2061 base: Node = Node{ .id = .UndefinedLiteral },
20622062 token: TokenIndex,
20632063
20642064 pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node {
......@@ -2075,7 +2075,7 @@ pub const Node = struct {
20752075 };
20762076
20772077 pub const AsmOutput = struct {
2078 base: Node = Node {.id = .AsmOutput},
2078 base: Node = Node{ .id = .AsmOutput },
20792079 lbracket: TokenIndex,
20802080 symbolic_name: *Node,
20812081 constraint: *Node,
......@@ -2120,7 +2120,7 @@ pub const Node = struct {
21202120 };
21212121
21222122 pub const AsmInput = struct {
2123 base: Node = Node {.id = .AsmInput},
2123 base: Node = Node{ .id = .AsmInput },
21242124 lbracket: TokenIndex,
21252125 symbolic_name: *Node,
21262126 constraint: *Node,
......@@ -2152,7 +2152,7 @@ pub const Node = struct {
21522152 };
21532153
21542154 pub const Asm = struct {
2155 base: Node = Node {.id = .Asm},
2155 base: Node = Node{ .id = .Asm },
21562156 asm_token: TokenIndex,
21572157 volatile_token: ?TokenIndex,
21582158 template: *Node,
......@@ -2187,7 +2187,7 @@ pub const Node = struct {
21872187 };
21882188
21892189 pub const Unreachable = struct {
2190 base: Node = Node {.id = .Unreachable},
2190 base: Node = Node{ .id = .Unreachable },
21912191 token: TokenIndex,
21922192
21932193 pub fn iterate(self: *Unreachable, index: usize) ?*Node {
......@@ -2204,7 +2204,7 @@ pub const Node = struct {
22042204 };
22052205
22062206 pub const ErrorType = struct {
2207 base: Node = Node {.id = .ErrorType},
2207 base: Node = Node{ .id = .ErrorType },
22082208 token: TokenIndex,
22092209
22102210 pub fn iterate(self: *ErrorType, index: usize) ?*Node {
......@@ -2238,7 +2238,7 @@ pub const Node = struct {
22382238 };
22392239
22402240 pub const DocComment = struct {
2241 base: Node = Node {.id = .DocComment},
2241 base: Node = Node{ .id = .DocComment },
22422242 lines: LineList,
22432243
22442244 pub const LineList = SegmentedList(TokenIndex, 4);
......@@ -2257,7 +2257,7 @@ pub const Node = struct {
22572257 };
22582258
22592259 pub const TestDecl = struct {
2260 base: Node = Node {.id = .TestDecl},
2260 base: Node = Node{ .id = .TestDecl },
22612261 doc_comments: ?*DocComment,
22622262 test_token: TokenIndex,
22632263 name: *Node,
src-self-hosted/translate_c.zig+19-27
......@@ -1194,7 +1194,7 @@ fn transImplicitCastExpr(
11941194 const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr));
11951195 const src_type = getExprQualType(c, sub_expr);
11961196 switch (ZigClangImplicitCastExpr_getCastKind(expr)) {
1197 .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast => {
1197 .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => {
11981198 return transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, sub_expr_node);
11991199 },
12001200 .LValueToRValue, .NoOp, .FunctionToPointerDecay, .ArrayToPointerDecay => {
......@@ -1221,29 +1221,6 @@ fn transImplicitCastExpr(
12211221 const rhs_node = try transCreateNodeInt(rp.c, 0);
12221222 return transCreateNodeInfixOp(rp, scope, node, .BangEqual, op_token, rhs_node, result_used, false);
12231223 },
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 },
12471224 else => |kind| return revertAndWarn(
12481225 rp,
12491226 error.UnsupportedTranslation,
......@@ -1509,8 +1486,18 @@ fn transCCast(
15091486 if (ZigClangQualType_eq(dst_type, src_type)) return expr;
15101487 if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type))
15111488 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");
15141501 try cast_node.params.push(try transQualType(rp, dst_type, loc));
15151502 _ = try appendToken(rp.c, .Comma, ",");
15161503 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt");
......@@ -1520,7 +1507,8 @@ fn transCCast(
15201507 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
15211508 return &cast_node.base;
15221509 }
1523 if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) {
1510 if (cIsInteger(src_type) and qualTypeIsPtr(dst_type)) {
1511 // @intToPtr(dest_type, val)
15241512 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@intToPtr");
15251513 try builtin_node.params.push(try transQualType(rp, dst_type, loc));
15261514 _ = try appendToken(rp.c, .Comma, ",");
......@@ -2870,6 +2858,10 @@ fn typeIsOpaque(c: *Context, ty: *const ZigClangType, loc: ZigClangSourceLocatio
28702858 }
28712859}
28722860
2861fn cIsInteger(qt: ZigClangQualType) bool {
2862 return cIsSignedInteger(qt) or cIsUnsignedInteger(qt);
2863}
2864
28732865fn cIsUnsignedInteger(qt: ZigClangQualType) bool {
28742866 const c_type = qualTypeCanon(qt);
28752867 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 {
2121 , &[_][]const u8{
2222 \\pub export fn foo() void {
2323 \\ var a: c_int = undefined;
24 \\ var b: u8 = @as(u8, 123);
24 \\ var b: u8 = @intCast(u8, 123);
2525 \\ const c: c_int = undefined;
26 \\ const d: c_uint = @as(c_uint, 440);
26 \\ const d: c_uint = @intCast(c_uint, 440);
2727 \\}
2828 });
2929
......@@ -110,7 +110,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
110110 \\pub extern fn foo() void;
111111 \\pub export fn bar() void {
112112 \\ 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)));
114114 \\}
115115 });
116116
......@@ -855,7 +855,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
855855 , &[_][]const u8{
856856 \\pub fn foo() void {
857857 \\ var arr: [10]u8 = .{
858 \\ @as(u8, 1),
858 \\ @intCast(u8, 1),
859859 \\ } ++ .{0} ** 9;
860860 \\ var arr1: [10][*c]u8 = .{
861861 \\ null,
......@@ -1082,18 +1082,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10821082 \\ unsigned d = 440;
10831083 \\}
10841084 , &[_][]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);
10871087 \\pub var c: c_int = 4;
10881088 \\pub export fn foo(_arg_c_1: u8) void {
10891089 \\ var c_1 = _arg_c_1;
10901090 \\ 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);
10931093 \\ {
10941094 \\ var d: c_int = 5;
10951095 \\ }
1096 \\ var d: c_uint = @as(c_uint, 440);
1096 \\ var d: c_uint = @intCast(c_uint, 440);
10971097 \\}
10981098 });
10991099
......@@ -1216,14 +1216,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12161216 \\ _ = 7;
12171217 \\ }
12181218 \\ }
1219 \\ var i: u8 = @as(u8, 2);
1219 \\ var i: u8 = @intCast(u8, 2);
12201220 \\}
12211221 });
12221222
12231223 cases.add("shadowing primitive types",
12241224 \\unsigned anyerror = 2;
12251225 , &[_][]const u8{
1226 \\pub export var _anyerror: c_uint = @as(c_uint, 2);
1226 \\pub export var _anyerror: c_uint = @intCast(c_uint, 2);
12271227 });
12281228
12291229 cases.add("floats",
......@@ -1397,17 +1397,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13971397 \\
13981398 , &[_][]const u8{
13991399 \\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, '\"');
14111411 \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
14121412 \\}
14131413 });
......@@ -1818,7 +1818,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18181818 , &[_][]const u8{
18191819 \\pub export fn foo() void {
18201820 \\ var i: c_int = 0;
1821 \\ var u: c_uint = @as(c_uint, 0);
1821 \\ var u: c_uint = @intCast(c_uint, 0);
18221822 \\ i += 1;
18231823 \\ i -= 1;
18241824 \\ u +%= 1;
......@@ -1858,7 +1858,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18581858 \\pub export fn log2(_arg_a: c_uint) c_int {
18591859 \\ var a = _arg_a;
18601860 \\ var i: c_int = 0;
1861 \\ while (a > @as(c_uint, 0)) {
1861 \\ while (a > @intCast(c_uint, 0)) {
18621862 \\ a >>= @as(@import("std").math.Log2Int(c_int), 1);
18631863 \\ }
18641864 \\ return i;
......@@ -1878,7 +1878,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18781878 \\pub export fn log2(_arg_a: u32) c_int {
18791879 \\ var a = _arg_a;
18801880 \\ var i: c_int = 0;
1881 \\ while (a > @as(c_uint, 0)) {
1881 \\ while (a > @intCast(c_uint, 0)) {
18821882 \\ a >>= @as(@import("std").math.Log2Int(c_int), 1);
18831883 \\ }
18841884 \\ return i;
......@@ -1957,35 +1957,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
19571957 \\}
19581958 , &[_][]const u8{
19591959 \\pub export fn foo() void {
1960 \\ var a: c_uint = @as(c_uint, 0);
1960 \\ var a: c_uint = @intCast(c_uint, 0);
19611961 \\ a +%= (blk: {
19621962 \\ const _ref_1 = &a;
1963 \\ _ref_1.* = _ref_1.* +% @as(c_uint, 1);
1963 \\ _ref_1.* = _ref_1.* +% @intCast(c_uint, 1);
19641964 \\ break :blk _ref_1.*;
19651965 \\ });
19661966 \\ a -%= (blk: {
19671967 \\ const _ref_2 = &a;
1968 \\ _ref_2.* = _ref_2.* -% @as(c_uint, 1);
1968 \\ _ref_2.* = _ref_2.* -% @intCast(c_uint, 1);
19691969 \\ break :blk _ref_2.*;
19701970 \\ });
19711971 \\ a *%= (blk: {
19721972 \\ const _ref_3 = &a;
1973 \\ _ref_3.* = _ref_3.* *% @as(c_uint, 1);
1973 \\ _ref_3.* = _ref_3.* *% @intCast(c_uint, 1);
19741974 \\ break :blk _ref_3.*;
19751975 \\ });
19761976 \\ a &= (blk: {
19771977 \\ const _ref_4 = &a;
1978 \\ _ref_4.* = _ref_4.* & @as(c_uint, 1);
1978 \\ _ref_4.* = _ref_4.* & @intCast(c_uint, 1);
19791979 \\ break :blk _ref_4.*;
19801980 \\ });
19811981 \\ a |= (blk: {
19821982 \\ const _ref_5 = &a;
1983 \\ _ref_5.* = _ref_5.* | @as(c_uint, 1);
1983 \\ _ref_5.* = _ref_5.* | @intCast(c_uint, 1);
19841984 \\ break :blk _ref_5.*;
19851985 \\ });
19861986 \\ a ^= (blk: {
19871987 \\ const _ref_6 = &a;
1988 \\ _ref_6.* = _ref_6.* ^ @as(c_uint, 1);
1988 \\ _ref_6.* = _ref_6.* ^ @intCast(c_uint, 1);
19891989 \\ break :blk _ref_6.*;
19901990 \\ });
19911991 \\ a >>= @as(@import("std").math.Log2Int(c_uint), (blk: {
......@@ -2017,7 +2017,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20172017 , &[_][]const u8{
20182018 \\pub export fn foo() void {
20192019 \\ var i: c_int = 0;
2020 \\ var u: c_uint = @as(c_uint, 0);
2020 \\ var u: c_uint = @intCast(c_uint, 0);
20212021 \\ i += 1;
20222022 \\ i -= 1;
20232023 \\ u +%= 1;
......@@ -2092,9 +2092,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20922092 \\ fn_int(1094861636);
20932093 \\ fn_f32(@intToFloat(f32, 3));
20942094 \\ 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));
20982098 \\ fn_f32(3);
20992099 \\ fn_f64(3);
21002100 \\ fn_bool(123 != 0);