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 {
232232 \\ | (*((unsigned char *)(p) + 1) << 8) \
233233 \\ | (*((unsigned char *)(p) + 2) << 16))
234234 , &[_][]const u8{
235 \\pub const FOO = (foo + 2).*;
235 \\pub const FOO = (foo + @as(c_int, 2)).*;
236236 ,
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));
238238 ,
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)) {
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);
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) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16));
241241 \\}
242242 });
243243
......@@ -312,14 +312,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
312312 \\ return type_1;
313313 \\}
314314 ,
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) });
316316 ,
317317 \\pub const struct_boom_t = extern struct {
318318 \\ i1: c_int,
319319 \\};
320320 \\pub const boom_t = struct_boom_t;
321321 ,
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)});
323323 });
324324
325325 cases.add("complex switch",
......@@ -343,8 +343,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
343343 cases.add("correct semicolon after infixop",
344344 \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
345345 , &[_][]const u8{
346 \\pub fn __ferror_unlocked_body(_fp: anytype) callconv(.Inline) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != 0) {
347 \\ return (_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) != @as(c_int, 0);
348348 \\}
349349 });
350350
......@@ -352,11 +352,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
352352 \\#define FOO(x) ((x >= 0) + (x >= 0))
353353 \\#define BAR 1 && 2 > 4
354354 , &[_][]const u8{
355 \\pub fn FOO(x: anytype) callconv(.Inline) @TypeOf(@boolToInt(x >= 0) + @boolToInt(x >= 0)) {
356 \\ return @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 >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0));
357357 \\}
358358 ,
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));
360360 });
361361
362362 cases.add("struct with aligned fields",
......@@ -401,15 +401,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
401401 \\ break :blk bar;
402402 \\};
403403 ,
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))) {
405405 \\ return blk: {
406406 \\ _ = &x;
407 \\ _ = 3;
408 \\ _ = 4 == 4;
409 \\ _ = 5 * 6;
410 \\ _ = baz(1, 2);
411 \\ _ = 2 % 2;
412 \\ break :blk baz(1, 2);
407 \\ _ = @as(c_int, 3);
408 \\ _ = @as(c_int, 4) == @as(c_int, 4);
409 \\ _ = @as(c_int, 5) * @as(c_int, 6);
410 \\ _ = baz(@as(c_int, 1), @as(c_int, 2));
411 \\ _ = @as(c_int, 2) % @as(c_int, 2);
412 \\ break :blk baz(@as(c_int, 1), @as(c_int, 2));
413413 \\ };
414414 \\}
415415 });
......@@ -418,9 +418,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
418418 \\#define foo 1
419419 \\#define inline 2
420420 , &[_][]const u8{
421 \\pub const foo = 1;
421 \\pub const foo = @as(c_int, 1);
422422 ,
423 \\pub const @"inline" = 2;
423 \\pub const @"inline" = @as(c_int, 2);
424424 });
425425
426426 cases.add("macro line continuation",
......@@ -507,7 +507,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
507507 cases.add("#define hex literal with capital X",
508508 \\#define VAL 0XF00D
509509 , &[_][]const u8{
510 \\pub const VAL = 0xF00D;
510 \\pub const VAL = @import("std").meta.promoteIntLiteral(c_int, 0xF00D, .hexadecimal);
511511 });
512512
513513 cases.add("anonymous struct & unions",
......@@ -872,7 +872,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
872872 cases.add("macro with left shift",
873873 \\#define REDISMODULE_READ (1<<0)
874874 , &[_][]const u8{
875 \\pub const REDISMODULE_READ = 1 << 0;
875 \\pub const REDISMODULE_READ = @as(c_int, 1) << @as(c_int, 0);
876876 });
877877
878878 cases.add("macro with right shift",
......@@ -881,7 +881,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
881881 , &[_][]const u8{
882882 \\pub const FLASH_SIZE = @as(c_ulong, 0x200000);
883883 ,
884 \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> 1;
884 \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> @as(c_int, 1);
885885 });
886886
887887 cases.add("double define struct",
......@@ -949,14 +949,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
949949 cases.add("#define an unsigned integer literal",
950950 \\#define CHANNEL_COUNT 24
951951 , &[_][]const u8{
952 \\pub const CHANNEL_COUNT = 24;
952 \\pub const CHANNEL_COUNT = @as(c_int, 24);
953953 });
954954
955955 cases.add("#define referencing another #define",
956956 \\#define THING2 THING1
957957 \\#define THING1 1234
958958 , &[_][]const u8{
959 \\pub const THING1 = 1234;
959 \\pub const THING1 = @as(c_int, 1234);
960960 ,
961961 \\pub const THING2 = THING1;
962962 });
......@@ -1002,7 +1002,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10021002 cases.add("macro with parens around negative number",
10031003 \\#define LUA_GLOBALSINDEX (-10002)
10041004 , &[_][]const u8{
1005 \\pub const LUA_GLOBALSINDEX = -10002;
1005 \\pub const LUA_GLOBALSINDEX = -@as(c_int, 10002);
10061006 });
10071007
10081008 cases.add(
......@@ -1085,8 +1085,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10851085 \\#define foo 1 //foo
10861086 \\#define bar /* bar */ 2
10871087 , &[_][]const u8{
1088 "pub const foo = 1;",
1089 "pub const bar = 2;",
1088 "pub const foo = @as(c_int, 1);",
1089 "pub const bar = @as(c_int, 2);",
10901090 });
10911091
10921092 cases.add("string prefix",
......@@ -1716,7 +1716,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17161716 cases.add("comment after integer literal",
17171717 \\#define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
17181718 , &[_][]const u8{
1719 \\pub const SDL_INIT_VIDEO = 0x00000020;
1719 \\pub const SDL_INIT_VIDEO = @as(c_int, 0x00000020);
17201720 });
17211721
17221722 cases.add("u integer suffix after hex literal",
......@@ -1830,8 +1830,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18301830 , &[_][]const u8{
18311831 \\pub extern var c: c_int;
18321832 ,
1833 \\pub fn BASIC(c_1: anytype) callconv(.Inline) @TypeOf(c_1 * 2) {
1834 \\ return c_1 * 2;
1833 \\pub fn BASIC(c_1: anytype) callconv(.Inline) @TypeOf(c_1 * @as(c_int, 2)) {
1834 \\ return c_1 * @as(c_int, 2);
18351835 \\}
18361836 ,
18371837 \\pub fn FOO(L: anytype, b: anytype) callconv(.Inline) @TypeOf(L + b) {
......@@ -2475,7 +2475,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
24752475 \\ return array[@intCast(c_uint, index)];
24762476 \\}
24772477 ,
2478 \\pub const ACCESS = array[2];
2478 \\pub const ACCESS = array[@as(c_int, 2)];
24792479 });
24802480
24812481 cases.add("cast signed array index to unsigned",
......@@ -3091,7 +3091,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30913091 ,
30923092 \\pub const BAR = @import("std").meta.cast(?*c_void, a);
30933093 ,
3094 \\pub const BAZ = @import("std").meta.cast(u32, 2);
3094 \\pub const BAZ = @import("std").meta.cast(u32, @as(c_int, 2));
30953095 });
30963096
30973097 cases.add("macro with cast to unsigned short, long, and long long",
......@@ -3099,9 +3099,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30993099 \\#define CURLAUTH_BASIC ((unsigned long) 1)
31003100 \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1)
31013101 , &[_][]const u8{
3102 \\pub const CURLAUTH_BASIC_BUT_USHORT = @import("std").meta.cast(c_ushort, 1);
3103 \\pub const CURLAUTH_BASIC = @import("std").meta.cast(c_ulong, 1);
3104 \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").meta.cast(c_ulonglong, 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, @as(c_int, 1));
3104 \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").meta.cast(c_ulonglong, @as(c_int, 1));
31053105 });
31063106
31073107 cases.add("macro conditional operator",
......@@ -3196,7 +3196,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
31963196 \\ bar_1 = 2;
31973197 \\}
31983198 ,
3199 \\pub const bar = 4;
3199 \\pub const bar = @as(c_int, 4);
32003200 });
32013201
32023202 cases.add("don't export inline functions",
......@@ -3325,9 +3325,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
33253325 \\#define NULL ((void*)0)
33263326 \\#define FOO ((int)0x8000)
33273327 , &[_][]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));
33293329 ,
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));
33313331 });
33323332
33333333 if (std.Target.current.abi == .msvc) {