authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-04-15 18:06:38+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-04-15 18:06:38+03:00
log0276d9ddc58694b81b5e98cc717243d50db873b1
treec6f1cffa8a6819faf6371cc766ac3ef5a8cb019b
parent1e23a3cd9162df098a302f22d70f2ac50b5eae21
parentca3bf6e6aded2ced560803970a43e703b8c4bd11
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #5046 from Vexu/translate-c

Translate-c correct invalid shortcut

10 files changed, 92 insertions(+), 70 deletions(-)

lib/std/array_list.zig+11-11
...@@ -205,7 +205,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {...@@ -205,7 +205,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
205 better_capacity += better_capacity / 2 + 8;205 better_capacity += better_capacity / 2 + 8;
206 if (better_capacity >= new_capacity) break;206 if (better_capacity >= new_capacity) break;
207 }207 }
208 208
209 const new_memory = try self.allocator.realloc(self.allocatedSlice(), better_capacity);209 const new_memory = try self.allocator.realloc(self.allocatedSlice(), better_capacity);
210 self.items.ptr = new_memory.ptr;210 self.items.ptr = new_memory.ptr;
211 self.capacity = new_memory.len;211 self.capacity = new_memory.len;
...@@ -250,7 +250,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {...@@ -250,7 +250,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
250 if (self.items.len == 0) return null;250 if (self.items.len == 0) return null;
251 return self.pop();251 return self.pop();
252 }252 }
253 253
254 // For a nicer API, `items.len` is the length, not the capacity.254 // For a nicer API, `items.len` is the length, not the capacity.
255 // This requires "unsafe" slicing.255 // This requires "unsafe" slicing.
256 fn allocatedSlice(self: Self) Slice {256 fn allocatedSlice(self: Self) Slice {
...@@ -448,16 +448,16 @@ test "std.ArrayList(u8) implements outStream" {...@@ -448,16 +448,16 @@ test "std.ArrayList(u8) implements outStream" {
448}448}
449449
450test "std.ArrayList.shrink still sets length on error.OutOfMemory" {450test "std.ArrayList.shrink still sets length on error.OutOfMemory" {
451 // use an arena allocator to make sure realloc returns error.OutOfMemory451 // use an arena allocator to make sure realloc returns error.OutOfMemory
452 var arena = std.heap.ArenaAllocator.init(testing.allocator);452 var arena = std.heap.ArenaAllocator.init(testing.allocator);
453 defer arena.deinit();453 defer arena.deinit();
454454
455 var list = ArrayList(i32).init(&arena.allocator);455 var list = ArrayList(i32).init(&arena.allocator);
456456
457 try list.append(1);457 try list.append(1);
458 try list.append(2);458 try list.append(2);
459 try list.append(3);459 try list.append(3);
460460
461 list.shrink(1);461 list.shrink(1);
462 testing.expect(list.items.len == 1);462 testing.expect(list.items.len == 1);
463}463}
lib/std/math/big/int.zig-1
...@@ -1467,7 +1467,6 @@ pub const Int = struct {...@@ -1467,7 +1467,6 @@ pub const Int = struct {
14671467
1468 r.swap(&x);1468 r.swap(&x);
1469 }1469 }
1470
1471};1470};
14721471
1473// Storage must live for the lifetime of the returned value1472// Storage must live for the lifetime of the returned value
lib/std/os.zig+1-1
...@@ -2584,7 +2584,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -2584,7 +2584,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
2584 }2584 }
2585}2585}
25862586
2587pub const FStatAtError = FStatError || error{NameTooLong, FileNotFound};2587pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound };
25882588
2589pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {2589pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
2590 const pathname_c = try toPosixPath(pathname);2590 const pathname_c = try toPosixPath(pathname);
lib/std/os/windows/gdi32.zig+1-1
...@@ -42,4 +42,4 @@ pub extern "gdi32" fn ChoosePixelFormat(...@@ -42,4 +42,4 @@ pub extern "gdi32" fn ChoosePixelFormat(
4242
43pub extern "gdi32" fn SwapBuffers(hdc: ?HDC) callconv(.Stdcall) bool;43pub extern "gdi32" fn SwapBuffers(hdc: ?HDC) callconv(.Stdcall) bool;
44pub extern "gdi32" fn wglCreateContext(hdc: ?HDC) callconv(.Stdcall) ?HGLRC;44pub extern "gdi32" fn wglCreateContext(hdc: ?HDC) callconv(.Stdcall) ?HGLRC;
45pub extern "gdi32" fn wglMakeCurrent(hdc: ?HDC, hglrc: ?HGLRC) callconv(.Stdcall) bool;
\ No newline at end of file
45pub extern "gdi32" fn wglMakeCurrent(hdc: ?HDC, hglrc: ?HGLRC) callconv(.Stdcall) bool;
lib/std/os/windows/user32.zig+1-1
...@@ -169,4 +169,4 @@ pub extern "user32" fn GetMessageA(...@@ -169,4 +169,4 @@ pub extern "user32" fn GetMessageA(
169169
170pub extern "user32" fn TranslateMessage(lpMsg: *const MSG) callconv(.Stdcall) bool;170pub extern "user32" fn TranslateMessage(lpMsg: *const MSG) callconv(.Stdcall) bool;
171pub extern "user32" fn DispatchMessageA(lpMsg: *const MSG) callconv(.Stdcall) LRESULT;171pub extern "user32" fn DispatchMessageA(lpMsg: *const MSG) callconv(.Stdcall) LRESULT;
172pub extern "user32" fn PostQuitMessage(nExitCode: i32) callconv(.Stdcall) void;
\ No newline at end of file
172pub extern "user32" fn PostQuitMessage(nExitCode: i32) callconv(.Stdcall) void;
lib/std/zig/parser_test.zig+1-1
...@@ -387,7 +387,7 @@ test "zig fmt: correctly space struct fields with doc comments" {...@@ -387,7 +387,7 @@ test "zig fmt: correctly space struct fields with doc comments" {
387 \\ c: u8,387 \\ c: u8,
388 \\};388 \\};
389 \\389 \\
390 ,390 ,
391 \\pub const S = struct {391 \\pub const S = struct {
392 \\ /// A392 \\ /// A
393 \\ a: u8,393 \\ a: u8,
src-self-hosted/stage2.zig+5-4
...@@ -903,13 +903,14 @@ fn enumToString(value: var, type_name: []const u8) ![]const u8 {...@@ -903,13 +903,14 @@ fn enumToString(value: var, type_name: []const u8) ![]const u8 {
903 if (e.is_exhaustive) {903 if (e.is_exhaustive) {
904 return std.fmt.allocPrint(std.heap.c_allocator, ".{}", .{@tagName(value)});904 return std.fmt.allocPrint(std.heap.c_allocator, ".{}", .{@tagName(value)});
905 } else {905 } else {
906 return std.fmt.allocPrint(std.heap.c_allocator,906 return std.fmt.allocPrint(
907 std.heap.c_allocator,
907 "@intToEnum({}, {})",908 "@intToEnum({}, {})",
908 .{type_name, @enumToInt(value)}909 .{ type_name, @enumToInt(value) },
909 );910 );
910 }911 }
911 },912 },
912 else => unreachable 913 else => unreachable,
913 }914 }
914}915}
915916
...@@ -1136,7 +1137,7 @@ const Stage2Target = extern struct {...@@ -1136,7 +1137,7 @@ const Stage2Target = extern struct {
1136 \\1137 \\
1137 , .{1138 , .{
1138 try enumToString(target.os.version_range.windows.min, "Target.Os.WindowsVersion"),1139 try enumToString(target.os.version_range.windows.min, "Target.Os.WindowsVersion"),
1139 try enumToString(target.os.version_range.windows.max, "Target.Os.WindowsVersion")1140 try enumToString(target.os.version_range.windows.max, "Target.Os.WindowsVersion"),
1140 }),1141 }),
1141 }1142 }
1142 try os_builtin_str_buffer.appendSlice("};\n");1143 try os_builtin_str_buffer.appendSlice("};\n");
src-self-hosted/translate_c.zig+65-36
...@@ -274,7 +274,7 @@ pub fn translate(...@@ -274,7 +274,7 @@ pub fn translate(
274 errdefer tree_arena.deinit();274 errdefer tree_arena.deinit();
275275
276 const tree = try tree_arena.allocator.create(ast.Tree);276 const tree = try tree_arena.allocator.create(ast.Tree);
277 tree.* = ast.Tree{277 tree.* = .{
278 .source = undefined, // need to use toOwnedSlice later278 .source = undefined, // need to use toOwnedSlice later
279 .root_node = undefined,279 .root_node = undefined,
280 .arena_allocator = tree_arena,280 .arena_allocator = tree_arena,
...@@ -644,7 +644,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void {...@@ -644,7 +644,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl) Error!void {
644 };644 };
645645
646 const node = try c.a().create(ast.Node.VarDecl);646 const node = try c.a().create(ast.Node.VarDecl);
647 node.* = ast.Node.VarDecl{647 node.* = .{
648 .doc_comments = null,648 .doc_comments = null,
649 .visib_token = visib_tok,649 .visib_token = visib_tok,
650 .thread_local_token = thread_local_token,650 .thread_local_token = thread_local_token,
...@@ -3479,7 +3479,7 @@ fn qualTypeToLog2IntRef(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigC...@@ -3479,7 +3479,7 @@ fn qualTypeToLog2IntRef(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigC
3479 // we can perform the log2 now.3479 // we can perform the log2 now.
3480 const cast_bit_width = math.log2_int(u64, int_bit_width);3480 const cast_bit_width = math.log2_int(u64, int_bit_width);
3481 const node = try rp.c.a().create(ast.Node.IntegerLiteral);3481 const node = try rp.c.a().create(ast.Node.IntegerLiteral);
3482 node.* = ast.Node.IntegerLiteral{3482 node.* = .{
3483 .token = try appendTokenFmt(rp.c, .Identifier, "u{}", .{cast_bit_width}),3483 .token = try appendTokenFmt(rp.c, .Identifier, "u{}", .{cast_bit_width}),
3484 };3484 };
3485 return &node.base;3485 return &node.base;
...@@ -3502,7 +3502,7 @@ fn qualTypeToLog2IntRef(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigC...@@ -3502,7 +3502,7 @@ fn qualTypeToLog2IntRef(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigC
3502 const import_fn_call = try transCreateNodeBuiltinFnCall(rp.c, "@import");3502 const import_fn_call = try transCreateNodeBuiltinFnCall(rp.c, "@import");
3503 const std_token = try appendToken(rp.c, .StringLiteral, "\"std\"");3503 const std_token = try appendToken(rp.c, .StringLiteral, "\"std\"");
3504 const std_node = try rp.c.a().create(ast.Node.StringLiteral);3504 const std_node = try rp.c.a().create(ast.Node.StringLiteral);
3505 std_node.* = ast.Node.StringLiteral{3505 std_node.* = .{
3506 .token = std_token,3506 .token = std_token,
3507 };3507 };
3508 try import_fn_call.params.push(&std_node.base);3508 try import_fn_call.params.push(&std_node.base);
...@@ -3783,7 +3783,7 @@ fn transCreateNodePrefixOp(...@@ -3783,7 +3783,7 @@ fn transCreateNodePrefixOp(
3783 bytes: []const u8,3783 bytes: []const u8,
3784) !*ast.Node.PrefixOp {3784) !*ast.Node.PrefixOp {
3785 const node = try c.a().create(ast.Node.PrefixOp);3785 const node = try c.a().create(ast.Node.PrefixOp);
3786 node.* = ast.Node.PrefixOp{3786 node.* = .{
3787 .op_token = try appendToken(c, op_tok_id, bytes),3787 .op_token = try appendToken(c, op_tok_id, bytes),
3788 .op = op,3788 .op = op,
3789 .rhs = undefined, // translate and set afterward3789 .rhs = undefined, // translate and set afterward
...@@ -3980,7 +3980,7 @@ fn transCreateNodeBoolLiteral(c: *Context, value: bool) !*ast.Node {...@@ -3980,7 +3980,7 @@ fn transCreateNodeBoolLiteral(c: *Context, value: bool) !*ast.Node {
3980fn transCreateNodeArrayInitializer(c: *Context, ty: *ast.Node) !*ast.Node.SuffixOp {3980fn transCreateNodeArrayInitializer(c: *Context, ty: *ast.Node) !*ast.Node.SuffixOp {
3981 _ = try appendToken(c, .LBrace, "{");3981 _ = try appendToken(c, .LBrace, "{");
3982 const node = try c.a().create(ast.Node.SuffixOp);3982 const node = try c.a().create(ast.Node.SuffixOp);
3983 node.* = ast.Node.SuffixOp{3983 node.* = .{
3984 .lhs = .{ .node = ty },3984 .lhs = .{ .node = ty },
3985 .op = .{3985 .op = .{
3986 .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(c.a()),3986 .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(c.a()),
...@@ -3993,7 +3993,7 @@ fn transCreateNodeArrayInitializer(c: *Context, ty: *ast.Node) !*ast.Node.Suffix...@@ -3993,7 +3993,7 @@ fn transCreateNodeArrayInitializer(c: *Context, ty: *ast.Node) !*ast.Node.Suffix
3993fn transCreateNodeStructInitializer(c: *Context, ty: *ast.Node) !*ast.Node.SuffixOp {3993fn transCreateNodeStructInitializer(c: *Context, ty: *ast.Node) !*ast.Node.SuffixOp {
3994 _ = try appendToken(c, .LBrace, "{");3994 _ = try appendToken(c, .LBrace, "{");
3995 const node = try c.a().create(ast.Node.SuffixOp);3995 const node = try c.a().create(ast.Node.SuffixOp);
3996 node.* = ast.Node.SuffixOp{3996 node.* = .{
3997 .lhs = .{ .node = ty },3997 .lhs = .{ .node = ty },
3998 .op = .{3998 .op = .{
3999 .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(c.a()),3999 .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(c.a()),
...@@ -4306,7 +4306,7 @@ fn transCreateNodeShiftOp(...@@ -4306,7 +4306,7 @@ fn transCreateNodeShiftOp(
4306 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");4306 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
43074307
4308 const node = try rp.c.a().create(ast.Node.InfixOp);4308 const node = try rp.c.a().create(ast.Node.InfixOp);
4309 node.* = ast.Node.InfixOp{4309 node.* = .{
4310 .op_token = op_token,4310 .op_token = op_token,
4311 .lhs = lhs,4311 .lhs = lhs,
4312 .op = op,4312 .op = op,
...@@ -4626,8 +4626,7 @@ fn finishTransFnProto(...@@ -4626,8 +4626,7 @@ fn finishTransFnProto(
4626 const type_node = try transQualType(rp, param_qt, source_loc);4626 const type_node = try transQualType(rp, param_qt, source_loc);
46274627
4628 const param_node = try rp.c.a().create(ast.Node.ParamDecl);4628 const param_node = try rp.c.a().create(ast.Node.ParamDecl);
4629 param_node.* = ast.Node.ParamDecl{4629 param_node.* = .{
4630 .base = ast.Node{ .id = ast.Node.Id.ParamDecl },
4631 .doc_comments = null,4630 .doc_comments = null,
4632 .comptime_token = null,4631 .comptime_token = null,
4633 .noalias_token = noalias_tok,4632 .noalias_token = noalias_tok,
...@@ -4648,8 +4647,7 @@ fn finishTransFnProto(...@@ -4648,8 +4647,7 @@ fn finishTransFnProto(
4648 }4647 }
46494648
4650 const var_arg_node = try rp.c.a().create(ast.Node.ParamDecl);4649 const var_arg_node = try rp.c.a().create(ast.Node.ParamDecl);
4651 var_arg_node.* = ast.Node.ParamDecl{4650 var_arg_node.* = .{
4652 .base = ast.Node{ .id = ast.Node.Id.ParamDecl },
4653 .doc_comments = null,4651 .doc_comments = null,
4654 .comptime_token = null,4652 .comptime_token = null,
4655 .noalias_token = null,4653 .noalias_token = null,
...@@ -4774,14 +4772,12 @@ pub fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comp...@@ -4774,14 +4772,12 @@ pub fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comp
4774 const semi_tok = try appendToken(c, .Semicolon, ";");4772 const semi_tok = try appendToken(c, .Semicolon, ";");
47754773
4776 const msg_node = try c.a().create(ast.Node.StringLiteral);4774 const msg_node = try c.a().create(ast.Node.StringLiteral);
4777 msg_node.* = ast.Node.StringLiteral{4775 msg_node.* = .{
4778 .base = ast.Node{ .id = ast.Node.Id.StringLiteral },
4779 .token = msg_tok,4776 .token = msg_tok,
4780 };4777 };
47814778
4782 const call_node = try c.a().create(ast.Node.BuiltinCall);4779 const call_node = try c.a().create(ast.Node.BuiltinCall);
4783 call_node.* = ast.Node.BuiltinCall{4780 call_node.* = .{
4784 .base = ast.Node{ .id = ast.Node.Id.BuiltinCall },
4785 .builtin_token = builtin_tok,4781 .builtin_token = builtin_tok,
4786 .params = ast.Node.BuiltinCall.ParamList.init(c.a()),4782 .params = ast.Node.BuiltinCall.ParamList.init(c.a()),
4787 .rparen_token = rparen_tok,4783 .rparen_token = rparen_tok,
...@@ -4789,8 +4785,7 @@ pub fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comp...@@ -4789,8 +4785,7 @@ pub fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comp
4789 try call_node.params.push(&msg_node.base);4785 try call_node.params.push(&msg_node.base);
47904786
4791 const var_decl_node = try c.a().create(ast.Node.VarDecl);4787 const var_decl_node = try c.a().create(ast.Node.VarDecl);
4792 var_decl_node.* = ast.Node.VarDecl{4788 var_decl_node.* = .{
4793 .base = ast.Node{ .id = ast.Node.Id.VarDecl },
4794 .doc_comments = null,4789 .doc_comments = null,
4795 .visib_token = pub_tok,4790 .visib_token = pub_tok,
4796 .thread_local_token = null,4791 .thread_local_token = null,
...@@ -4825,7 +4820,7 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8,...@@ -4825,7 +4820,7 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8,
4825 const new_token = try c.tree.tokens.addOne();4820 const new_token = try c.tree.tokens.addOne();
4826 errdefer c.tree.tokens.shrink(token_index);4821 errdefer c.tree.tokens.shrink(token_index);
48274822
4828 new_token.* = Token{4823 new_token.* = .{
4829 .id = token_id,4824 .id = token_id,
4830 .start = start_index,4825 .start = start_index,
4831 .end = end_index,4826 .end = end_index,
...@@ -5523,36 +5518,70 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5523,36 +5518,70 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5523 return error.ParseError;5518 return error.ParseError;
5524 }5519 }
55255520
5521 const lparen = try appendToken(c, .LParen, "(");
5522
5526 if (saw_integer_literal) {5523 if (saw_integer_literal) {
5527 // @intToPtr(dest, x)5524 //( if (@typeInfo(dest) == .Pointer))
5525 // @intToPtr(dest, x)
5526 //else
5527 // @as(dest, x) )
5528 const if_node = try transCreateNodeIf(c);
5529 const type_info_node = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
5530 try type_info_node.params.push(inner_node);
5531 type_info_node.rparen_token = try appendToken(c, .LParen, ")");
5532 const cmp_node = try c.a().create(ast.Node.InfixOp);
5533 cmp_node.* = .{
5534 .op_token = try appendToken(c, .EqualEqual, "=="),
5535 .lhs = &type_info_node.base,
5536 .op = .EqualEqual,
5537 .rhs = try transCreateNodeEnumLiteral(c, "Pointer"),
5538 };
5539 if_node.condition = &cmp_node.base;
5540 _ = try appendToken(c, .RParen, ")");
5541
5528 const int_to_ptr = try transCreateNodeBuiltinFnCall(c, "@intToPtr");5542 const int_to_ptr = try transCreateNodeBuiltinFnCall(c, "@intToPtr");
5529 try int_to_ptr.params.push(inner_node);5543 try int_to_ptr.params.push(inner_node);
5530 try int_to_ptr.params.push(node_to_cast);5544 try int_to_ptr.params.push(node_to_cast);
5531 int_to_ptr.rparen_token = try appendToken(c, .RParen, ")");5545 int_to_ptr.rparen_token = try appendToken(c, .RParen, ")");
5532 return &int_to_ptr.base;5546 if_node.body = &int_to_ptr.base;
5547
5548 const else_node = try transCreateNodeElse(c);
5549 if_node.@"else" = else_node;
5550
5551 const as_node = try transCreateNodeBuiltinFnCall(c, "@as");
5552 try as_node.params.push(inner_node);
5553 try as_node.params.push(node_to_cast);
5554 as_node.rparen_token = try appendToken(c, .RParen, ")");
5555 else_node.body = &as_node.base;
5556
5557 const group_node = try c.a().create(ast.Node.GroupedExpression);
5558 group_node.* = .{
5559 .lparen = lparen,
5560 .expr = &if_node.base,
5561 .rparen = try appendToken(c, .RParen, ")"),
5562 };
5563 return &group_node.base;
5533 }5564 }
55345565
5535 //( if (@typeInfo(@TypeOf(x)) == .Pointer)5566 //( if (@typeInfo(@TypeOf(x)) == .Pointer)
5536 // @ptrCast(dest, @alignCast(@alignOf(dest.Child), x))5567 // @ptrCast(dest, @alignCast(@alignOf(dest.Child), x))
5537 //else if (@typeInfo(@TypeOf(x)) == .Integer and @typeInfo(dest) == .Pointer))5568 //else if (@typeInfo(@TypeOf(x)) == .Int and @typeInfo(dest) == .Pointer))
5538 // @intToPtr(dest, x)5569 // @intToPtr(dest, x)
5539 //else5570 //else
5540 // @as(dest, x) )5571 // @as(dest, x) )
55415572
5542 const lparen = try appendToken(c, .LParen, "(");
5543
5544 const if_1 = try transCreateNodeIf(c);5573 const if_1 = try transCreateNodeIf(c);
5545 const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");5574 const type_info_1 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
5546 const type_of_1 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");5575 const type_of_1 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");
5547 try type_id_1.params.push(&type_of_1.base);5576 try type_info_1.params.push(&type_of_1.base);
5548 try type_of_1.params.push(node_to_cast);5577 try type_of_1.params.push(node_to_cast);
5549 type_of_1.rparen_token = try appendToken(c, .RParen, ")");5578 type_of_1.rparen_token = try appendToken(c, .RParen, ")");
5550 type_id_1.rparen_token = try appendToken(c, .RParen, ")");5579 type_info_1.rparen_token = try appendToken(c, .RParen, ")");
55515580
5552 const cmp_1 = try c.a().create(ast.Node.InfixOp);5581 const cmp_1 = try c.a().create(ast.Node.InfixOp);
5553 cmp_1.* = .{5582 cmp_1.* = .{
5554 .op_token = try appendToken(c, .EqualEqual, "=="),5583 .op_token = try appendToken(c, .EqualEqual, "=="),
5555 .lhs = &type_id_1.base,5584 .lhs = &type_info_1.base,
5556 .op = .EqualEqual,5585 .op = .EqualEqual,
5557 .rhs = try transCreateNodeEnumLiteral(c, "Pointer"),5586 .rhs = try transCreateNodeEnumLiteral(c, "Pointer"),
5558 };5587 };
...@@ -5590,17 +5619,17 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5590,17 +5619,17 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5590 if_1.@"else" = else_1;5619 if_1.@"else" = else_1;
55915620
5592 const if_2 = try transCreateNodeIf(c);5621 const if_2 = try transCreateNodeIf(c);
5593 const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");5622 const type_info_2 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
5594 const type_of_2 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");5623 const type_of_2 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");
5595 try type_id_2.params.push(&type_of_2.base);5624 try type_info_2.params.push(&type_of_2.base);
5596 try type_of_2.params.push(node_to_cast);5625 try type_of_2.params.push(node_to_cast);
5597 type_of_2.rparen_token = try appendToken(c, .RParen, ")");5626 type_of_2.rparen_token = try appendToken(c, .RParen, ")");
5598 type_id_2.rparen_token = try appendToken(c, .RParen, ")");5627 type_info_2.rparen_token = try appendToken(c, .RParen, ")");
55995628
5600 const cmp_2 = try c.a().create(ast.Node.InfixOp);5629 const cmp_2 = try c.a().create(ast.Node.InfixOp);
5601 cmp_2.* = .{5630 cmp_2.* = .{
5602 .op_token = try appendToken(c, .EqualEqual, "=="),5631 .op_token = try appendToken(c, .EqualEqual, "=="),
5603 .lhs = &type_id_2.base,5632 .lhs = &type_info_2.base,
5604 .op = .EqualEqual,5633 .op = .EqualEqual,
5605 .rhs = try transCreateNodeEnumLiteral(c, "Int"),5634 .rhs = try transCreateNodeEnumLiteral(c, "Int"),
5606 };5635 };
...@@ -5612,13 +5641,13 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5612,13 +5641,13 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5612 .op = .BoolAnd,5641 .op = .BoolAnd,
5613 .rhs = undefined,5642 .rhs = undefined,
5614 };5643 };
5615 const type_id_3 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");5644 const type_info_3 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
5616 try type_id_3.params.push(inner_node);5645 try type_info_3.params.push(inner_node);
5617 type_id_3.rparen_token = try appendToken(c, .LParen, ")");5646 type_info_3.rparen_token = try appendToken(c, .LParen, ")");
5618 const cmp_3 = try c.a().create(ast.Node.InfixOp);5647 const cmp_3 = try c.a().create(ast.Node.InfixOp);
5619 cmp_3.* = .{5648 cmp_3.* = .{
5620 .op_token = try appendToken(c, .EqualEqual, "=="),5649 .op_token = try appendToken(c, .EqualEqual, "=="),
5621 .lhs = &type_id_3.base,5650 .lhs = &type_info_3.base,
5622 .op = .EqualEqual,5651 .op = .EqualEqual,
5623 .rhs = try transCreateNodeEnumLiteral(c, "Pointer"),5652 .rhs = try transCreateNodeEnumLiteral(c, "Pointer"),
5624 };5653 };
test/stage1/behavior/for.zig+1-1
...@@ -162,7 +162,7 @@ test "for copies its payload" {...@@ -162,7 +162,7 @@ test "for copies its payload" {
162test "for on slice with allowzero ptr" {162test "for on slice with allowzero ptr" {
163 const S = struct {163 const S = struct {
164 fn doTheTest(slice: []const u8) void {164 fn doTheTest(slice: []const u8) void {
165 var ptr = @ptrCast([*]const allowzero u8, slice.ptr)[0..slice.len];165 var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len];
166 for (ptr) |x, i| expect(x == i + 1);166 for (ptr) |x, i| expect(x == i + 1);
167 for (ptr) |*x, i| expect(x.* == i + 1);167 for (ptr) |*x, i| expect(x.* == i + 1);
168 }168 }
test/translate_c.zig+6-13
...@@ -2879,7 +2879,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2879,7 +2879,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2879 , &[_][]const u8{2879 , &[_][]const u8{
2880 \\pub const FOO = 0x61626364;2880 \\pub const FOO = 0x61626364;
2881 });2881 });
2882 2882
2883 cases.add("Make sure casts are grouped",2883 cases.add("Make sure casts are grouped",
2884 \\typedef struct2884 \\typedef struct
2885 \\{2885 \\{
...@@ -2895,22 +2895,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2895,22 +2895,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2895 \\}2895 \\}
2896 });2896 });
28972897
2898 cases.add("Cast from integer literals to poiter",2898 cases.add("macro integer literal casts",
2899 \\#define NULL ((void*)0)2899 \\#define NULL ((void*)0)
2900 \\#define GPIO_0_MEM_MAP ((unsigned*)0x8000)2900 \\#define FOO ((int)0x8000)
2901 \\#define GPIO_1_MEM_MAP ((unsigned*)0x8004)
2902 \\#define GPIO_2_MEM_MAP ((unsigned*)0x8008)
2903 \\
2904 , &[_][]const u8{2901 , &[_][]const u8{
2905 \\pub const NULL = @intToPtr(?*c_void, 0);2902 \\pub const NULL = (if (@typeInfo(?*c_void) == .Pointer) @intToPtr(?*c_void, 0) else @as(?*c_void, 0));
2906 ,
2907 \\pub const GPIO_0_MEM_MAP = @intToPtr([*c]c_uint, 0x8000);
2908 ,2903 ,
2909 \\pub const GPIO_1_MEM_MAP = @intToPtr([*c]c_uint, 0x8004);2904 \\pub const FOO = (if (@typeInfo(c_int) == .Pointer) @intToPtr(c_int, 0x8000) else @as(c_int, 0x8000));
2910 ,
2911 \\pub const GPIO_2_MEM_MAP = @intToPtr([*c]c_uint, 0x8008);
2912 });2905 });
2913 2906
2914 if (std.Target.current.abi == .msvc) {2907 if (std.Target.current.abi == .msvc) {
2915 cases.add("nameless struct fields",2908 cases.add("nameless struct fields",
2916 \\typedef struct NAMED2909 \\typedef struct NAMED