authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2021-03-05 19:42:21+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2021-03-05 21:04:27+01:00
logb4ef6fa09d945c6e7d0f8a73e77c4c03ba262fd7
treecb04ac5e7e4943bd1890d3217ffb2b4b4c031403
parent5f53b77c2bed56e53717315eef2c92bfbf0a3ee0

fix test-translate-c


1 files changed, 39 insertions(+), 39 deletions(-)

test/translate_c.zig+39-39
...@@ -232,12 +232,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -232,12 +232,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
232 \\ | (*((unsigned char *)(p) + 1) << 8) \232 \\ | (*((unsigned char *)(p) + 1) << 8) \
233 \\ | (*((unsigned char *)(p) + 2) << 16))233 \\ | (*((unsigned char *)(p) + 2) << 16))
234 , &[_][]const u8{234 , &[_][]const u8{
235 \\pub const FOO = (foo + 2).*;235 \\pub const FOO = (foo + @as(c_int, 2)).*;
236 ,236 ,
237 \\pub const VALUE = ((((1 + (2 * 3)) + (4 * 5)) + 6) << 7) | @boolToInt(8 == 9);237 \\pub const VALUE = ((((@as(c_int, 1) + (@as(c_int, 2) * @as(c_int, 3))) + (@as(c_int, 4) * @as(c_int, 5))) + @as(c_int, 6)) << @as(c_int, 7)) | @boolToInt(@as(c_int, 8) == @as(c_int, 9));
238 ,238 ,
239 \\pub fn _AL_READ3BYTES(p: anytype) callconv(.Inline) @TypeOf((@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + 1).* << 8)) | ((@import("std").meta.cast([*c]u8, p) + 2).* << 16)) {239 \\pub fn _AL_READ3BYTES(p: anytype) callconv(.Inline) @TypeOf((@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) {
240 \\ return (@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + 1).* << 8)) | ((@import("std").meta.cast([*c]u8, p) + 2).* << 16);240 \\ return (@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16));
241 \\}241 \\}
242 });242 });
243243
...@@ -312,14 +312,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -312,14 +312,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
312 \\ return type_1;312 \\ return type_1;
313 \\}313 \\}
314 ,314 ,
315 \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ 200, 200, 200, 255 });315 \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ @as(c_int, 200), @as(c_int, 200), @as(c_int, 200), @as(c_int, 255) });
316 ,316 ,
317 \\pub const struct_boom_t = extern struct {317 \\pub const struct_boom_t = extern struct {
318 \\ i1: c_int,318 \\ i1: c_int,
319 \\};319 \\};
320 \\pub const boom_t = struct_boom_t;320 \\pub const boom_t = struct_boom_t;
321 ,321 ,
322 \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{1});322 \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{@as(c_int, 1)});
323 });323 });
324324
325 cases.add("complex switch",325 cases.add("complex switch",
...@@ -343,8 +343,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -343,8 +343,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
343 cases.add("correct semicolon after infixop",343 cases.add("correct semicolon after infixop",
344 \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)344 \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
345 , &[_][]const u8{345 , &[_][]const u8{
346 \\pub fn __ferror_unlocked_body(_fp: anytype) callconv(.Inline) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != 0) {346 \\pub fn __ferror_unlocked_body(_fp: anytype) callconv(.Inline) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) {
347 \\ return (_fp.*._flags & _IO_ERR_SEEN) != 0;347 \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0);
348 \\}348 \\}
349 });349 });
350350
...@@ -352,11 +352,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -352,11 +352,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
352 \\#define FOO(x) ((x >= 0) + (x >= 0))352 \\#define FOO(x) ((x >= 0) + (x >= 0))
353 \\#define BAR 1 && 2 > 4353 \\#define BAR 1 && 2 > 4
354 , &[_][]const u8{354 , &[_][]const u8{
355 \\pub fn FOO(x: anytype) callconv(.Inline) @TypeOf(@boolToInt(x >= 0) + @boolToInt(x >= 0)) {355 \\pub fn FOO(x: anytype) callconv(.Inline) @TypeOf(@boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0))) {
356 \\ return @boolToInt(x >= 0) + @boolToInt(x >= 0);356 \\ return @boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0));
357 \\}357 \\}
358 ,358 ,
359 \\pub const BAR = (1 != 0) and (2 > 4);359 \\pub const BAR = (@as(c_int, 1) != 0) and (@as(c_int, 2) > @as(c_int, 4));
360 });360 });
361361
362 cases.add("struct with aligned fields",362 cases.add("struct with aligned fields",
...@@ -401,15 +401,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -401,15 +401,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
401 \\ break :blk bar;401 \\ break :blk bar;
402 \\};402 \\};
403 ,403 ,
404 \\pub fn bar(x: anytype) callconv(.Inline) @TypeOf(baz(1, 2)) {404 \\pub fn bar(x: anytype) callconv(.Inline) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) {
405 \\ return blk: {405 \\ return blk: {
406 \\ _ = &x;406 \\ _ = &x;
407 \\ _ = 3;407 \\ _ = @as(c_int, 3);
408 \\ _ = 4 == 4;408 \\ _ = @as(c_int, 4) == @as(c_int, 4);
409 \\ _ = 5 * 6;409 \\ _ = @as(c_int, 5) * @as(c_int, 6);
410 \\ _ = baz(1, 2);410 \\ _ = baz(@as(c_int, 1), @as(c_int, 2));
411 \\ _ = 2 % 2;411 \\ _ = @as(c_int, 2) % @as(c_int, 2);
412 \\ break :blk baz(1, 2);412 \\ break :blk baz(@as(c_int, 1), @as(c_int, 2));
413 \\ };413 \\ };
414 \\}414 \\}
415 });415 });
...@@ -418,9 +418,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -418,9 +418,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
418 \\#define foo 1418 \\#define foo 1
419 \\#define inline 2419 \\#define inline 2
420 , &[_][]const u8{420 , &[_][]const u8{
421 \\pub const foo = 1;421 \\pub const foo = @as(c_int, 1);
422 ,422 ,
423 \\pub const @"inline" = 2;423 \\pub const @"inline" = @as(c_int, 2);
424 });424 });
425425
426 cases.add("macro line continuation",426 cases.add("macro line continuation",
...@@ -507,7 +507,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -507,7 +507,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
507 cases.add("#define hex literal with capital X",507 cases.add("#define hex literal with capital X",
508 \\#define VAL 0XF00D508 \\#define VAL 0XF00D
509 , &[_][]const u8{509 , &[_][]const u8{
510 \\pub const VAL = 0xF00D;510 \\pub const VAL = @import("std").meta.promoteIntLiteral(c_int, 0xF00D, .hexadecimal);
511 });511 });
512512
513 cases.add("anonymous struct & unions",513 cases.add("anonymous struct & unions",
...@@ -872,7 +872,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -872,7 +872,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
872 cases.add("macro with left shift",872 cases.add("macro with left shift",
873 \\#define REDISMODULE_READ (1<<0)873 \\#define REDISMODULE_READ (1<<0)
874 , &[_][]const u8{874 , &[_][]const u8{
875 \\pub const REDISMODULE_READ = 1 << 0;875 \\pub const REDISMODULE_READ = @as(c_int, 1) << @as(c_int, 0);
876 });876 });
877877
878 cases.add("macro with right shift",878 cases.add("macro with right shift",
...@@ -881,7 +881,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -881,7 +881,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
881 , &[_][]const u8{881 , &[_][]const u8{
882 \\pub const FLASH_SIZE = @as(c_ulong, 0x200000);882 \\pub const FLASH_SIZE = @as(c_ulong, 0x200000);
883 ,883 ,
884 \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> 1;884 \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> @as(c_int, 1);
885 });885 });
886886
887 cases.add("double define struct",887 cases.add("double define struct",
...@@ -949,14 +949,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -949,14 +949,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
949 cases.add("#define an unsigned integer literal",949 cases.add("#define an unsigned integer literal",
950 \\#define CHANNEL_COUNT 24950 \\#define CHANNEL_COUNT 24
951 , &[_][]const u8{951 , &[_][]const u8{
952 \\pub const CHANNEL_COUNT = 24;952 \\pub const CHANNEL_COUNT = @as(c_int, 24);
953 });953 });
954954
955 cases.add("#define referencing another #define",955 cases.add("#define referencing another #define",
956 \\#define THING2 THING1956 \\#define THING2 THING1
957 \\#define THING1 1234957 \\#define THING1 1234
958 , &[_][]const u8{958 , &[_][]const u8{
959 \\pub const THING1 = 1234;959 \\pub const THING1 = @as(c_int, 1234);
960 ,960 ,
961 \\pub const THING2 = THING1;961 \\pub const THING2 = THING1;
962 });962 });
...@@ -1002,7 +1002,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1002,7 +1002,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1002 cases.add("macro with parens around negative number",1002 cases.add("macro with parens around negative number",
1003 \\#define LUA_GLOBALSINDEX (-10002)1003 \\#define LUA_GLOBALSINDEX (-10002)
1004 , &[_][]const u8{1004 , &[_][]const u8{
1005 \\pub const LUA_GLOBALSINDEX = -10002;1005 \\pub const LUA_GLOBALSINDEX = -@as(c_int, 10002);
1006 });1006 });
10071007
1008 cases.add(1008 cases.add(
...@@ -1085,8 +1085,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1085,8 +1085,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1085 \\#define foo 1 //foo1085 \\#define foo 1 //foo
1086 \\#define bar /* bar */ 21086 \\#define bar /* bar */ 2
1087 , &[_][]const u8{1087 , &[_][]const u8{
1088 "pub const foo = 1;",1088 "pub const foo = @as(c_int, 1);",
1089 "pub const bar = 2;",1089 "pub const bar = @as(c_int, 2);",
1090 });1090 });
10911091
1092 cases.add("string prefix",1092 cases.add("string prefix",
...@@ -1716,7 +1716,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1716,7 +1716,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1716 cases.add("comment after integer literal",1716 cases.add("comment after integer literal",
1717 \\#define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */1717 \\#define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
1718 , &[_][]const u8{1718 , &[_][]const u8{
1719 \\pub const SDL_INIT_VIDEO = 0x00000020;1719 \\pub const SDL_INIT_VIDEO = @as(c_int, 0x00000020);
1720 });1720 });
17211721
1722 cases.add("u integer suffix after hex literal",1722 cases.add("u integer suffix after hex literal",
...@@ -1830,8 +1830,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1830,8 +1830,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1830 , &[_][]const u8{1830 , &[_][]const u8{
1831 \\pub extern var c: c_int;1831 \\pub extern var c: c_int;
1832 ,1832 ,
1833 \\pub fn BASIC(c_1: anytype) callconv(.Inline) @TypeOf(c_1 * 2) {1833 \\pub fn BASIC(c_1: anytype) callconv(.Inline) @TypeOf(c_1 * @as(c_int, 2)) {
1834 \\ return c_1 * 2;1834 \\ return c_1 * @as(c_int, 2);
1835 \\}1835 \\}
1836 ,1836 ,
1837 \\pub fn FOO(L: anytype, b: anytype) callconv(.Inline) @TypeOf(L + b) {1837 \\pub fn FOO(L: anytype, b: anytype) callconv(.Inline) @TypeOf(L + b) {
...@@ -2475,7 +2475,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2475,7 +2475,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2475 \\ return array[@intCast(c_uint, index)];2475 \\ return array[@intCast(c_uint, index)];
2476 \\}2476 \\}
2477 ,2477 ,
2478 \\pub const ACCESS = array[2];2478 \\pub const ACCESS = array[@as(c_int, 2)];
2479 });2479 });
24802480
2481 cases.add("cast signed array index to unsigned",2481 cases.add("cast signed array index to unsigned",
...@@ -3091,7 +3091,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3091,7 +3091,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3091 ,3091 ,
3092 \\pub const BAR = @import("std").meta.cast(?*c_void, a);3092 \\pub const BAR = @import("std").meta.cast(?*c_void, a);
3093 ,3093 ,
3094 \\pub const BAZ = @import("std").meta.cast(u32, 2);3094 \\pub const BAZ = @import("std").meta.cast(u32, @as(c_int, 2));
3095 });3095 });
30963096
3097 cases.add("macro with cast to unsigned short, long, and long long",3097 cases.add("macro with cast to unsigned short, long, and long long",
...@@ -3099,9 +3099,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3099,9 +3099,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3099 \\#define CURLAUTH_BASIC ((unsigned long) 1)3099 \\#define CURLAUTH_BASIC ((unsigned long) 1)
3100 \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1)3100 \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1)
3101 , &[_][]const u8{3101 , &[_][]const u8{
3102 \\pub const CURLAUTH_BASIC_BUT_USHORT = @import("std").meta.cast(c_ushort, 1);3102 \\pub const CURLAUTH_BASIC_BUT_USHORT = @import("std").meta.cast(c_ushort, @as(c_int, 1));
3103 \\pub const CURLAUTH_BASIC = @import("std").meta.cast(c_ulong, 1);3103 \\pub const CURLAUTH_BASIC = @import("std").meta.cast(c_ulong, @as(c_int, 1));
3104 \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").meta.cast(c_ulonglong, 1);3104 \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").meta.cast(c_ulonglong, @as(c_int, 1));
3105 });3105 });
31063106
3107 cases.add("macro conditional operator",3107 cases.add("macro conditional operator",
...@@ -3196,7 +3196,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3196,7 +3196,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3196 \\ bar_1 = 2;3196 \\ bar_1 = 2;
3197 \\}3197 \\}
3198 ,3198 ,
3199 \\pub const bar = 4;3199 \\pub const bar = @as(c_int, 4);
3200 });3200 });
32013201
3202 cases.add("don't export inline functions",3202 cases.add("don't export inline functions",
...@@ -3325,9 +3325,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3325,9 +3325,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3325 \\#define NULL ((void*)0)3325 \\#define NULL ((void*)0)
3326 \\#define FOO ((int)0x8000)3326 \\#define FOO ((int)0x8000)
3327 , &[_][]const u8{3327 , &[_][]const u8{
3328 \\pub const NULL = @import("std").meta.cast(?*c_void, 0);3328 \\pub const NULL = @import("std").meta.cast(?*c_void, @as(c_int, 0));
3329 ,3329 ,
3330 \\pub const FOO = @import("std").meta.cast(c_int, 0x8000);3330 \\pub const FOO = @import("std").meta.cast(c_int, @import("std").meta.promoteIntLiteral(c_int, 0x8000, .hexadecimal));
3331 });3331 });
33323332
3333 if (std.Target.current.abi == .msvc) {3333 if (std.Target.current.abi == .msvc) {