use * for pointer type instead of &
See #770 To help automatically translate code, see the zig-fmt-pointer-reform-2 branch. This will convert all & into *. Due to the syntax ambiguity (which is why we are making this change), even address-of & will turn into *, so you'll have to manually fix thes instances. You will be guaranteed to get compile errors for them - expected 'type', found 'foo'
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const builtin = @import("builtin");
|
||||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: &tests.CompareOutputContext) void {
|
||||
pub fn addCases(cases: *tests.CompareOutputContext) void {
|
||||
if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
|
||||
cases.addAsm("hello world linux x86_64",
|
||||
\\.text
|
||||
|
||||
@@ -2,7 +2,7 @@ const tests = @import("tests.zig");
|
||||
const builtin = @import("builtin");
|
||||
const is_windows = builtin.os == builtin.Os.windows;
|
||||
|
||||
pub fn addCases(cases: &tests.BuildExamplesContext) void {
|
||||
pub fn addCases(cases: *tests.BuildExamplesContext) void {
|
||||
cases.add("example/hello_world/hello.zig");
|
||||
cases.addC("example/hello_world/hello_libc.zig");
|
||||
cases.add("example/cat/main.zig");
|
||||
|
||||
@@ -5,7 +5,7 @@ var foo: u8 align(4) = 100;
|
||||
|
||||
test "global variable alignment" {
|
||||
assert(@typeOf(&foo).alignment == 4);
|
||||
assert(@typeOf(&foo) == &align(4) u8);
|
||||
assert(@typeOf(&foo) == *align(4) u8);
|
||||
const slice = (&foo)[0..1];
|
||||
assert(@typeOf(slice) == []align(4) u8);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ var baz: packed struct {
|
||||
} = undefined;
|
||||
|
||||
test "packed struct alignment" {
|
||||
assert(@typeOf(&baz.b) == &align(1) u32);
|
||||
assert(@typeOf(&baz.b) == *align(1) u32);
|
||||
}
|
||||
|
||||
const blah: packed struct {
|
||||
@@ -40,11 +40,11 @@ const blah: packed struct {
|
||||
} = undefined;
|
||||
|
||||
test "bit field alignment" {
|
||||
assert(@typeOf(&blah.b) == &align(1:3:6) const u3);
|
||||
assert(@typeOf(&blah.b) == *align(1:3:6) const u3);
|
||||
}
|
||||
|
||||
test "default alignment allows unspecified in type syntax" {
|
||||
assert(&u32 == &align(@alignOf(u32)) u32);
|
||||
assert(*u32 == *align(@alignOf(u32)) u32);
|
||||
}
|
||||
|
||||
test "implicitly decreasing pointer alignment" {
|
||||
@@ -53,7 +53,7 @@ test "implicitly decreasing pointer alignment" {
|
||||
assert(addUnaligned(&a, &b) == 7);
|
||||
}
|
||||
|
||||
fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) u32 {
|
||||
fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
|
||||
return a.* + b.*;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ fn testBytesAlign(b: u8) void {
|
||||
b,
|
||||
b,
|
||||
};
|
||||
const ptr = @ptrCast(&u32, &bytes[0]);
|
||||
const ptr = @ptrCast(*u32, &bytes[0]);
|
||||
assert(ptr.* == 0x33333333);
|
||||
}
|
||||
|
||||
@@ -99,10 +99,10 @@ test "@alignCast pointers" {
|
||||
expectsOnly1(&x);
|
||||
assert(x == 2);
|
||||
}
|
||||
fn expectsOnly1(x: &align(1) u32) void {
|
||||
fn expectsOnly1(x: *align(1) u32) void {
|
||||
expects4(@alignCast(4, x));
|
||||
}
|
||||
fn expects4(x: &align(4) u32) void {
|
||||
fn expects4(x: *align(4) u32) void {
|
||||
x.* += 1;
|
||||
}
|
||||
|
||||
@@ -163,8 +163,8 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
|
||||
|
||||
test "@ptrCast preserves alignment of bigger source" {
|
||||
var x: u32 align(16) = 1234;
|
||||
const ptr = @ptrCast(&u8, &x);
|
||||
assert(@typeOf(ptr) == &align(16) u8);
|
||||
const ptr = @ptrCast(*u8, &x);
|
||||
assert(@typeOf(ptr) == *align(16) u8);
|
||||
}
|
||||
|
||||
test "compile-time known array index has best alignment possible" {
|
||||
@@ -175,10 +175,10 @@ test "compile-time known array index has best alignment possible" {
|
||||
3,
|
||||
4,
|
||||
};
|
||||
assert(@typeOf(&array[0]) == &align(4) u8);
|
||||
assert(@typeOf(&array[1]) == &u8);
|
||||
assert(@typeOf(&array[2]) == &align(2) u8);
|
||||
assert(@typeOf(&array[3]) == &u8);
|
||||
assert(@typeOf(&array[0]) == *align(4) u8);
|
||||
assert(@typeOf(&array[1]) == *u8);
|
||||
assert(@typeOf(&array[2]) == *align(2) u8);
|
||||
assert(@typeOf(&array[3]) == *u8);
|
||||
|
||||
// because align is too small but we still figure out to use 2
|
||||
var bigger align(2) = []u64{
|
||||
@@ -187,10 +187,10 @@ test "compile-time known array index has best alignment possible" {
|
||||
3,
|
||||
4,
|
||||
};
|
||||
assert(@typeOf(&bigger[0]) == &align(2) u64);
|
||||
assert(@typeOf(&bigger[1]) == &align(2) u64);
|
||||
assert(@typeOf(&bigger[2]) == &align(2) u64);
|
||||
assert(@typeOf(&bigger[3]) == &align(2) u64);
|
||||
assert(@typeOf(&bigger[0]) == *align(2) u64);
|
||||
assert(@typeOf(&bigger[1]) == *align(2) u64);
|
||||
assert(@typeOf(&bigger[2]) == *align(2) u64);
|
||||
assert(@typeOf(&bigger[3]) == *align(2) u64);
|
||||
|
||||
// because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
|
||||
var smaller align(2) = []u32{
|
||||
@@ -199,21 +199,21 @@ test "compile-time known array index has best alignment possible" {
|
||||
3,
|
||||
4,
|
||||
};
|
||||
testIndex(&smaller[0], 0, &align(2) u32);
|
||||
testIndex(&smaller[0], 1, &align(2) u32);
|
||||
testIndex(&smaller[0], 2, &align(2) u32);
|
||||
testIndex(&smaller[0], 3, &align(2) u32);
|
||||
testIndex(&smaller[0], 0, *align(2) u32);
|
||||
testIndex(&smaller[0], 1, *align(2) u32);
|
||||
testIndex(&smaller[0], 2, *align(2) u32);
|
||||
testIndex(&smaller[0], 3, *align(2) u32);
|
||||
|
||||
// has to use ABI alignment because index known at runtime only
|
||||
testIndex2(&array[0], 0, &u8);
|
||||
testIndex2(&array[0], 1, &u8);
|
||||
testIndex2(&array[0], 2, &u8);
|
||||
testIndex2(&array[0], 3, &u8);
|
||||
testIndex2(&array[0], 0, *u8);
|
||||
testIndex2(&array[0], 1, *u8);
|
||||
testIndex2(&array[0], 2, *u8);
|
||||
testIndex2(&array[0], 3, *u8);
|
||||
}
|
||||
fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) void {
|
||||
fn testIndex(smaller: *align(2) u32, index: usize, comptime T: type) void {
|
||||
assert(@typeOf(&smaller[index]) == T);
|
||||
}
|
||||
fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) void {
|
||||
fn testIndex2(ptr: *align(4) u8, index: usize, comptime T: type) void {
|
||||
assert(@typeOf(&ptr[index]) == T);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ test "atomicrmw and atomicload" {
|
||||
testAtomicLoad(&data);
|
||||
}
|
||||
|
||||
fn testAtomicRmw(ptr: &u8) void {
|
||||
fn testAtomicRmw(ptr: *u8) void {
|
||||
const prev_value = @atomicRmw(u8, ptr, AtomicRmwOp.Xchg, 42, AtomicOrder.SeqCst);
|
||||
assert(prev_value == 200);
|
||||
comptime {
|
||||
@@ -45,7 +45,7 @@ fn testAtomicRmw(ptr: &u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
fn testAtomicLoad(ptr: &u8) void {
|
||||
fn testAtomicLoad(ptr: *u8) void {
|
||||
const x = @atomicLoad(u8, ptr, AtomicOrder.SeqCst);
|
||||
assert(x == 42);
|
||||
}
|
||||
@@ -54,18 +54,18 @@ test "cmpxchg with ptr" {
|
||||
var data1: i32 = 1234;
|
||||
var data2: i32 = 5678;
|
||||
var data3: i32 = 9101;
|
||||
var x: &i32 = &data1;
|
||||
if (@cmpxchgWeak(&i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
|
||||
var x: *i32 = &data1;
|
||||
if (@cmpxchgWeak(*i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
|
||||
assert(x1 == &data1);
|
||||
} else {
|
||||
@panic("cmpxchg should have failed");
|
||||
}
|
||||
|
||||
while (@cmpxchgWeak(&i32, &x, &data1, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
|
||||
while (@cmpxchgWeak(*i32, &x, &data1, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
|
||||
assert(x1 == &data1);
|
||||
}
|
||||
assert(x == &data3);
|
||||
|
||||
assert(@cmpxchgStrong(&i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
|
||||
assert(@cmpxchgStrong(*i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
|
||||
assert(x == &data2);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");
|
||||
|
||||
test "function with &const parameter with type dereferenced by namespace" {
|
||||
const x: other_file.Integer = 1234;
|
||||
comptime std.debug.assert(@typeOf(&x) == &const other_file.Integer);
|
||||
comptime std.debug.assert(@typeOf(&x) == *const other_file.Integer);
|
||||
foo(x);
|
||||
}
|
||||
|
||||
fn foo(x: &const other_file.Integer) void {
|
||||
fn foo(x: *const other_file.Integer) void {
|
||||
std.debug.assert(x.* == 1234);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ const CountBy = struct {
|
||||
|
||||
const One = CountBy{ .a = 1 };
|
||||
|
||||
pub fn counter(self: &const CountBy) Counter {
|
||||
pub fn counter(self: *const CountBy) Counter {
|
||||
return Counter{ .i = 0 };
|
||||
}
|
||||
};
|
||||
@@ -11,13 +11,13 @@ const CountBy = struct {
|
||||
const Counter = struct {
|
||||
i: usize,
|
||||
|
||||
pub fn count(self: &Counter) bool {
|
||||
pub fn count(self: *Counter) bool {
|
||||
self.i += 1;
|
||||
return self.i <= 10;
|
||||
}
|
||||
};
|
||||
|
||||
fn constCount(comptime cb: &const CountBy, comptime unused: u32) void {
|
||||
fn constCount(comptime cb: *const CountBy, comptime unused: u32) void {
|
||||
comptime {
|
||||
var cnt = cb.counter();
|
||||
if (cnt.i != 0) @compileError("Counter instance reused!");
|
||||
|
||||
@@ -9,10 +9,10 @@ const ZigTable = struct {
|
||||
|
||||
pdf: fn (f64) f64,
|
||||
is_symmetric: bool,
|
||||
zero_case: fn (&Random, f64) f64,
|
||||
zero_case: fn (*Random, f64) f64,
|
||||
};
|
||||
|
||||
fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn (f64) f64, comptime f_inv: fn (f64) f64, comptime zero_case: fn (&Random, f64) f64) ZigTable {
|
||||
fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn (f64) f64, comptime f_inv: fn (f64) f64, comptime zero_case: fn (*Random, f64) f64) ZigTable {
|
||||
var tables: ZigTable = undefined;
|
||||
|
||||
tables.is_symmetric = is_symmetric;
|
||||
@@ -45,7 +45,7 @@ fn norm_f(x: f64) f64 {
|
||||
fn norm_f_inv(y: f64) f64 {
|
||||
return math.sqrt(-2.0 * math.ln(y));
|
||||
}
|
||||
fn norm_zero_case(random: &Random, u: f64) f64 {
|
||||
fn norm_zero_case(random: *Random, u: f64) f64 {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,20 +3,20 @@ const mem = @import("std").mem;
|
||||
|
||||
test "int to ptr cast" {
|
||||
const x = usize(13);
|
||||
const y = @intToPtr(&u8, x);
|
||||
const y = @intToPtr(*u8, x);
|
||||
const z = @ptrToInt(y);
|
||||
assert(z == 13);
|
||||
}
|
||||
|
||||
test "integer literal to pointer cast" {
|
||||
const vga_mem = @intToPtr(&u16, 0xB8000);
|
||||
const vga_mem = @intToPtr(*u16, 0xB8000);
|
||||
assert(@ptrToInt(vga_mem) == 0xB8000);
|
||||
}
|
||||
|
||||
test "pointer reinterpret const float to int" {
|
||||
const float: f64 = 5.99999999999994648725e-01;
|
||||
const float_ptr = &float;
|
||||
const int_ptr = @ptrCast(&const i32, float_ptr);
|
||||
const int_ptr = @ptrCast(*const i32, float_ptr);
|
||||
const int_val = int_ptr.*;
|
||||
assert(int_val == 858993411);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ test "implicitly cast a pointer to a const pointer of it" {
|
||||
assert(x == 2);
|
||||
}
|
||||
|
||||
fn funcWithConstPtrPtr(x: &const &i32) void {
|
||||
fn funcWithConstPtrPtr(x: *const *i32) void {
|
||||
x.*.* += 1;
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ fn Struct(comptime T: type) type {
|
||||
const Self = this;
|
||||
x: T,
|
||||
|
||||
fn pointer(self: &const Self) Self {
|
||||
fn pointer(self: *const Self) Self {
|
||||
return self.*;
|
||||
}
|
||||
|
||||
fn maybePointer(self: ?&const Self) Self {
|
||||
fn maybePointer(self: ?*const Self) Self {
|
||||
const none = Self{ .x = if (T == void) void{} else 0 };
|
||||
return (self ?? &none).*;
|
||||
}
|
||||
@@ -80,11 +80,11 @@ fn Struct(comptime T: type) type {
|
||||
const Union = union {
|
||||
x: u8,
|
||||
|
||||
fn pointer(self: &const Union) Union {
|
||||
fn pointer(self: *const Union) Union {
|
||||
return self.*;
|
||||
}
|
||||
|
||||
fn maybePointer(self: ?&const Union) Union {
|
||||
fn maybePointer(self: ?*const Union) Union {
|
||||
const none = Union{ .x = 0 };
|
||||
return (self ?? &none).*;
|
||||
}
|
||||
@@ -94,11 +94,11 @@ const Enum = enum {
|
||||
None,
|
||||
Some,
|
||||
|
||||
fn pointer(self: &const Enum) Enum {
|
||||
fn pointer(self: *const Enum) Enum {
|
||||
return self.*;
|
||||
}
|
||||
|
||||
fn maybePointer(self: ?&const Enum) Enum {
|
||||
fn maybePointer(self: ?*const Enum) Enum {
|
||||
return (self ?? &Enum.None).*;
|
||||
}
|
||||
};
|
||||
@@ -107,16 +107,16 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
|
||||
const S = struct {
|
||||
const Self = this;
|
||||
x: u8,
|
||||
fn constConst(p: &const &const Self) u8 {
|
||||
fn constConst(p: *const *const Self) u8 {
|
||||
return (p.*).x;
|
||||
}
|
||||
fn maybeConstConst(p: ?&const &const Self) u8 {
|
||||
fn maybeConstConst(p: ?*const *const Self) u8 {
|
||||
return ((??p).*).x;
|
||||
}
|
||||
fn constConstConst(p: &const &const &const Self) u8 {
|
||||
fn constConstConst(p: *const *const *const Self) u8 {
|
||||
return (p.*.*).x;
|
||||
}
|
||||
fn maybeConstConstConst(p: ?&const &const &const Self) u8 {
|
||||
fn maybeConstConstConst(p: ?*const *const *const Self) u8 {
|
||||
return ((??p).*.*).x;
|
||||
}
|
||||
};
|
||||
@@ -166,12 +166,12 @@ fn testPeerResolveArrayConstSlice(b: bool) void {
|
||||
}
|
||||
|
||||
test "integer literal to &const int" {
|
||||
const x: &const i32 = 3;
|
||||
const x: *const i32 = 3;
|
||||
assert(x.* == 3);
|
||||
}
|
||||
|
||||
test "string literal to &const []const u8" {
|
||||
const x: &const []const u8 = "hello";
|
||||
const x: *const []const u8 = "hello";
|
||||
assert(mem.eql(u8, x.*, "hello"));
|
||||
}
|
||||
|
||||
@@ -209,11 +209,11 @@ test "return null from fn() error!?&T" {
|
||||
const b = returnNullLitFromMaybeTypeErrorRef();
|
||||
assert((try a) == null and (try b) == null);
|
||||
}
|
||||
fn returnNullFromMaybeTypeErrorRef() error!?&A {
|
||||
const a: ?&A = null;
|
||||
fn returnNullFromMaybeTypeErrorRef() error!?*A {
|
||||
const a: ?*A = null;
|
||||
return a;
|
||||
}
|
||||
fn returnNullLitFromMaybeTypeErrorRef() error!?&A {
|
||||
fn returnNullLitFromMaybeTypeErrorRef() error!?*A {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ test "implicit cast from &const [N]T to []const T" {
|
||||
fn testCastConstArrayRefToConstSlice() void {
|
||||
const blah = "aoeu";
|
||||
const const_array_ref = &blah;
|
||||
assert(@typeOf(const_array_ref) == &const [4]u8);
|
||||
assert(@typeOf(const_array_ref) == *const [4]u8);
|
||||
const slice: []const u8 = const_array_ref;
|
||||
assert(mem.eql(u8, slice, "aoeu"));
|
||||
}
|
||||
@@ -322,7 +322,7 @@ test "var args implicitly casts by value arg to const ref" {
|
||||
}
|
||||
|
||||
fn foo(args: ...) void {
|
||||
assert(@typeOf(args[0]) == &const [5]u8);
|
||||
assert(@typeOf(args[0]) == *const [5]u8);
|
||||
}
|
||||
|
||||
test "peer type resolution: error and [N]T" {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const debug = @import("std").debug;
|
||||
const assert = debug.assert;
|
||||
|
||||
var argv: &const &const u8 = undefined;
|
||||
var argv: *const *const u8 = undefined;
|
||||
|
||||
test "const slice child" {
|
||||
const strs = ([]&const u8){
|
||||
const strs = ([]*const u8){
|
||||
c"one",
|
||||
c"two",
|
||||
c"three",
|
||||
@@ -29,7 +29,7 @@ fn bar(argc: usize) void {
|
||||
foo(args);
|
||||
}
|
||||
|
||||
fn strlen(ptr: &const u8) usize {
|
||||
fn strlen(ptr: *const u8) usize {
|
||||
var count: usize = 0;
|
||||
while (ptr[count] != 0) : (count += 1) {}
|
||||
return count;
|
||||
|
||||
@@ -154,7 +154,7 @@ test "async function with dot syntax" {
|
||||
test "async fn pointer in a struct field" {
|
||||
var data: i32 = 1;
|
||||
const Foo = struct {
|
||||
bar: async<&std.mem.Allocator> fn (&i32) void,
|
||||
bar: async<*std.mem.Allocator> fn (*i32) void,
|
||||
};
|
||||
var foo = Foo{ .bar = simpleAsyncFn2 };
|
||||
const p = (async<std.debug.global_allocator> foo.bar(&data)) catch unreachable;
|
||||
@@ -162,7 +162,7 @@ test "async fn pointer in a struct field" {
|
||||
cancel p;
|
||||
assert(data == 4);
|
||||
}
|
||||
async<&std.mem.Allocator> fn simpleAsyncFn2(y: &i32) void {
|
||||
async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void {
|
||||
defer y.* += 2;
|
||||
y.* += 1;
|
||||
suspend;
|
||||
@@ -220,7 +220,7 @@ test "break from suspend" {
|
||||
cancel p;
|
||||
std.debug.assert(my_result == 2);
|
||||
}
|
||||
async fn testBreakFromSuspend(my_result: &i32) void {
|
||||
async fn testBreakFromSuspend(my_result: *i32) void {
|
||||
s: suspend |p| {
|
||||
break :s;
|
||||
}
|
||||
|
||||
@@ -56,14 +56,14 @@ test "constant enum with payload" {
|
||||
shouldBeNotEmpty(full);
|
||||
}
|
||||
|
||||
fn shouldBeEmpty(x: &const AnEnumWithPayload) void {
|
||||
fn shouldBeEmpty(x: *const AnEnumWithPayload) void {
|
||||
switch (x.*) {
|
||||
AnEnumWithPayload.Empty => {},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
fn shouldBeNotEmpty(x: &const AnEnumWithPayload) void {
|
||||
fn shouldBeNotEmpty(x: *const AnEnumWithPayload) void {
|
||||
switch (x.*) {
|
||||
AnEnumWithPayload.Empty => unreachable,
|
||||
else => {},
|
||||
@@ -750,15 +750,15 @@ test "bit field access with enum fields" {
|
||||
assert(data.b == B.Four3);
|
||||
}
|
||||
|
||||
fn getA(data: &const BitFieldOfEnums) A {
|
||||
fn getA(data: *const BitFieldOfEnums) A {
|
||||
return data.a;
|
||||
}
|
||||
|
||||
fn getB(data: &const BitFieldOfEnums) B {
|
||||
fn getB(data: *const BitFieldOfEnums) B {
|
||||
return data.b;
|
||||
}
|
||||
|
||||
fn getC(data: &const BitFieldOfEnums) C {
|
||||
fn getC(data: *const BitFieldOfEnums) C {
|
||||
return data.c;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ const ET = union(enum) {
|
||||
SINT: i32,
|
||||
UINT: u32,
|
||||
|
||||
pub fn print(a: &const ET, buf: []u8) error!usize {
|
||||
pub fn print(a: *const ET, buf: []u8) error!usize {
|
||||
return switch (a.*) {
|
||||
ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
|
||||
ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
|
||||
|
||||
@@ -282,7 +282,7 @@ fn fnWithFloatMode() f32 {
|
||||
const SimpleStruct = struct {
|
||||
field: i32,
|
||||
|
||||
fn method(self: &const SimpleStruct) i32 {
|
||||
fn method(self: *const SimpleStruct) i32 {
|
||||
return self.field + 3;
|
||||
}
|
||||
};
|
||||
@@ -367,7 +367,7 @@ test "const global shares pointer with other same one" {
|
||||
assertEqualPtrs(&hi1[0], &hi2[0]);
|
||||
comptime assert(&hi1[0] == &hi2[0]);
|
||||
}
|
||||
fn assertEqualPtrs(ptr1: &const u8, ptr2: &const u8) void {
|
||||
fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {
|
||||
assert(ptr1 == ptr2);
|
||||
}
|
||||
|
||||
@@ -418,9 +418,9 @@ test "string literal used as comptime slice is memoized" {
|
||||
}
|
||||
|
||||
test "comptime slice of undefined pointer of length 0" {
|
||||
const slice1 = (&i32)(undefined)[0..0];
|
||||
const slice1 = (*i32)(undefined)[0..0];
|
||||
assert(slice1.len == 0);
|
||||
const slice2 = (&i32)(undefined)[100..100];
|
||||
const slice2 = (*i32)(undefined)[100..100];
|
||||
assert(slice2.len == 0);
|
||||
}
|
||||
|
||||
@@ -472,7 +472,7 @@ test "comptime function with mutable pointer is not memoized" {
|
||||
}
|
||||
}
|
||||
|
||||
fn increment(value: &i32) void {
|
||||
fn increment(value: *i32) void {
|
||||
value.* += 1;
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ test "comptime slice of pointer preserves comptime var" {
|
||||
const SingleFieldStruct = struct {
|
||||
x: i32,
|
||||
|
||||
fn read_x(self: &const SingleFieldStruct) i32 {
|
||||
fn read_x(self: *const SingleFieldStruct) i32 {
|
||||
return self.x;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ const foo = Foo{
|
||||
.d = -10,
|
||||
};
|
||||
|
||||
fn testParentFieldPtr(c: &const i32) void {
|
||||
fn testParentFieldPtr(c: *const i32) void {
|
||||
assert(c == &foo.c);
|
||||
|
||||
const base = @fieldParentPtr(Foo, "c", c);
|
||||
@@ -32,7 +32,7 @@ fn testParentFieldPtr(c: &const i32) void {
|
||||
assert(&base.c == c);
|
||||
}
|
||||
|
||||
fn testParentFieldPtrFirst(a: &const bool) void {
|
||||
fn testParentFieldPtrFirst(a: *const bool) void {
|
||||
assert(a == &foo.a);
|
||||
|
||||
const base = @fieldParentPtr(Foo, "a", a);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const assert = @import("std").debug.assert;
|
||||
|
||||
fn get_foo() fn (&u8) usize {
|
||||
fn get_foo() fn (*u8) usize {
|
||||
comptime {
|
||||
return struct {
|
||||
fn func(ptr: &u8) usize {
|
||||
fn func(ptr: *u8) usize {
|
||||
var u = @ptrToInt(ptr);
|
||||
return u;
|
||||
}
|
||||
@@ -13,5 +13,5 @@ fn get_foo() fn (&u8) usize {
|
||||
|
||||
test "define a function in an anonymous struct in comptime" {
|
||||
const foo = get_foo();
|
||||
assert(foo(@intToPtr(&u8, 12345)) == 12345);
|
||||
assert(foo(@intToPtr(*u8, 12345)) == 12345);
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ test "generic struct" {
|
||||
fn GenNode(comptime T: type) type {
|
||||
return struct {
|
||||
value: T,
|
||||
next: ?&GenNode(T),
|
||||
fn getVal(n: &const GenNode(T)) T {
|
||||
next: ?*GenNode(T),
|
||||
fn getVal(n: *const GenNode(T)) T {
|
||||
return n.value;
|
||||
}
|
||||
};
|
||||
@@ -126,11 +126,11 @@ test "generic fn with implicit cast" {
|
||||
13,
|
||||
}) == 0);
|
||||
}
|
||||
fn getByte(ptr: ?&const u8) u8 {
|
||||
fn getByte(ptr: ?*const u8) u8 {
|
||||
return (??ptr).*;
|
||||
}
|
||||
fn getFirstByte(comptime T: type, mem: []const T) u8 {
|
||||
return getByte(@ptrCast(&const u8, &mem[0]));
|
||||
return getByte(@ptrCast(*const u8, &mem[0]));
|
||||
}
|
||||
|
||||
const foos = []fn (var) bool{
|
||||
|
||||
@@ -11,12 +11,12 @@ const B = struct {
|
||||
const C = struct {
|
||||
x: i32,
|
||||
|
||||
fn d(c: &const C) i32 {
|
||||
fn d(c: *const C) i32 {
|
||||
return c.x;
|
||||
}
|
||||
};
|
||||
|
||||
fn foo(a: &const A) i32 {
|
||||
fn foo(a: *const A) i32 {
|
||||
return a.b.c.d();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ fn testDivision() void {
|
||||
assert(divTrunc(f32, -5.0, 3.0) == -1.0);
|
||||
|
||||
comptime {
|
||||
assert(1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600);
|
||||
assert(@rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600);
|
||||
assert(1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2);
|
||||
assert(@divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2);
|
||||
assert(@divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2);
|
||||
assert(@divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2);
|
||||
assert(4126227191251978491697987544882340798050766755606969681711 % 10 == 1);
|
||||
assert(1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,);
|
||||
assert(@rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,);
|
||||
assert(1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,);
|
||||
assert(@divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,);
|
||||
assert(@divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,);
|
||||
assert(@divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,);
|
||||
assert(4126227191251978491697987544882340798050766755606969681711 % 10 == 1,);
|
||||
}
|
||||
}
|
||||
fn div(comptime T: type, a: T, b: T) T {
|
||||
@@ -324,8 +324,8 @@ test "big number addition" {
|
||||
|
||||
test "big number multiplication" {
|
||||
comptime {
|
||||
assert(45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567);
|
||||
assert(594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016);
|
||||
assert(45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,);
|
||||
assert(594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -252,20 +252,20 @@ test "multiline C string" {
|
||||
}
|
||||
|
||||
test "type equality" {
|
||||
assert(&const u8 != &u8);
|
||||
assert(*const u8 != *u8);
|
||||
}
|
||||
|
||||
const global_a: i32 = 1234;
|
||||
const global_b: &const i32 = &global_a;
|
||||
const global_c: &const f32 = @ptrCast(&const f32, global_b);
|
||||
const global_b: *const i32 = &global_a;
|
||||
const global_c: *const f32 = @ptrCast(*const f32, global_b);
|
||||
test "compile time global reinterpret" {
|
||||
const d = @ptrCast(&const i32, global_c);
|
||||
const d = @ptrCast(*const i32, global_c);
|
||||
assert(d.* == 1234);
|
||||
}
|
||||
|
||||
test "explicit cast maybe pointers" {
|
||||
const a: ?&i32 = undefined;
|
||||
const b: ?&f32 = @ptrCast(?&f32, a);
|
||||
const a: ?*i32 = undefined;
|
||||
const b: ?*f32 = @ptrCast(?*f32, a);
|
||||
}
|
||||
|
||||
test "generic malloc free" {
|
||||
@@ -274,7 +274,7 @@ test "generic malloc free" {
|
||||
}
|
||||
var some_mem: [100]u8 = undefined;
|
||||
fn memAlloc(comptime T: type, n: usize) error![]T {
|
||||
return @ptrCast(&T, &some_mem[0])[0..n];
|
||||
return @ptrCast(*T, &some_mem[0])[0..n];
|
||||
}
|
||||
fn memFree(comptime T: type, memory: []T) void {}
|
||||
|
||||
@@ -357,7 +357,7 @@ const test3_foo = Test3Foo{
|
||||
},
|
||||
};
|
||||
const test3_bar = Test3Foo{ .Two = 13 };
|
||||
fn test3_1(f: &const Test3Foo) void {
|
||||
fn test3_1(f: *const Test3Foo) void {
|
||||
switch (f.*) {
|
||||
Test3Foo.Three => |pt| {
|
||||
assert(pt.x == 3);
|
||||
@@ -366,7 +366,7 @@ fn test3_1(f: &const Test3Foo) void {
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
fn test3_2(f: &const Test3Foo) void {
|
||||
fn test3_2(f: *const Test3Foo) void {
|
||||
switch (f.*) {
|
||||
Test3Foo.Two => |x| {
|
||||
assert(x == 13);
|
||||
@@ -393,7 +393,7 @@ test "pointer comparison" {
|
||||
const b = &a;
|
||||
assert(ptrEql(b, b));
|
||||
}
|
||||
fn ptrEql(a: &const []const u8, b: &const []const u8) bool {
|
||||
fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
@@ -446,13 +446,13 @@ fn testPointerToVoidReturnType() error!void {
|
||||
return a.*;
|
||||
}
|
||||
const test_pointer_to_void_return_type_x = void{};
|
||||
fn testPointerToVoidReturnType2() &const void {
|
||||
fn testPointerToVoidReturnType2() *const void {
|
||||
return &test_pointer_to_void_return_type_x;
|
||||
}
|
||||
|
||||
test "non const ptr to aliased type" {
|
||||
const int = i32;
|
||||
assert(?&int == ?&i32);
|
||||
assert(?*int == ?*i32);
|
||||
}
|
||||
|
||||
test "array 2D const double ptr" {
|
||||
@@ -463,7 +463,7 @@ test "array 2D const double ptr" {
|
||||
testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
|
||||
}
|
||||
|
||||
fn testArray2DConstDoublePtr(ptr: &const f32) void {
|
||||
fn testArray2DConstDoublePtr(ptr: *const f32) void {
|
||||
assert(ptr[0] == 1.0);
|
||||
assert(ptr[1] == 2.0);
|
||||
}
|
||||
@@ -497,7 +497,7 @@ test "@typeId" {
|
||||
assert(@typeId(u64) == Tid.Int);
|
||||
assert(@typeId(f32) == Tid.Float);
|
||||
assert(@typeId(f64) == Tid.Float);
|
||||
assert(@typeId(&f32) == Tid.Pointer);
|
||||
assert(@typeId(*f32) == Tid.Pointer);
|
||||
assert(@typeId([2]u8) == Tid.Array);
|
||||
assert(@typeId(AStruct) == Tid.Struct);
|
||||
assert(@typeId(@typeOf(1)) == Tid.IntLiteral);
|
||||
@@ -540,7 +540,7 @@ test "@typeName" {
|
||||
};
|
||||
comptime {
|
||||
assert(mem.eql(u8, @typeName(i64), "i64"));
|
||||
assert(mem.eql(u8, @typeName(&usize), "&usize"));
|
||||
assert(mem.eql(u8, @typeName(*usize), "*usize"));
|
||||
// https://github.com/ziglang/zig/issues/675
|
||||
assert(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));
|
||||
assert(mem.eql(u8, @typeName(Struct), "Struct"));
|
||||
@@ -555,7 +555,7 @@ fn TypeFromFn(comptime T: type) type {
|
||||
|
||||
test "volatile load and store" {
|
||||
var number: i32 = 1234;
|
||||
const ptr = (&volatile i32)(&number);
|
||||
const ptr = (*volatile i32)(&number);
|
||||
ptr.* += 1;
|
||||
assert(ptr.* == 1235);
|
||||
}
|
||||
@@ -587,28 +587,28 @@ var global_ptr = &gdt[0];
|
||||
|
||||
// can't really run this test but we can make sure it has no compile error
|
||||
// and generates code
|
||||
const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000];
|
||||
const vram = @intToPtr(*volatile u8, 0x20000000)[0..0x8000];
|
||||
export fn writeToVRam() void {
|
||||
vram[0] = 'X';
|
||||
}
|
||||
|
||||
test "pointer child field" {
|
||||
assert((&u32).Child == u32);
|
||||
assert((*u32).Child == u32);
|
||||
}
|
||||
|
||||
const OpaqueA = @OpaqueType();
|
||||
const OpaqueB = @OpaqueType();
|
||||
test "@OpaqueType" {
|
||||
assert(&OpaqueA != &OpaqueB);
|
||||
assert(*OpaqueA != *OpaqueB);
|
||||
assert(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
|
||||
assert(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
|
||||
}
|
||||
|
||||
test "variable is allowed to be a pointer to an opaque type" {
|
||||
var x: i32 = 1234;
|
||||
_ = hereIsAnOpaqueType(@ptrCast(&OpaqueA, &x));
|
||||
_ = hereIsAnOpaqueType(@ptrCast(*OpaqueA, &x));
|
||||
}
|
||||
fn hereIsAnOpaqueType(ptr: &OpaqueA) &OpaqueA {
|
||||
fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {
|
||||
var a = ptr;
|
||||
return a;
|
||||
}
|
||||
@@ -692,7 +692,7 @@ test "packed struct, enum, union parameters in extern function" {
|
||||
}, PackedUnion{ .a = 1 }, PackedEnum.A);
|
||||
}
|
||||
|
||||
export fn testPackedStuff(a: &const PackedStruct, b: &const PackedUnion, c: PackedEnum) void {}
|
||||
export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: PackedEnum) void {}
|
||||
|
||||
test "slicing zero length array" {
|
||||
const s1 = ""[0..];
|
||||
@@ -703,8 +703,8 @@ test "slicing zero length array" {
|
||||
assert(mem.eql(u32, s2, []u32{}));
|
||||
}
|
||||
|
||||
const addr1 = @ptrCast(&const u8, emptyFn);
|
||||
const addr1 = @ptrCast(*const u8, emptyFn);
|
||||
test "comptime cast fn to ptr" {
|
||||
const addr2 = @ptrCast(&const u8, emptyFn);
|
||||
const addr2 = @ptrCast(*const u8, emptyFn);
|
||||
comptime assert(addr1 == addr2);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ test "if var maybe pointer" {
|
||||
.d = 1,
|
||||
}) == 15);
|
||||
}
|
||||
fn shouldBeAPlus1(p: &const Particle) u64 {
|
||||
fn shouldBeAPlus1(p: *const Particle) u64 {
|
||||
var maybe_particle: ?Particle = p.*;
|
||||
if (maybe_particle) |*particle| {
|
||||
particle.a += 1;
|
||||
|
||||
@@ -5,7 +5,7 @@ const reflection = this;
|
||||
test "reflection: array, pointer, nullable, error union type child" {
|
||||
comptime {
|
||||
assert(([10]u8).Child == u8);
|
||||
assert((&u8).Child == u8);
|
||||
assert((*u8).Child == u8);
|
||||
assert((error!u8).Payload == u8);
|
||||
assert((?u8).Child == u8);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const assert = @import("std").debug.assert;
|
||||
const mem = @import("std").mem;
|
||||
|
||||
const x = @intToPtr(&i32, 0x1000)[0..0x500];
|
||||
const x = @intToPtr(*i32, 0x1000)[0..0x500];
|
||||
const y = x[0x100..];
|
||||
test "compile time slice of pointer to hard coded address" {
|
||||
assert(@ptrToInt(x.ptr) == 0x1000);
|
||||
|
||||
@@ -43,7 +43,7 @@ const VoidStructFieldsFoo = struct {
|
||||
|
||||
test "structs" {
|
||||
var foo: StructFoo = undefined;
|
||||
@memset(@ptrCast(&u8, &foo), 0, @sizeOf(StructFoo));
|
||||
@memset(@ptrCast(*u8, &foo), 0, @sizeOf(StructFoo));
|
||||
foo.a += 1;
|
||||
foo.b = foo.a == 1;
|
||||
testFoo(foo);
|
||||
@@ -55,16 +55,16 @@ const StructFoo = struct {
|
||||
b: bool,
|
||||
c: f32,
|
||||
};
|
||||
fn testFoo(foo: &const StructFoo) void {
|
||||
fn testFoo(foo: *const StructFoo) void {
|
||||
assert(foo.b);
|
||||
}
|
||||
fn testMutation(foo: &StructFoo) void {
|
||||
fn testMutation(foo: *StructFoo) void {
|
||||
foo.c = 100;
|
||||
}
|
||||
|
||||
const Node = struct {
|
||||
val: Val,
|
||||
next: &Node,
|
||||
next: *Node,
|
||||
};
|
||||
|
||||
const Val = struct {
|
||||
@@ -112,7 +112,7 @@ fn aFunc() i32 {
|
||||
return 13;
|
||||
}
|
||||
|
||||
fn callStructField(foo: &const Foo) i32 {
|
||||
fn callStructField(foo: *const Foo) i32 {
|
||||
return foo.ptr();
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ test "store member function in variable" {
|
||||
}
|
||||
const MemberFnTestFoo = struct {
|
||||
x: i32,
|
||||
fn member(foo: &const MemberFnTestFoo) i32 {
|
||||
fn member(foo: *const MemberFnTestFoo) i32 {
|
||||
return foo.x;
|
||||
}
|
||||
};
|
||||
@@ -141,7 +141,7 @@ test "member functions" {
|
||||
}
|
||||
const MemberFnRand = struct {
|
||||
seed: u32,
|
||||
pub fn getSeed(r: &const MemberFnRand) u32 {
|
||||
pub fn getSeed(r: *const MemberFnRand) u32 {
|
||||
return r.seed;
|
||||
}
|
||||
};
|
||||
@@ -166,7 +166,7 @@ test "empty struct method call" {
|
||||
assert(es.method() == 1234);
|
||||
}
|
||||
const EmptyStruct = struct {
|
||||
fn method(es: &const EmptyStruct) i32 {
|
||||
fn method(es: *const EmptyStruct) i32 {
|
||||
return 1234;
|
||||
}
|
||||
};
|
||||
@@ -228,15 +228,15 @@ test "bit field access" {
|
||||
assert(data.b == 3);
|
||||
}
|
||||
|
||||
fn getA(data: &const BitField1) u3 {
|
||||
fn getA(data: *const BitField1) u3 {
|
||||
return data.a;
|
||||
}
|
||||
|
||||
fn getB(data: &const BitField1) u3 {
|
||||
fn getB(data: *const BitField1) u3 {
|
||||
return data.b;
|
||||
}
|
||||
|
||||
fn getC(data: &const BitField1) u2 {
|
||||
fn getC(data: *const BitField1) u2 {
|
||||
return data.c;
|
||||
}
|
||||
|
||||
@@ -396,8 +396,8 @@ const Bitfields = packed struct {
|
||||
test "native bit field understands endianness" {
|
||||
var all: u64 = 0x7765443322221111;
|
||||
var bytes: [8]u8 = undefined;
|
||||
@memcpy(&bytes[0], @ptrCast(&u8, &all), 8);
|
||||
var bitfields = @ptrCast(&Bitfields, &bytes[0]).*;
|
||||
@memcpy(&bytes[0], @ptrCast(*u8, &all), 8);
|
||||
var bitfields = @ptrCast(*Bitfields, &bytes[0]).*;
|
||||
|
||||
assert(bitfields.f1 == 0x1111);
|
||||
assert(bitfields.f2 == 0x2222);
|
||||
@@ -415,7 +415,7 @@ test "align 1 field before self referential align 8 field as slice return type"
|
||||
|
||||
const Expr = union(enum) {
|
||||
Literal: u8,
|
||||
Question: &Expr,
|
||||
Question: *Expr,
|
||||
};
|
||||
|
||||
fn alloc(comptime T: type) []T {
|
||||
|
||||
@@ -2,13 +2,13 @@ const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
test "struct contains null pointer which contains original struct" {
|
||||
var x: ?&NodeLineComment = null;
|
||||
var x: ?*NodeLineComment = null;
|
||||
assert(x == null);
|
||||
}
|
||||
|
||||
pub const Node = struct {
|
||||
id: Id,
|
||||
comment: ?&NodeLineComment,
|
||||
comment: ?*NodeLineComment,
|
||||
|
||||
pub const Id = enum {
|
||||
Root,
|
||||
|
||||
@@ -90,7 +90,7 @@ const SwitchProngWithVarEnum = union(enum) {
|
||||
Two: f32,
|
||||
Meh: void,
|
||||
};
|
||||
fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) void {
|
||||
fn switchProngWithVarFn(a: *const SwitchProngWithVarEnum) void {
|
||||
switch (a.*) {
|
||||
SwitchProngWithVarEnum.One => |x| {
|
||||
assert(x == 13);
|
||||
|
||||
@@ -8,7 +8,7 @@ fn Point(comptime T: type) type {
|
||||
x: T,
|
||||
y: T,
|
||||
|
||||
fn addOne(self: &Self) void {
|
||||
fn addOne(self: *Self) void {
|
||||
self.x += 1;
|
||||
self.y += 1;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ test "type info: pointer type info" {
|
||||
}
|
||||
|
||||
fn testPointer() void {
|
||||
const u32_ptr_info = @typeInfo(&u32);
|
||||
const u32_ptr_info = @typeInfo(*u32);
|
||||
assert(TypeId(u32_ptr_info) == TypeId.Pointer);
|
||||
assert(u32_ptr_info.Pointer.is_const == false);
|
||||
assert(u32_ptr_info.Pointer.is_volatile == false);
|
||||
@@ -169,14 +169,14 @@ fn testUnion() void {
|
||||
assert(notag_union_info.Union.fields[1].field_type == u32);
|
||||
|
||||
const TestExternUnion = extern union {
|
||||
foo: &c_void,
|
||||
foo: *c_void,
|
||||
};
|
||||
|
||||
const extern_union_info = @typeInfo(TestExternUnion);
|
||||
assert(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);
|
||||
assert(extern_union_info.Union.tag_type == @typeOf(undefined));
|
||||
assert(extern_union_info.Union.fields[0].enum_field == null);
|
||||
assert(extern_union_info.Union.fields[0].field_type == &c_void);
|
||||
assert(extern_union_info.Union.fields[0].field_type == *c_void);
|
||||
}
|
||||
|
||||
test "type info: struct info" {
|
||||
@@ -190,13 +190,13 @@ fn testStruct() void {
|
||||
assert(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
|
||||
assert(struct_info.Struct.fields.len == 3);
|
||||
assert(struct_info.Struct.fields[1].offset == null);
|
||||
assert(struct_info.Struct.fields[2].field_type == &TestStruct);
|
||||
assert(struct_info.Struct.fields[2].field_type == *TestStruct);
|
||||
assert(struct_info.Struct.defs.len == 2);
|
||||
assert(struct_info.Struct.defs[0].is_pub);
|
||||
assert(!struct_info.Struct.defs[0].data.Fn.is_extern);
|
||||
assert(struct_info.Struct.defs[0].data.Fn.lib_name == null);
|
||||
assert(struct_info.Struct.defs[0].data.Fn.return_type == void);
|
||||
assert(struct_info.Struct.defs[0].data.Fn.fn_type == fn (&const TestStruct) void);
|
||||
assert(struct_info.Struct.defs[0].data.Fn.fn_type == fn (*const TestStruct) void);
|
||||
}
|
||||
|
||||
const TestStruct = packed struct {
|
||||
@@ -204,9 +204,9 @@ const TestStruct = packed struct {
|
||||
|
||||
fieldA: usize,
|
||||
fieldB: void,
|
||||
fieldC: &Self,
|
||||
fieldC: *Self,
|
||||
|
||||
pub fn foo(self: &const Self) void {}
|
||||
pub fn foo(self: *const Self) void {}
|
||||
};
|
||||
|
||||
test "type info: function type info" {
|
||||
@@ -227,7 +227,7 @@ fn testFunction() void {
|
||||
const test_instance: TestStruct = undefined;
|
||||
const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));
|
||||
assert(TypeId(bound_fn_info) == TypeId.BoundFn);
|
||||
assert(bound_fn_info.BoundFn.args[0].arg_type == &const TestStruct);
|
||||
assert(bound_fn_info.BoundFn.args[0].arg_type == *const TestStruct);
|
||||
}
|
||||
|
||||
fn foo(comptime a: usize, b: bool, args: ...) usize {
|
||||
|
||||
@@ -27,12 +27,12 @@ test "init static array to undefined" {
|
||||
const Foo = struct {
|
||||
x: i32,
|
||||
|
||||
fn setFooXMethod(foo: &Foo) void {
|
||||
fn setFooXMethod(foo: *Foo) void {
|
||||
foo.x = 3;
|
||||
}
|
||||
};
|
||||
|
||||
fn setFooX(foo: &Foo) void {
|
||||
fn setFooX(foo: *Foo) void {
|
||||
foo.x = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,11 +68,11 @@ test "init union with runtime value" {
|
||||
assert(foo.int == 42);
|
||||
}
|
||||
|
||||
fn setFloat(foo: &Foo, x: f64) void {
|
||||
fn setFloat(foo: *Foo, x: f64) void {
|
||||
foo.* = Foo{ .float = x };
|
||||
}
|
||||
|
||||
fn setInt(foo: &Foo, x: i32) void {
|
||||
fn setInt(foo: *Foo, x: i32) void {
|
||||
foo.* = Foo{ .int = x };
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ fn doTest() void {
|
||||
assert(bar(Payload{ .A = 1234 }) == -10);
|
||||
}
|
||||
|
||||
fn bar(value: &const Payload) i32 {
|
||||
fn bar(value: *const Payload) i32 {
|
||||
assert(Letter(value.*) == Letter.A);
|
||||
return switch (value.*) {
|
||||
Payload.A => |x| return x - 1244,
|
||||
@@ -147,7 +147,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {
|
||||
comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
|
||||
}
|
||||
|
||||
fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void {
|
||||
fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: *const MultipleChoice2) void {
|
||||
assert(u32(@TagType(MultipleChoice2)(x.*)) == 60);
|
||||
assert(1123 == switch (x.*) {
|
||||
MultipleChoice2.A => 1,
|
||||
@@ -163,7 +163,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void
|
||||
}
|
||||
|
||||
const ExternPtrOrInt = extern union {
|
||||
ptr: &u8,
|
||||
ptr: *u8,
|
||||
int: u64,
|
||||
};
|
||||
test "extern union size" {
|
||||
@@ -171,7 +171,7 @@ test "extern union size" {
|
||||
}
|
||||
|
||||
const PackedPtrOrInt = packed union {
|
||||
ptr: &u8,
|
||||
ptr: *u8,
|
||||
int: u64,
|
||||
};
|
||||
test "extern union size" {
|
||||
@@ -206,7 +206,7 @@ test "cast union to tag type of union" {
|
||||
comptime testCastUnionToTagType(TheUnion{ .B = 1234 });
|
||||
}
|
||||
|
||||
fn testCastUnionToTagType(x: &const TheUnion) void {
|
||||
fn testCastUnionToTagType(x: *const TheUnion) void {
|
||||
assert(TheTag(x.*) == TheTag.B);
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ const TheUnion2 = union(enum) {
|
||||
Item2: i32,
|
||||
};
|
||||
|
||||
fn assertIsTheUnion2Item1(value: &const TheUnion2) void {
|
||||
fn assertIsTheUnion2Item1(value: *const TheUnion2) void {
|
||||
assert(value.* == TheUnion2.Item1);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ const std = @import("std");
|
||||
const os = std.os;
|
||||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: &tests.CompareOutputContext) void {
|
||||
pub fn addCases(cases: *tests.CompareOutputContext) void {
|
||||
cases.addC("hello world with libc",
|
||||
\\const c = @cImport(@cInclude("stdio.h"));
|
||||
\\export fn main(argc: c_int, argv: &&u8) c_int {
|
||||
\\export fn main(argc: c_int, argv: **u8) c_int {
|
||||
\\ _ = c.puts(c"Hello, world!");
|
||||
\\ return 0;
|
||||
\\}
|
||||
@@ -139,7 +139,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
|
||||
\\ @cInclude("stdio.h");
|
||||
\\});
|
||||
\\
|
||||
\\export fn main(argc: c_int, argv: &&u8) c_int {
|
||||
\\export fn main(argc: c_int, argv: **u8) c_int {
|
||||
\\ if (is_windows) {
|
||||
\\ // we want actual \n, not \r\n
|
||||
\\ _ = c._setmode(1, c._O_BINARY);
|
||||
@@ -284,9 +284,9 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
|
||||
cases.addC("expose function pointer to C land",
|
||||
\\const c = @cImport(@cInclude("stdlib.h"));
|
||||
\\
|
||||
\\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) c_int {
|
||||
\\ const a_int = @ptrCast(&align(1) const i32, a ?? unreachable);
|
||||
\\ const b_int = @ptrCast(&align(1) const i32, b ?? unreachable);
|
||||
\\export fn compare_fn(a: ?*const c_void, b: ?*const c_void) c_int {
|
||||
\\ const a_int = @ptrCast(*align(1) const i32, a ?? unreachable);
|
||||
\\ const b_int = @ptrCast(*align(1) const i32, b ?? unreachable);
|
||||
\\ if (a_int.* < b_int.*) {
|
||||
\\ return -1;
|
||||
\\ } else if (a_int.* > b_int.*) {
|
||||
@@ -299,7 +299,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
|
||||
\\export fn main() c_int {
|
||||
\\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
|
||||
\\
|
||||
\\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);
|
||||
\\ c.qsort(@ptrCast(*c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);
|
||||
\\
|
||||
\\ for (array) |item, i| {
|
||||
\\ if (item != i) {
|
||||
@@ -324,7 +324,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
|
||||
\\ @cInclude("stdio.h");
|
||||
\\});
|
||||
\\
|
||||
\\export fn main(argc: c_int, argv: &&u8) c_int {
|
||||
\\export fn main(argc: c_int, argv: **u8) c_int {
|
||||
\\ if (is_windows) {
|
||||
\\ // we want actual \n, not \r\n
|
||||
\\ _ = c._setmode(1, c._O_BINARY);
|
||||
@@ -344,13 +344,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
|
||||
\\const Foo = struct {
|
||||
\\ field1: Bar,
|
||||
\\
|
||||
\\ fn method(a: &const Foo) bool { return true; }
|
||||
\\ fn method(a: *const Foo) bool { return true; }
|
||||
\\};
|
||||
\\
|
||||
\\const Bar = struct {
|
||||
\\ field2: i32,
|
||||
\\
|
||||
\\ fn method(b: &const Bar) bool { return true; }
|
||||
\\ fn method(b: *const Bar) bool { return true; }
|
||||
\\};
|
||||
\\
|
||||
\\pub fn main() void {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"invalid deref on switch target",
|
||||
\\comptime {
|
||||
@@ -109,7 +109,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
"@ptrCast discards const qualifier",
|
||||
\\export fn entry() void {
|
||||
\\ const x: i32 = 1234;
|
||||
\\ const y = @ptrCast(&i32, &x);
|
||||
\\ const y = @ptrCast(*i32, &x);
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:3:15: error: cast discards const qualifier",
|
||||
@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"comptime slice of undefined pointer non-zero len",
|
||||
\\export fn entry() void {
|
||||
\\ const slice = (&i32)(undefined)[0..1];
|
||||
\\ const slice = (*i32)(undefined)[0..1];
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:2:36: error: non-zero length slice of undefined pointer",
|
||||
@@ -126,7 +126,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
|
||||
cases.add(
|
||||
"type checking function pointers",
|
||||
\\fn a(b: fn (&const u8) void) void {
|
||||
\\fn a(b: fn (*const u8) void) void {
|
||||
\\ b('a');
|
||||
\\}
|
||||
\\fn c(d: u8) void {
|
||||
@@ -136,7 +136,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ a(c);
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:8:7: error: expected type 'fn(&const u8) void', found 'fn(u8) void'",
|
||||
".tmp_source.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -594,15 +594,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
|
||||
cases.add(
|
||||
"attempt to use 0 bit type in extern fn",
|
||||
\\extern fn foo(ptr: extern fn(&void) void) void;
|
||||
\\extern fn foo(ptr: extern fn(*void) void) void;
|
||||
\\
|
||||
\\export fn entry() void {
|
||||
\\ foo(bar);
|
||||
\\}
|
||||
\\
|
||||
\\extern fn bar(x: &void) void { }
|
||||
\\extern fn bar(x: *void) void { }
|
||||
,
|
||||
".tmp_source.zig:7:18: error: parameter of type '&void' has 0 bits; not allowed in function with calling convention 'ccc'",
|
||||
".tmp_source.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -911,10 +911,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
|
||||
cases.add(
|
||||
"pointer to noreturn",
|
||||
\\fn a() &noreturn {}
|
||||
\\fn a() *noreturn {}
|
||||
\\export fn entry() void { _ = a(); }
|
||||
,
|
||||
".tmp_source.zig:1:9: error: pointer to noreturn not allowed",
|
||||
".tmp_source.zig:1:8: error: pointer to noreturn not allowed",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -985,7 +985,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ return a;
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:3:12: error: expected type 'i32', found '&const u8'",
|
||||
".tmp_source.zig:3:12: error: expected type 'i32', found '*const u8'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -1446,7 +1446,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
|
||||
cases.add(
|
||||
"switch expression - switch on pointer type with no else",
|
||||
\\fn foo(x: &u8) void {
|
||||
\\fn foo(x: *u8) void {
|
||||
\\ switch (x) {
|
||||
\\ &y => {},
|
||||
\\ }
|
||||
@@ -1454,7 +1454,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\const y: u8 = 100;
|
||||
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
|
||||
,
|
||||
".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'",
|
||||
".tmp_source.zig:2:5: error: else prong required when switching on type '*u8'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -1501,10 +1501,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
"address of number literal",
|
||||
\\const x = 3;
|
||||
\\const y = &x;
|
||||
\\fn foo() &const i32 { return y; }
|
||||
\\fn foo() *const i32 { return y; }
|
||||
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
|
||||
,
|
||||
".tmp_source.zig:3:30: error: expected type '&const i32', found '&const (integer literal)'",
|
||||
".tmp_source.zig:3:30: error: expected type '*const i32', found '*const (integer literal)'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -1529,10 +1529,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ a: i32,
|
||||
\\ b: i32,
|
||||
\\
|
||||
\\ fn member_a(foo: &const Foo) i32 {
|
||||
\\ fn member_a(foo: *const Foo) i32 {
|
||||
\\ return foo.a;
|
||||
\\ }
|
||||
\\ fn member_b(foo: &const Foo) i32 {
|
||||
\\ fn member_b(foo: *const Foo) i32 {
|
||||
\\ return foo.b;
|
||||
\\ }
|
||||
\\};
|
||||
@@ -1543,7 +1543,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ Foo.member_b,
|
||||
\\};
|
||||
\\
|
||||
\\fn f(foo: &const Foo, index: usize) void {
|
||||
\\fn f(foo: *const Foo, index: usize) void {
|
||||
\\ const result = members[index]();
|
||||
\\}
|
||||
\\
|
||||
@@ -1692,11 +1692,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
|
||||
cases.add(
|
||||
"assign null to non-nullable pointer",
|
||||
\\const a: &u8 = null;
|
||||
\\const a: *u8 = null;
|
||||
\\
|
||||
\\export fn entry() usize { return @sizeOf(@typeOf(a)); }
|
||||
,
|
||||
".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'",
|
||||
".tmp_source.zig:1:16: error: expected type '*u8', found '(null)'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -1806,7 +1806,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ One: void,
|
||||
\\ Two: i32,
|
||||
\\};
|
||||
\\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) bool {
|
||||
\\fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
|
||||
\\ return a.* == b.*;
|
||||
\\}
|
||||
\\
|
||||
@@ -2011,9 +2011,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"wrong number of arguments for method fn call",
|
||||
\\const Foo = struct {
|
||||
\\ fn method(self: &const Foo, a: i32) void {}
|
||||
\\ fn method(self: *const Foo, a: i32) void {}
|
||||
\\};
|
||||
\\fn f(foo: &const Foo) void {
|
||||
\\fn f(foo: *const Foo) void {
|
||||
\\
|
||||
\\ foo.method(1, 2);
|
||||
\\}
|
||||
@@ -2062,7 +2062,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"misspelled type with pointer only reference",
|
||||
\\const JasonHM = u8;
|
||||
\\const JasonList = &JsonNode;
|
||||
\\const JasonList = *JsonNode;
|
||||
\\
|
||||
\\const JsonOA = union(enum) {
|
||||
\\ JSONArray: JsonList,
|
||||
@@ -2113,16 +2113,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ derp.init();
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:14:5: error: expected type 'i32', found '&const Foo'",
|
||||
".tmp_source.zig:14:5: error: expected type 'i32', found '*const Foo'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"method call with first arg type wrong container",
|
||||
\\pub const List = struct {
|
||||
\\ len: usize,
|
||||
\\ allocator: &Allocator,
|
||||
\\ allocator: *Allocator,
|
||||
\\
|
||||
\\ pub fn init(allocator: &Allocator) List {
|
||||
\\ pub fn init(allocator: *Allocator) List {
|
||||
\\ return List {
|
||||
\\ .len = 0,
|
||||
\\ .allocator = allocator,
|
||||
@@ -2143,7 +2143,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ x.init();
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:23:5: error: expected type '&Allocator', found '&List'",
|
||||
".tmp_source.zig:23:5: error: expected type '*Allocator', found '*List'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -2308,17 +2308,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ c: u2,
|
||||
\\};
|
||||
\\
|
||||
\\fn foo(bit_field: &const BitField) u3 {
|
||||
\\fn foo(bit_field: *const BitField) u3 {
|
||||
\\ return bar(&bit_field.b);
|
||||
\\}
|
||||
\\
|
||||
\\fn bar(x: &const u3) u3 {
|
||||
\\fn bar(x: *const u3) u3 {
|
||||
\\ return x.*;
|
||||
\\}
|
||||
\\
|
||||
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
|
||||
,
|
||||
".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'",
|
||||
".tmp_source.zig:8:26: error: expected type '*const u3', found '*align(1:3:6) const u3'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -2441,13 +2441,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ const b = &a;
|
||||
\\ return ptrEql(b, b);
|
||||
\\}
|
||||
\\fn ptrEql(a: &[]const u8, b: &[]const u8) bool {
|
||||
\\fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
|
||||
\\ return true;
|
||||
\\}
|
||||
\\
|
||||
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
|
||||
,
|
||||
".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'",
|
||||
".tmp_source.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",
|
||||
);
|
||||
|
||||
cases.addCase(x: {
|
||||
@@ -2493,7 +2493,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
|
||||
cases.add(
|
||||
"ptrcast to non-pointer",
|
||||
\\export fn entry(a: &i32) usize {
|
||||
\\export fn entry(a: *i32) usize {
|
||||
\\ return @ptrCast(usize, a);
|
||||
\\}
|
||||
,
|
||||
@@ -2542,16 +2542,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
"int to ptr of 0 bits",
|
||||
\\export fn foo() void {
|
||||
\\ var x: usize = 0x1000;
|
||||
\\ var y: &void = @intToPtr(&void, x);
|
||||
\\ var y: *void = @intToPtr(*void, x);
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:3:31: error: type '&void' has 0 bits and cannot store information",
|
||||
".tmp_source.zig:3:30: error: type '*void' has 0 bits and cannot store information",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"@fieldParentPtr - non struct",
|
||||
\\const Foo = i32;
|
||||
\\export fn foo(a: &i32) &Foo {
|
||||
\\export fn foo(a: *i32) *Foo {
|
||||
\\ return @fieldParentPtr(Foo, "a", a);
|
||||
\\}
|
||||
,
|
||||
@@ -2563,7 +2563,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\const Foo = extern struct {
|
||||
\\ derp: i32,
|
||||
\\};
|
||||
\\export fn foo(a: &i32) &Foo {
|
||||
\\export fn foo(a: *i32) *Foo {
|
||||
\\ return @fieldParentPtr(Foo, "a", a);
|
||||
\\}
|
||||
,
|
||||
@@ -2575,7 +2575,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\const Foo = extern struct {
|
||||
\\ a: i32,
|
||||
\\};
|
||||
\\export fn foo(a: i32) &Foo {
|
||||
\\export fn foo(a: i32) *Foo {
|
||||
\\ return @fieldParentPtr(Foo, "a", a);
|
||||
\\}
|
||||
,
|
||||
@@ -2591,7 +2591,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\const foo = Foo { .a = 1, .b = 2, };
|
||||
\\
|
||||
\\comptime {
|
||||
\\ const field_ptr = @intToPtr(&i32, 0x1234);
|
||||
\\ const field_ptr = @intToPtr(*i32, 0x1234);
|
||||
\\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
|
||||
\\}
|
||||
,
|
||||
@@ -2682,7 +2682,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
|
||||
cases.add(
|
||||
"returning address of local variable - simple",
|
||||
\\export fn foo() &i32 {
|
||||
\\export fn foo() *i32 {
|
||||
\\ var a: i32 = undefined;
|
||||
\\ return &a;
|
||||
\\}
|
||||
@@ -2692,7 +2692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
|
||||
cases.add(
|
||||
"returning address of local variable - phi",
|
||||
\\export fn foo(c: bool) &i32 {
|
||||
\\export fn foo(c: bool) *i32 {
|
||||
\\ var a: i32 = undefined;
|
||||
\\ var b: i32 = undefined;
|
||||
\\ return if (c) &a else &b;
|
||||
@@ -3086,11 +3086,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ bar(&foo.b);
|
||||
\\}
|
||||
\\
|
||||
\\fn bar(x: &u32) void {
|
||||
\\fn bar(x: *u32) void {
|
||||
\\ x.* += 1;
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:8:13: error: expected type '&u32', found '&align(1) u32'",
|
||||
".tmp_source.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -3117,13 +3117,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
"increase pointer alignment in @ptrCast",
|
||||
\\export fn entry() u32 {
|
||||
\\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04};
|
||||
\\ const ptr = @ptrCast(&u32, &bytes[0]);
|
||||
\\ const ptr = @ptrCast(*u32, &bytes[0]);
|
||||
\\ return ptr.*;
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:3:17: error: cast increases pointer alignment",
|
||||
".tmp_source.zig:3:38: note: '&u8' has alignment 1",
|
||||
".tmp_source.zig:3:27: note: '&u32' has alignment 4",
|
||||
".tmp_source.zig:3:38: note: '*u8' has alignment 1",
|
||||
".tmp_source.zig:3:26: note: '*u32' has alignment 4",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -3169,7 +3169,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ return x == 5678;
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:4:32: error: expected type '&i32', found '&align(1) i32'",
|
||||
".tmp_source.zig:4:32: error: expected type '*i32', found '*align(1) i32'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -3198,20 +3198,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"wrong pointer implicitly casted to pointer to @OpaqueType()",
|
||||
\\const Derp = @OpaqueType();
|
||||
\\extern fn bar(d: &Derp) void;
|
||||
\\extern fn bar(d: *Derp) void;
|
||||
\\export fn foo() void {
|
||||
\\ var x = u8(1);
|
||||
\\ bar(@ptrCast(&c_void, &x));
|
||||
\\ bar(@ptrCast(*c_void, &x));
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:5:9: error: expected type '&Derp', found '&c_void'",
|
||||
".tmp_source.zig:5:9: error: expected type '*Derp', found '*c_void'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"non-const variables of things that require const variables",
|
||||
\\const Opaque = @OpaqueType();
|
||||
\\
|
||||
\\export fn entry(opaque: &Opaque) void {
|
||||
\\export fn entry(opaque: *Opaque) void {
|
||||
\\ var m2 = &2;
|
||||
\\ const y: u32 = m2.*;
|
||||
\\
|
||||
@@ -3229,10 +3229,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\}
|
||||
\\
|
||||
\\const Foo = struct {
|
||||
\\ fn bar(self: &const Foo) void {}
|
||||
\\ fn bar(self: *const Foo) void {}
|
||||
\\};
|
||||
,
|
||||
".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime",
|
||||
".tmp_source.zig:4:4: error: variable of type '*const (integer literal)' must be const or comptime",
|
||||
".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",
|
||||
".tmp_source.zig:8:4: error: variable of type '(integer literal)' must be const or comptime",
|
||||
".tmp_source.zig:9:4: error: variable of type '(float literal)' must be const or comptime",
|
||||
@@ -3241,7 +3241,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime",
|
||||
".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime",
|
||||
".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime",
|
||||
".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo) void)' must be const or comptime",
|
||||
".tmp_source.zig:15:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
|
||||
".tmp_source.zig:17:4: error: unreachable code",
|
||||
);
|
||||
|
||||
@@ -3397,14 +3397,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\
|
||||
\\export fn entry() bool {
|
||||
\\ var x: i32 = 1;
|
||||
\\ return bar(@ptrCast(&MyType, &x));
|
||||
\\ return bar(@ptrCast(*MyType, &x));
|
||||
\\}
|
||||
\\
|
||||
\\fn bar(x: &MyType) bool {
|
||||
\\fn bar(x: *MyType) bool {
|
||||
\\ return x.blah;
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:9:13: error: type '&MyType' does not support field access",
|
||||
".tmp_source.zig:9:13: error: type '*MyType' does not support field access",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -3535,9 +3535,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\export fn entry() void {
|
||||
\\ foo("hello",);
|
||||
\\}
|
||||
\\pub extern fn foo(format: &const u8, ...) void;
|
||||
\\pub extern fn foo(format: *const u8, ...) void;
|
||||
,
|
||||
".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'",
|
||||
".tmp_source.zig:2:9: error: expected type '*const u8', found '[5]u8'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
@@ -3902,7 +3902,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
||||
\\ const a = Payload { .A = 1234 };
|
||||
\\ foo(a);
|
||||
\\}
|
||||
\\fn foo(a: &const Payload) void {
|
||||
\\fn foo(a: *const Payload) void {
|
||||
\\ switch (a.*) {
|
||||
\\ Payload.A => {},
|
||||
\\ else => unreachable,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: &tests.GenHContext) void {
|
||||
pub fn addCases(cases: *tests.GenHContext) void {
|
||||
cases.add("declare enum",
|
||||
\\const Foo = extern enum { A, B, C };
|
||||
\\export fn entry(foo: Foo) void { }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: &tests.CompareOutputContext) void {
|
||||
pub fn addCases(cases: *tests.CompareOutputContext) void {
|
||||
cases.addRuntimeSafety("calling panic",
|
||||
\\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
|
||||
\\ @import("std").os.exit(126);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Builder = @import("std").build.Builder;
|
||||
|
||||
pub fn build(b: &Builder) void {
|
||||
pub fn build(b: *Builder) void {
|
||||
const main = b.addTest("main.zig");
|
||||
main.setBuildMode(b.standardReleaseOptions());
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ const Token = union(enum) {
|
||||
Eof,
|
||||
};
|
||||
|
||||
var global_allocator: &mem.Allocator = undefined;
|
||||
var global_allocator: *mem.Allocator = undefined;
|
||||
|
||||
fn tokenize(input: []const u8) !ArrayList(Token) {
|
||||
const State = enum {
|
||||
@@ -73,7 +73,7 @@ const ParseError = error{
|
||||
OutOfMemory,
|
||||
};
|
||||
|
||||
fn parse(tokens: &const ArrayList(Token), token_index: &usize) ParseError!Node {
|
||||
fn parse(tokens: *const ArrayList(Token), token_index: *usize) ParseError!Node {
|
||||
const first_token = tokens.items[token_index.*];
|
||||
token_index.* += 1;
|
||||
|
||||
@@ -109,7 +109,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) ParseError!Node {
|
||||
}
|
||||
}
|
||||
|
||||
fn expandString(input: []const u8, output: &Buffer) !void {
|
||||
fn expandString(input: []const u8, output: *Buffer) !void {
|
||||
const tokens = try tokenize(input);
|
||||
if (tokens.len == 1) {
|
||||
return output.resize(0);
|
||||
@@ -139,7 +139,7 @@ fn expandString(input: []const u8, output: &Buffer) !void {
|
||||
|
||||
const ExpandNodeError = error{OutOfMemory};
|
||||
|
||||
fn expandNode(node: &const Node, output: &ArrayList(Buffer)) ExpandNodeError!void {
|
||||
fn expandNode(node: *const Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
|
||||
assert(output.len == 0);
|
||||
switch (node.*) {
|
||||
Node.Scalar => |scalar| {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Builder = @import("std").build.Builder;
|
||||
|
||||
pub fn build(b: &Builder) void {
|
||||
pub fn build(b: *Builder) void {
|
||||
const obj = b.addObject("test", "test.zig");
|
||||
|
||||
const test_step = b.step("test", "Test the program");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const StackTrace = @import("builtin").StackTrace;
|
||||
pub fn panic(msg: []const u8, stack_trace: ?&StackTrace) noreturn {
|
||||
pub fn panic(msg: []const u8, stack_trace: ?*StackTrace) noreturn {
|
||||
@breakpoint();
|
||||
while (true) {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Builder = @import("std").build.Builder;
|
||||
|
||||
pub fn build(b: &Builder) void {
|
||||
pub fn build(b: *Builder) void {
|
||||
const test_artifact = b.addTest("main.zig");
|
||||
test_artifact.addIncludeDir("a_directory");
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Builder = @import("std").build.Builder;
|
||||
|
||||
pub fn build(b: &Builder) void {
|
||||
pub fn build(b: *Builder) void {
|
||||
const exe = b.addExecutable("test", "test.zig");
|
||||
exe.addPackagePath("my_pkg", "pkg.zig");
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Builder = @import("std").build.Builder;
|
||||
|
||||
pub fn build(b: &Builder) void {
|
||||
pub fn build(b: *Builder) void {
|
||||
b.addCIncludePath(".");
|
||||
|
||||
const main = b.addTest("main.zig");
|
||||
|
||||
136
test/tests.zig
136
test/tests.zig
@@ -47,7 +47,7 @@ const test_targets = []TestTarget{
|
||||
|
||||
const max_stdout_size = 1 * 1024 * 1024; // 1 MB
|
||||
|
||||
pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
|
||||
pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
cases.* = CompareOutputContext{
|
||||
.b = b,
|
||||
@@ -61,7 +61,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build
|
||||
return cases.step;
|
||||
}
|
||||
|
||||
pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
|
||||
pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
cases.* = CompareOutputContext{
|
||||
.b = b,
|
||||
@@ -75,7 +75,7 @@ pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build
|
||||
return cases.step;
|
||||
}
|
||||
|
||||
pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
|
||||
pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
||||
const cases = b.allocator.create(CompileErrorContext) catch unreachable;
|
||||
cases.* = CompileErrorContext{
|
||||
.b = b,
|
||||
@@ -89,7 +89,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build.
|
||||
return cases.step;
|
||||
}
|
||||
|
||||
pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
|
||||
pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
||||
const cases = b.allocator.create(BuildExamplesContext) catch unreachable;
|
||||
cases.* = BuildExamplesContext{
|
||||
.b = b,
|
||||
@@ -103,7 +103,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build.
|
||||
return cases.step;
|
||||
}
|
||||
|
||||
pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
|
||||
pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
cases.* = CompareOutputContext{
|
||||
.b = b,
|
||||
@@ -117,7 +117,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &bui
|
||||
return cases.step;
|
||||
}
|
||||
|
||||
pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
|
||||
pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
||||
const cases = b.allocator.create(TranslateCContext) catch unreachable;
|
||||
cases.* = TranslateCContext{
|
||||
.b = b,
|
||||
@@ -131,7 +131,7 @@ pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.St
|
||||
return cases.step;
|
||||
}
|
||||
|
||||
pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
|
||||
pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
||||
const cases = b.allocator.create(GenHContext) catch unreachable;
|
||||
cases.* = GenHContext{
|
||||
.b = b,
|
||||
@@ -145,7 +145,7 @@ pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
|
||||
return cases.step;
|
||||
}
|
||||
|
||||
pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, name: []const u8, desc: []const u8, with_lldb: bool) &build.Step {
|
||||
pub fn addPkgTests(b: *build.Builder, test_filter: ?[]const u8, root_src: []const u8, name: []const u8, desc: []const u8, with_lldb: bool) *build.Step {
|
||||
const step = b.step(b.fmt("test-{}", name), desc);
|
||||
for (test_targets) |test_target| {
|
||||
const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
|
||||
@@ -193,8 +193,8 @@ pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []cons
|
||||
}
|
||||
|
||||
pub const CompareOutputContext = struct {
|
||||
b: &build.Builder,
|
||||
step: &build.Step,
|
||||
b: *build.Builder,
|
||||
step: *build.Step,
|
||||
test_index: usize,
|
||||
test_filter: ?[]const u8,
|
||||
|
||||
@@ -217,28 +217,28 @@ pub const CompareOutputContext = struct {
|
||||
source: []const u8,
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
|
||||
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
||||
self.sources.append(SourceFile{
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) void {
|
||||
pub fn setCommandLineArgs(self: *TestCase, args: []const []const u8) void {
|
||||
self.cli_args = args;
|
||||
}
|
||||
};
|
||||
|
||||
const RunCompareOutputStep = struct {
|
||||
step: build.Step,
|
||||
context: &CompareOutputContext,
|
||||
context: *CompareOutputContext,
|
||||
exe_path: []const u8,
|
||||
name: []const u8,
|
||||
expected_output: []const u8,
|
||||
test_index: usize,
|
||||
cli_args: []const []const u8,
|
||||
|
||||
pub fn create(context: &CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) &RunCompareOutputStep {
|
||||
pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep {
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
|
||||
ptr.* = RunCompareOutputStep{
|
||||
@@ -254,7 +254,7 @@ pub const CompareOutputContext = struct {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
fn make(step: &build.Step) !void {
|
||||
fn make(step: *build.Step) !void {
|
||||
const self = @fieldParentPtr(RunCompareOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
@@ -321,12 +321,12 @@ pub const CompareOutputContext = struct {
|
||||
|
||||
const RuntimeSafetyRunStep = struct {
|
||||
step: build.Step,
|
||||
context: &CompareOutputContext,
|
||||
context: *CompareOutputContext,
|
||||
exe_path: []const u8,
|
||||
name: []const u8,
|
||||
test_index: usize,
|
||||
|
||||
pub fn create(context: &CompareOutputContext, exe_path: []const u8, name: []const u8) &RuntimeSafetyRunStep {
|
||||
pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep {
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
|
||||
ptr.* = RuntimeSafetyRunStep{
|
||||
@@ -340,7 +340,7 @@ pub const CompareOutputContext = struct {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
fn make(step: &build.Step) !void {
|
||||
fn make(step: *build.Step) !void {
|
||||
const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
@@ -382,7 +382,7 @@ pub const CompareOutputContext = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub fn createExtra(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8, special: Special) TestCase {
|
||||
pub fn createExtra(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8, special: Special) TestCase {
|
||||
var tc = TestCase{
|
||||
.name = name,
|
||||
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
||||
@@ -396,32 +396,32 @@ pub const CompareOutputContext = struct {
|
||||
return tc;
|
||||
}
|
||||
|
||||
pub fn create(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) TestCase {
|
||||
pub fn create(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) TestCase {
|
||||
return createExtra(self, name, source, expected_output, Special.None);
|
||||
}
|
||||
|
||||
pub fn addC(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
||||
pub fn addC(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
||||
var tc = self.create(name, source, expected_output);
|
||||
tc.link_libc = true;
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn add(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
||||
pub fn add(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
||||
const tc = self.create(name, source, expected_output);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addAsm(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
||||
pub fn addAsm(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
||||
const tc = self.createExtra(name, source, expected_output, Special.Asm);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addRuntimeSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) void {
|
||||
pub fn addRuntimeSafety(self: *CompareOutputContext, name: []const u8, source: []const u8) void {
|
||||
const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addCase(self: &CompareOutputContext, case: &const TestCase) void {
|
||||
pub fn addCase(self: *CompareOutputContext, case: *const TestCase) void {
|
||||
const b = self.b;
|
||||
|
||||
const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
|
||||
@@ -504,8 +504,8 @@ pub const CompareOutputContext = struct {
|
||||
};
|
||||
|
||||
pub const CompileErrorContext = struct {
|
||||
b: &build.Builder,
|
||||
step: &build.Step,
|
||||
b: *build.Builder,
|
||||
step: *build.Step,
|
||||
test_index: usize,
|
||||
test_filter: ?[]const u8,
|
||||
|
||||
@@ -521,27 +521,27 @@ pub const CompileErrorContext = struct {
|
||||
source: []const u8,
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
|
||||
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
||||
self.sources.append(SourceFile{
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addExpectedError(self: &TestCase, text: []const u8) void {
|
||||
pub fn addExpectedError(self: *TestCase, text: []const u8) void {
|
||||
self.expected_errors.append(text) catch unreachable;
|
||||
}
|
||||
};
|
||||
|
||||
const CompileCmpOutputStep = struct {
|
||||
step: build.Step,
|
||||
context: &CompileErrorContext,
|
||||
context: *CompileErrorContext,
|
||||
name: []const u8,
|
||||
test_index: usize,
|
||||
case: &const TestCase,
|
||||
case: *const TestCase,
|
||||
build_mode: Mode,
|
||||
|
||||
pub fn create(context: &CompileErrorContext, name: []const u8, case: &const TestCase, build_mode: Mode) &CompileCmpOutputStep {
|
||||
pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep {
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
|
||||
ptr.* = CompileCmpOutputStep{
|
||||
@@ -556,7 +556,7 @@ pub const CompileErrorContext = struct {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
fn make(step: &build.Step) !void {
|
||||
fn make(step: *build.Step) !void {
|
||||
const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
@@ -661,7 +661,7 @@ pub const CompileErrorContext = struct {
|
||||
warn("\n");
|
||||
}
|
||||
|
||||
pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) &TestCase {
|
||||
pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
|
||||
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
||||
tc.* = TestCase{
|
||||
.name = name,
|
||||
@@ -678,24 +678,24 @@ pub const CompileErrorContext = struct {
|
||||
return tc;
|
||||
}
|
||||
|
||||
pub fn addC(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
pub fn addC(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
var tc = self.create(name, source, expected_lines);
|
||||
tc.link_libc = true;
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addExe(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
pub fn addExe(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
var tc = self.create(name, source, expected_lines);
|
||||
tc.is_exe = true;
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn add(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
pub fn add(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
const tc = self.create(name, source, expected_lines);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addCase(self: &CompileErrorContext, case: &const TestCase) void {
|
||||
pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {
|
||||
const b = self.b;
|
||||
|
||||
for ([]Mode{
|
||||
@@ -720,20 +720,20 @@ pub const CompileErrorContext = struct {
|
||||
};
|
||||
|
||||
pub const BuildExamplesContext = struct {
|
||||
b: &build.Builder,
|
||||
step: &build.Step,
|
||||
b: *build.Builder,
|
||||
step: *build.Step,
|
||||
test_index: usize,
|
||||
test_filter: ?[]const u8,
|
||||
|
||||
pub fn addC(self: &BuildExamplesContext, root_src: []const u8) void {
|
||||
pub fn addC(self: *BuildExamplesContext, root_src: []const u8) void {
|
||||
self.addAllArgs(root_src, true);
|
||||
}
|
||||
|
||||
pub fn add(self: &BuildExamplesContext, root_src: []const u8) void {
|
||||
pub fn add(self: *BuildExamplesContext, root_src: []const u8) void {
|
||||
self.addAllArgs(root_src, false);
|
||||
}
|
||||
|
||||
pub fn addBuildFile(self: &BuildExamplesContext, build_file: []const u8) void {
|
||||
pub fn addBuildFile(self: *BuildExamplesContext, build_file: []const u8) void {
|
||||
const b = self.b;
|
||||
|
||||
const annotated_case_name = b.fmt("build {} (Debug)", build_file);
|
||||
@@ -763,7 +763,7 @@ pub const BuildExamplesContext = struct {
|
||||
self.step.dependOn(&log_step.step);
|
||||
}
|
||||
|
||||
pub fn addAllArgs(self: &BuildExamplesContext, root_src: []const u8, link_libc: bool) void {
|
||||
pub fn addAllArgs(self: *BuildExamplesContext, root_src: []const u8, link_libc: bool) void {
|
||||
const b = self.b;
|
||||
|
||||
for ([]Mode{
|
||||
@@ -792,8 +792,8 @@ pub const BuildExamplesContext = struct {
|
||||
};
|
||||
|
||||
pub const TranslateCContext = struct {
|
||||
b: &build.Builder,
|
||||
step: &build.Step,
|
||||
b: *build.Builder,
|
||||
step: *build.Step,
|
||||
test_index: usize,
|
||||
test_filter: ?[]const u8,
|
||||
|
||||
@@ -808,26 +808,26 @@ pub const TranslateCContext = struct {
|
||||
source: []const u8,
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
|
||||
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
||||
self.sources.append(SourceFile{
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addExpectedLine(self: &TestCase, text: []const u8) void {
|
||||
pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
|
||||
self.expected_lines.append(text) catch unreachable;
|
||||
}
|
||||
};
|
||||
|
||||
const TranslateCCmpOutputStep = struct {
|
||||
step: build.Step,
|
||||
context: &TranslateCContext,
|
||||
context: *TranslateCContext,
|
||||
name: []const u8,
|
||||
test_index: usize,
|
||||
case: &const TestCase,
|
||||
case: *const TestCase,
|
||||
|
||||
pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) &TranslateCCmpOutputStep {
|
||||
pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep {
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
|
||||
ptr.* = TranslateCCmpOutputStep{
|
||||
@@ -841,7 +841,7 @@ pub const TranslateCContext = struct {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
fn make(step: &build.Step) !void {
|
||||
fn make(step: *build.Step) !void {
|
||||
const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
@@ -935,7 +935,7 @@ pub const TranslateCContext = struct {
|
||||
warn("\n");
|
||||
}
|
||||
|
||||
pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) &TestCase {
|
||||
pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
|
||||
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
||||
tc.* = TestCase{
|
||||
.name = name,
|
||||
@@ -951,22 +951,22 @@ pub const TranslateCContext = struct {
|
||||
return tc;
|
||||
}
|
||||
|
||||
pub fn add(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
pub fn add(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
const tc = self.create(false, "source.h", name, source, expected_lines);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addC(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
pub fn addC(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
const tc = self.create(false, "source.c", name, source, expected_lines);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addAllowWarnings(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
pub fn addAllowWarnings(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
const tc = self.create(true, "source.h", name, source, expected_lines);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addCase(self: &TranslateCContext, case: &const TestCase) void {
|
||||
pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
|
||||
const b = self.b;
|
||||
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable;
|
||||
@@ -986,8 +986,8 @@ pub const TranslateCContext = struct {
|
||||
};
|
||||
|
||||
pub const GenHContext = struct {
|
||||
b: &build.Builder,
|
||||
step: &build.Step,
|
||||
b: *build.Builder,
|
||||
step: *build.Step,
|
||||
test_index: usize,
|
||||
test_filter: ?[]const u8,
|
||||
|
||||
@@ -1001,27 +1001,27 @@ pub const GenHContext = struct {
|
||||
source: []const u8,
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
|
||||
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
||||
self.sources.append(SourceFile{
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addExpectedLine(self: &TestCase, text: []const u8) void {
|
||||
pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
|
||||
self.expected_lines.append(text) catch unreachable;
|
||||
}
|
||||
};
|
||||
|
||||
const GenHCmpOutputStep = struct {
|
||||
step: build.Step,
|
||||
context: &GenHContext,
|
||||
context: *GenHContext,
|
||||
h_path: []const u8,
|
||||
name: []const u8,
|
||||
test_index: usize,
|
||||
case: &const TestCase,
|
||||
case: *const TestCase,
|
||||
|
||||
pub fn create(context: &GenHContext, h_path: []const u8, name: []const u8, case: &const TestCase) &GenHCmpOutputStep {
|
||||
pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep {
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;
|
||||
ptr.* = GenHCmpOutputStep{
|
||||
@@ -1036,7 +1036,7 @@ pub const GenHContext = struct {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
fn make(step: &build.Step) !void {
|
||||
fn make(step: *build.Step) !void {
|
||||
const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
@@ -1069,7 +1069,7 @@ pub const GenHContext = struct {
|
||||
warn("\n");
|
||||
}
|
||||
|
||||
pub fn create(self: &GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) &TestCase {
|
||||
pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
|
||||
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
||||
tc.* = TestCase{
|
||||
.name = name,
|
||||
@@ -1084,12 +1084,12 @@ pub const GenHContext = struct {
|
||||
return tc;
|
||||
}
|
||||
|
||||
pub fn add(self: &GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
||||
const tc = self.create("test.zig", name, source, expected_lines);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addCase(self: &GenHContext, case: &const TestCase) void {
|
||||
pub fn addCase(self: *GenHContext, case: *const TestCase) void {
|
||||
const b = self.b;
|
||||
const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
cases.add("double define struct",
|
||||
\\typedef struct Bar Bar;
|
||||
\\typedef struct Foo Foo;
|
||||
@@ -14,11 +14,11 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\};
|
||||
,
|
||||
\\pub const struct_Foo = extern struct {
|
||||
\\ a: ?&Foo,
|
||||
\\ a: ?*Foo,
|
||||
\\};
|
||||
\\pub const Foo = struct_Foo;
|
||||
\\pub const struct_Bar = extern struct {
|
||||
\\ a: ?&Foo,
|
||||
\\ a: ?*Foo,
|
||||
\\};
|
||||
);
|
||||
|
||||
@@ -99,7 +99,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
cases.add("restrict -> noalias",
|
||||
\\void foo(void *restrict bar, void *restrict);
|
||||
,
|
||||
\\pub extern fn foo(noalias bar: ?&c_void, noalias arg1: ?&c_void) void;
|
||||
\\pub extern fn foo(noalias bar: ?*c_void, noalias arg1: ?*c_void) void;
|
||||
);
|
||||
|
||||
cases.add("simple struct",
|
||||
@@ -110,7 +110,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
,
|
||||
\\const struct_Foo = extern struct {
|
||||
\\ x: c_int,
|
||||
\\ y: ?&u8,
|
||||
\\ y: ?*u8,
|
||||
\\};
|
||||
,
|
||||
\\pub const Foo = struct_Foo;
|
||||
@@ -141,7 +141,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
,
|
||||
\\pub const BarB = enum_Bar.B;
|
||||
,
|
||||
\\pub extern fn func(a: ?&struct_Foo, b: ?&(?&enum_Bar)) void;
|
||||
\\pub extern fn func(a: ?*struct_Foo, b: ?*(?*enum_Bar)) void;
|
||||
,
|
||||
\\pub const Foo = struct_Foo;
|
||||
,
|
||||
@@ -151,7 +151,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
cases.add("constant size array",
|
||||
\\void func(int array[20]);
|
||||
,
|
||||
\\pub extern fn func(array: ?&c_int) void;
|
||||
\\pub extern fn func(array: ?*c_int) void;
|
||||
);
|
||||
|
||||
cases.add("self referential struct with function pointer",
|
||||
@@ -160,7 +160,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\};
|
||||
,
|
||||
\\pub const struct_Foo = extern struct {
|
||||
\\ derp: ?extern fn(?&struct_Foo) void,
|
||||
\\ derp: ?extern fn(?*struct_Foo) void,
|
||||
\\};
|
||||
,
|
||||
\\pub const Foo = struct_Foo;
|
||||
@@ -172,7 +172,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
,
|
||||
\\pub const struct_Foo = @OpaqueType();
|
||||
,
|
||||
\\pub extern fn some_func(foo: ?&struct_Foo, x: c_int) ?&struct_Foo;
|
||||
\\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
|
||||
,
|
||||
\\pub const Foo = struct_Foo;
|
||||
);
|
||||
@@ -219,11 +219,11 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\};
|
||||
,
|
||||
\\pub const struct_Bar = extern struct {
|
||||
\\ next: ?&struct_Foo,
|
||||
\\ next: ?*struct_Foo,
|
||||
\\};
|
||||
,
|
||||
\\pub const struct_Foo = extern struct {
|
||||
\\ next: ?&struct_Bar,
|
||||
\\ next: ?*struct_Bar,
|
||||
\\};
|
||||
);
|
||||
|
||||
@@ -233,7 +233,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
,
|
||||
\\pub const Foo = c_void;
|
||||
,
|
||||
\\pub extern fn fun(a: ?&Foo) Foo;
|
||||
\\pub extern fn fun(a: ?*Foo) Foo;
|
||||
);
|
||||
|
||||
cases.add("generate inline func for #define global extern fn",
|
||||
@@ -505,7 +505,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ return 6;
|
||||
\\}
|
||||
,
|
||||
\\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?&c_void) c_int {
|
||||
\\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
|
||||
\\ if ((a != 0) and (b != 0)) return 0;
|
||||
\\ if ((b != 0) and (c != null)) return 1;
|
||||
\\ if ((a != 0) and (c != null)) return 2;
|
||||
@@ -607,7 +607,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\pub const struct_Foo = extern struct {
|
||||
\\ field: c_int,
|
||||
\\};
|
||||
\\pub export fn read_field(foo: ?&struct_Foo) c_int {
|
||||
\\pub export fn read_field(foo: ?*struct_Foo) c_int {
|
||||
\\ return (??foo).field;
|
||||
\\}
|
||||
);
|
||||
@@ -653,8 +653,8 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ return x;
|
||||
\\}
|
||||
,
|
||||
\\pub export fn foo(x: ?&c_ushort) ?&c_void {
|
||||
\\ return @ptrCast(?&c_void, x);
|
||||
\\pub export fn foo(x: ?*c_ushort) ?*c_void {
|
||||
\\ return @ptrCast(?*c_void, x);
|
||||
\\}
|
||||
);
|
||||
|
||||
@@ -674,7 +674,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ return 0;
|
||||
\\}
|
||||
,
|
||||
\\pub export fn foo() ?&c_int {
|
||||
\\pub export fn foo() ?*c_int {
|
||||
\\ return null;
|
||||
\\}
|
||||
);
|
||||
@@ -983,7 +983,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ *x = 1;
|
||||
\\}
|
||||
,
|
||||
\\pub export fn foo(x: ?&c_int) void {
|
||||
\\pub export fn foo(x: ?*c_int) void {
|
||||
\\ (??x).* = 1;
|
||||
\\}
|
||||
);
|
||||
@@ -1011,7 +1011,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
,
|
||||
\\pub fn foo() c_int {
|
||||
\\ var x: c_int = 1234;
|
||||
\\ var ptr: ?&c_int = &x;
|
||||
\\ var ptr: ?*c_int = &x;
|
||||
\\ return (??ptr).*;
|
||||
\\}
|
||||
);
|
||||
@@ -1021,7 +1021,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ return "bar";
|
||||
\\}
|
||||
,
|
||||
\\pub fn foo() ?&const u8 {
|
||||
\\pub fn foo() ?*const u8 {
|
||||
\\ return c"bar";
|
||||
\\}
|
||||
);
|
||||
@@ -1150,8 +1150,8 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ return (float *)a;
|
||||
\\}
|
||||
,
|
||||
\\fn ptrcast(a: ?&c_int) ?&f32 {
|
||||
\\ return @ptrCast(?&f32, a);
|
||||
\\fn ptrcast(a: ?*c_int) ?*f32 {
|
||||
\\ return @ptrCast(?*f32, a);
|
||||
\\}
|
||||
);
|
||||
|
||||
@@ -1173,7 +1173,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ return !c;
|
||||
\\}
|
||||
,
|
||||
\\pub fn foo(a: c_int, b: f32, c: ?&c_void) c_int {
|
||||
\\pub fn foo(a: c_int, b: f32, c: ?*c_void) c_int {
|
||||
\\ return !(a == 0);
|
||||
\\ return !(a != 0);
|
||||
\\ return !(b != 0);
|
||||
@@ -1194,7 +1194,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
cases.add("const ptr initializer",
|
||||
\\static const char *v0 = "0.0.0";
|
||||
,
|
||||
\\pub var v0: ?&const u8 = c"0.0.0";
|
||||
\\pub var v0: ?*const u8 = c"0.0.0";
|
||||
);
|
||||
|
||||
cases.add("static incomplete array inside function",
|
||||
@@ -1203,14 +1203,14 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\}
|
||||
,
|
||||
\\pub fn foo() void {
|
||||
\\ const v2: &const u8 = c"2.2.2";
|
||||
\\ const v2: *const u8 = c"2.2.2";
|
||||
\\}
|
||||
);
|
||||
|
||||
cases.add("macro pointer cast",
|
||||
\\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
|
||||
,
|
||||
\\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);
|
||||
\\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);
|
||||
);
|
||||
|
||||
cases.add("if on none bool",
|
||||
@@ -1231,7 +1231,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ B,
|
||||
\\ C,
|
||||
\\};
|
||||
\\pub fn if_none_bool(a: c_int, b: f32, c: ?&c_void, d: enum_SomeEnum) c_int {
|
||||
\\pub fn if_none_bool(a: c_int, b: f32, c: ?*c_void, d: enum_SomeEnum) c_int {
|
||||
\\ if (a != 0) return 0;
|
||||
\\ if (b != 0) return 1;
|
||||
\\ if (c != null) return 2;
|
||||
@@ -1248,7 +1248,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ return 3;
|
||||
\\}
|
||||
,
|
||||
\\pub fn while_none_bool(a: c_int, b: f32, c: ?&c_void) c_int {
|
||||
\\pub fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
|
||||
\\ while (a != 0) return 0;
|
||||
\\ while (b != 0) return 1;
|
||||
\\ while (c != null) return 2;
|
||||
@@ -1264,7 +1264,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
|
||||
\\ return 3;
|
||||
\\}
|
||||
,
|
||||
\\pub fn for_none_bool(a: c_int, b: f32, c: ?&c_void) c_int {
|
||||
\\pub fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
|
||||
\\ while (a != 0) return 0;
|
||||
\\ while (b != 0) return 1;
|
||||
\\ while (c != null) return 2;
|
||||
|
||||
Reference in New Issue
Block a user