| ... | @@ -117,11 +117,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -117,11 +117,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 117 | \\}; | 117 | \\}; |
| 118 | , | 118 | , |
| 119 | \\pub const struct_Foo = extern struct { | 119 | \\pub const struct_Foo = extern struct { |
| 120 | \\ a: ?[*]Foo, | 120 | \\ a: [*c]Foo, |
| 121 | \\}; | 121 | \\}; |
| 122 | \\pub const Foo = struct_Foo; | 122 | \\pub const Foo = struct_Foo; |
| 123 | \\pub const struct_Bar = extern struct { | 123 | \\pub const struct_Bar = extern struct { |
| 124 | \\ a: ?[*]Foo, | 124 | \\ a: [*c]Foo, |
| 125 | \\}; | 125 | \\}; |
| 126 | ); | 126 | ); |
| 127 | | 127 | |
| ... | @@ -202,7 +202,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -202,7 +202,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 202 | cases.add("restrict -> noalias", | 202 | cases.add("restrict -> noalias", |
| 203 | \\void foo(void *restrict bar, void *restrict); | 203 | \\void foo(void *restrict bar, void *restrict); |
| 204 | , | 204 | , |
| 205 | \\pub extern fn foo(noalias bar: ?*c_void, noalias arg1: ?*c_void) void; | 205 | \\pub extern fn foo(noalias bar: [*c]c_void, noalias arg1: [*c]c_void) void; |
| 206 | ); | 206 | ); |
| 207 | | 207 | |
| 208 | cases.add("simple struct", | 208 | cases.add("simple struct", |
| ... | @@ -213,7 +213,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -213,7 +213,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 213 | , | 213 | , |
| 214 | \\const struct_Foo = extern struct { | 214 | \\const struct_Foo = extern struct { |
| 215 | \\ x: c_int, | 215 | \\ x: c_int, |
| 216 | \\ y: ?[*]u8, | 216 | \\ y: [*c]u8, |
| 217 | \\}; | 217 | \\}; |
| 218 | , | 218 | , |
| 219 | \\pub const Foo = struct_Foo; | 219 | \\pub const Foo = struct_Foo; |
| ... | @@ -244,7 +244,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -244,7 +244,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 244 | , | 244 | , |
| 245 | \\pub const BarB = enum_Bar.B; | 245 | \\pub const BarB = enum_Bar.B; |
| 246 | , | 246 | , |
| 247 | \\pub extern fn func(a: ?[*]struct_Foo, b: ?[*](?[*]enum_Bar)) void; | 247 | \\pub extern fn func(a: [*c]struct_Foo, b: [*c]([*c]enum_Bar)) void; |
| 248 | , | 248 | , |
| 249 | \\pub const Foo = struct_Foo; | 249 | \\pub const Foo = struct_Foo; |
| 250 | , | 250 | , |
| ... | @@ -254,7 +254,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -254,7 +254,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 254 | cases.add("constant size array", | 254 | cases.add("constant size array", |
| 255 | \\void func(int array[20]); | 255 | \\void func(int array[20]); |
| 256 | , | 256 | , |
| 257 | \\pub extern fn func(array: ?[*]c_int) void; | 257 | \\pub extern fn func(array: [*c]c_int) void; |
| 258 | ); | 258 | ); |
| 259 | | 259 | |
| 260 | cases.add("self referential struct with function pointer", | 260 | cases.add("self referential struct with function pointer", |
| ... | @@ -263,7 +263,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -263,7 +263,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 263 | \\}; | 263 | \\}; |
| 264 | , | 264 | , |
| 265 | \\pub const struct_Foo = extern struct { | 265 | \\pub const struct_Foo = extern struct { |
| 266 | \\ derp: ?extern fn(?[*]struct_Foo) void, | 266 | \\ derp: ?extern fn([*c]struct_Foo) void, |
| 267 | \\}; | 267 | \\}; |
| 268 | , | 268 | , |
| 269 | \\pub const Foo = struct_Foo; | 269 | \\pub const Foo = struct_Foo; |
| ... | @@ -275,7 +275,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -275,7 +275,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 275 | , | 275 | , |
| 276 | \\pub const struct_Foo = @OpaqueType(); | 276 | \\pub const struct_Foo = @OpaqueType(); |
| 277 | , | 277 | , |
| 278 | \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo; | 278 | \\pub extern fn some_func(foo: [*c]struct_Foo, x: c_int) [*c]struct_Foo; |
| 279 | , | 279 | , |
| 280 | \\pub const Foo = struct_Foo; | 280 | \\pub const Foo = struct_Foo; |
| 281 | ); | 281 | ); |
| ... | @@ -322,11 +322,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -322,11 +322,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 322 | \\}; | 322 | \\}; |
| 323 | , | 323 | , |
| 324 | \\pub const struct_Bar = extern struct { | 324 | \\pub const struct_Bar = extern struct { |
| 325 | \\ next: ?[*]struct_Foo, | 325 | \\ next: [*c]struct_Foo, |
| 326 | \\}; | 326 | \\}; |
| 327 | , | 327 | , |
| 328 | \\pub const struct_Foo = extern struct { | 328 | \\pub const struct_Foo = extern struct { |
| 329 | \\ next: ?[*]struct_Bar, | 329 | \\ next: [*c]struct_Bar, |
| 330 | \\}; | 330 | \\}; |
| 331 | ); | 331 | ); |
| 332 | | 332 | |
| ... | @@ -336,7 +336,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -336,7 +336,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 336 | , | 336 | , |
| 337 | \\pub const Foo = c_void; | 337 | \\pub const Foo = c_void; |
| 338 | , | 338 | , |
| 339 | \\pub extern fn fun(a: ?*Foo) Foo; | 339 | \\pub extern fn fun(a: [*c]Foo) Foo; |
| 340 | ); | 340 | ); |
| 341 | | 341 | |
| 342 | cases.add("generate inline func for #define global extern fn", | 342 | cases.add("generate inline func for #define global extern fn", |
| ... | @@ -608,7 +608,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -608,7 +608,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 608 | \\ return 6; | 608 | \\ return 6; |
| 609 | \\} | 609 | \\} |
| 610 | , | 610 | , |
| 611 | \\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?*c_void) c_int { | 611 | \\pub export fn and_or_none_bool(a: c_int, b: f32, c: [*c]c_void) c_int { |
| 612 | \\ if ((a != 0) and (b != 0)) return 0; | 612 | \\ if ((a != 0) and (b != 0)) return 0; |
| 613 | \\ if ((b != 0) and (c != null)) return 1; | 613 | \\ if ((b != 0) and (c != null)) return 1; |
| 614 | \\ if ((a != 0) and (c != null)) return 2; | 614 | \\ if ((a != 0) and (c != null)) return 2; |
| ... | @@ -710,7 +710,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -710,7 +710,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 710 | \\pub const struct_Foo = extern struct { | 710 | \\pub const struct_Foo = extern struct { |
| 711 | \\ field: c_int, | 711 | \\ field: c_int, |
| 712 | \\}; | 712 | \\}; |
| 713 | \\pub export fn read_field(foo: ?[*]struct_Foo) c_int { | 713 | \\pub export fn read_field(foo: [*c]struct_Foo) c_int { |
| 714 | \\ return foo.?.field; | 714 | \\ return foo.?.field; |
| 715 | \\} | 715 | \\} |
| 716 | ); | 716 | ); |
| ... | @@ -756,8 +756,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -756,8 +756,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 756 | \\ return x; | 756 | \\ return x; |
| 757 | \\} | 757 | \\} |
| 758 | , | 758 | , |
| 759 | \\pub export fn foo(x: ?[*]c_ushort) ?*c_void { | 759 | \\pub export fn foo(x: [*c]c_ushort) [*c]c_void { |
| 760 | \\ return @ptrCast(?*c_void, x); | 760 | \\ return @ptrCast([*c]c_void, x); |
| 761 | \\} | 761 | \\} |
| 762 | ); | 762 | ); |
| 763 | | 763 | |
| ... | @@ -777,7 +777,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -777,7 +777,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 777 | \\ return 0; | 777 | \\ return 0; |
| 778 | \\} | 778 | \\} |
| 779 | , | 779 | , |
| 780 | \\pub export fn foo() ?[*]c_int { | 780 | \\pub export fn foo() [*c]c_int { |
| 781 | \\ return null; | 781 | \\ return null; |
| 782 | \\} | 782 | \\} |
| 783 | ); | 783 | ); |
| ... | @@ -1086,7 +1086,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1086,7 +1086,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1086 | \\ *x = 1; | 1086 | \\ *x = 1; |
| 1087 | \\} | 1087 | \\} |
| 1088 | , | 1088 | , |
| 1089 | \\pub export fn foo(x: ?[*]c_int) void { | 1089 | \\pub export fn foo(x: [*c]c_int) void { |
| 1090 | \\ x.?.* = 1; | 1090 | \\ x.?.* = 1; |
| 1091 | \\} | 1091 | \\} |
| 1092 | ); | 1092 | ); |
| ... | @@ -1114,7 +1114,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1114,7 +1114,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1114 | , | 1114 | , |
| 1115 | \\pub fn foo() c_int { | 1115 | \\pub fn foo() c_int { |
| 1116 | \\ var x: c_int = 1234; | 1116 | \\ var x: c_int = 1234; |
| 1117 | \\ var ptr: ?[*]c_int = &x; | 1117 | \\ var ptr: [*c]c_int = &x; |
| 1118 | \\ return ptr.?.*; | 1118 | \\ return ptr.?.*; |
| 1119 | \\} | 1119 | \\} |
| 1120 | ); | 1120 | ); |
| ... | @@ -1124,7 +1124,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1124,7 +1124,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1124 | \\ return "bar"; | 1124 | \\ return "bar"; |
| 1125 | \\} | 1125 | \\} |
| 1126 | , | 1126 | , |
| 1127 | \\pub fn foo() ?[*]const u8 { | 1127 | \\pub fn foo() [*c]const u8 { |
| 1128 | \\ return c"bar"; | 1128 | \\ return c"bar"; |
| 1129 | \\} | 1129 | \\} |
| 1130 | ); | 1130 | ); |
| ... | @@ -1253,8 +1253,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1253,8 +1253,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1253 | \\ return (float *)a; | 1253 | \\ return (float *)a; |
| 1254 | \\} | 1254 | \\} |
| 1255 | , | 1255 | , |
| 1256 | \\fn ptrcast(a: ?[*]c_int) ?[*]f32 { | 1256 | \\fn ptrcast(a: [*c]c_int) [*c]f32 { |
| 1257 | \\ return @ptrCast(?[*]f32, a); | 1257 | \\ return @ptrCast([*c]f32, a); |
| 1258 | \\} | 1258 | \\} |
| 1259 | ); | 1259 | ); |
| 1260 | | 1260 | |
| ... | @@ -1276,7 +1276,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1276,7 +1276,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1276 | \\ return !c; | 1276 | \\ return !c; |
| 1277 | \\} | 1277 | \\} |
| 1278 | , | 1278 | , |
| 1279 | \\pub fn foo(a: c_int, b: f32, c: ?*c_void) c_int { | 1279 | \\pub fn foo(a: c_int, b: f32, c: [*c]c_void) c_int { |
| 1280 | \\ return !(a == 0); | 1280 | \\ return !(a == 0); |
| 1281 | \\ return !(a != 0); | 1281 | \\ return !(a != 0); |
| 1282 | \\ return !(b != 0); | 1282 | \\ return !(b != 0); |
| ... | @@ -1297,7 +1297,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1297,7 +1297,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1297 | cases.add("const ptr initializer", | 1297 | cases.add("const ptr initializer", |
| 1298 | \\static const char *v0 = "0.0.0"; | 1298 | \\static const char *v0 = "0.0.0"; |
| 1299 | , | 1299 | , |
| 1300 | \\pub var v0: ?[*]const u8 = c"0.0.0"; | 1300 | \\pub var v0: [*c]const u8 = c"0.0.0"; |
| 1301 | ); | 1301 | ); |
| 1302 | | 1302 | |
| 1303 | cases.add("static incomplete array inside function", | 1303 | cases.add("static incomplete array inside function", |
| ... | @@ -1306,17 +1306,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1306,17 +1306,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1306 | \\} | 1306 | \\} |
| 1307 | , | 1307 | , |
| 1308 | \\pub fn foo() void { | 1308 | \\pub fn foo() void { |
| 1309 | \\ const v2: [*]const u8 = c"2.2.2"; | 1309 | \\ const v2: [*c]const u8 = c"2.2.2"; |
| 1310 | \\} | 1310 | \\} |
| 1311 | ); | 1311 | ); |
| 1312 | | 1312 | |
| 1313 | cases.add("macro pointer cast", | 1313 | cases.add("macro pointer cast", |
| 1314 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) | 1314 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) |
| 1315 | , | 1315 | , |
| 1316 | \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*]NRF_GPIO_Type, NRF_GPIO_BASE) else ([*]NRF_GPIO_Type)(NRF_GPIO_BASE); | 1316 | \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else ([*c]NRF_GPIO_Type)(NRF_GPIO_BASE); |
| 1317 | ); | 1317 | ); |
| 1318 | | 1318 | |
| 1319 | cases.add("if on none bool", | 1319 | cases.add("if on non-bool", |
| 1320 | \\enum SomeEnum { A, B, C }; | 1320 | \\enum SomeEnum { A, B, C }; |
| 1321 | \\int if_none_bool(int a, float b, void *c, enum SomeEnum d) { | 1321 | \\int if_none_bool(int a, float b, void *c, enum SomeEnum d) { |
| 1322 | \\ if (a) return 0; | 1322 | \\ if (a) return 0; |
| ... | @@ -1334,7 +1334,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1334,7 +1334,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1334 | \\ B, | 1334 | \\ B, |
| 1335 | \\ C, | 1335 | \\ C, |
| 1336 | \\}; | 1336 | \\}; |
| 1337 | \\pub fn if_none_bool(a: c_int, b: f32, c: ?*c_void, d: enum_SomeEnum) c_int { | 1337 | \\pub fn if_none_bool(a: c_int, b: f32, c: [*c]c_void, d: enum_SomeEnum) c_int { |
| 1338 | \\ if (a != 0) return 0; | 1338 | \\ if (a != 0) return 0; |
| 1339 | \\ if (b != 0) return 1; | 1339 | \\ if (b != 0) return 1; |
| 1340 | \\ if (c != null) return 2; | 1340 | \\ if (c != null) return 2; |
| ... | @@ -1343,7 +1343,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1343,7 +1343,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1343 | \\} | 1343 | \\} |
| 1344 | ); | 1344 | ); |
| 1345 | | 1345 | |
| 1346 | cases.add("while on none bool", | 1346 | cases.add("while on non-bool", |
| 1347 | \\int while_none_bool(int a, float b, void *c) { | 1347 | \\int while_none_bool(int a, float b, void *c) { |
| 1348 | \\ while (a) return 0; | 1348 | \\ while (a) return 0; |
| 1349 | \\ while (b) return 1; | 1349 | \\ while (b) return 1; |
| ... | @@ -1351,7 +1351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1351,7 +1351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1351 | \\ return 3; | 1351 | \\ return 3; |
| 1352 | \\} | 1352 | \\} |
| 1353 | , | 1353 | , |
| 1354 | \\pub fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int { | 1354 | \\pub fn while_none_bool(a: c_int, b: f32, c: [*c]c_void) c_int { |
| 1355 | \\ while (a != 0) return 0; | 1355 | \\ while (a != 0) return 0; |
| 1356 | \\ while (b != 0) return 1; | 1356 | \\ while (b != 0) return 1; |
| 1357 | \\ while (c != null) return 2; | 1357 | \\ while (c != null) return 2; |
| ... | @@ -1359,7 +1359,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1359,7 +1359,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1359 | \\} | 1359 | \\} |
| 1360 | ); | 1360 | ); |
| 1361 | | 1361 | |
| 1362 | cases.add("for on none bool", | 1362 | cases.add("for on non-bool", |
| 1363 | \\int for_none_bool(int a, float b, void *c) { | 1363 | \\int for_none_bool(int a, float b, void *c) { |
| 1364 | \\ for (;a;) return 0; | 1364 | \\ for (;a;) return 0; |
| 1365 | \\ for (;b;) return 1; | 1365 | \\ for (;b;) return 1; |
| ... | @@ -1367,7 +1367,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1367,7 +1367,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1367 | \\ return 3; | 1367 | \\ return 3; |
| 1368 | \\} | 1368 | \\} |
| 1369 | , | 1369 | , |
| 1370 | \\pub fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int { | 1370 | \\pub fn for_none_bool(a: c_int, b: f32, c: [*c]c_void) c_int { |
| 1371 | \\ while (a != 0) return 0; | 1371 | \\ while (a != 0) return 0; |
| 1372 | \\ while (b != 0) return 1; | 1372 | \\ while (b != 0) return 1; |
| 1373 | \\ while (c != null) return 2; | 1373 | \\ while (c != null) return 2; |