rename @ptrcast to @ptrCast to follow convention

This commit is contained in:
Andrew Kelley 2017-04-21 10:39:13 -04:00
parent ecb71d1dd3
commit e3c524c1d4
17 changed files with 37 additions and 37 deletions

View File

@ -623,7 +623,7 @@ calls the public `panic` function exposed in the root source file, or
if there is not one specified, invokes the one provided in
`std/special/panic.zig`.
### @ptrcast(comptime DestType: type, value: var) -> DestType
### @ptrCast(comptime DestType: type, value: var) -> DestType
Converts a pointer of one type to a pointer of another type.

View File

@ -4551,7 +4551,7 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdSetGlobalSection, "setGlobalSection", 2);
create_builtin_fn(g, BuiltinFnIdSetGlobalLinkage, "setGlobalLinkage", 2);
create_builtin_fn(g, BuiltinFnIdPanic, "panic", 1);
create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrcast", 2);
create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrCast", 2);
create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2);
create_builtin_fn(g, BuiltinFnIdEnumTagName, "enumTagName", 1);
create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3);

View File

@ -58,7 +58,7 @@ pub const BufMap = struct {
fn free(self: &BufMap, value: []const u8) {
// remove the const
const mut_value = @ptrcast(&u8, value.ptr)[0...value.len];
const mut_value = @ptrCast(&u8, value.ptr)[0...value.len];
self.hash_map.allocator.free(mut_value);
}

View File

@ -47,7 +47,7 @@ pub const BufSet = struct {
fn free(self: &BufSet, value: []const u8) {
// remove the const
const mut_value = @ptrcast(&u8, value.ptr)[0...value.len];
const mut_value = @ptrCast(&u8, value.ptr)[0...value.len];
self.hash_map.allocator.free(mut_value);
}

View File

@ -74,7 +74,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream) -> %void {
const name = %return compile_unit.die.getAttrString(st, DW.AT_name);
%return out_stream.printf("{} -> {}\n", return_address, name);
maybe_fp = *@ptrcast(&const ?&const u8, fp);
maybe_fp = *@ptrCast(&const ?&const u8, fp);
}
},
ObjectFormat.coff => {

View File

@ -250,7 +250,7 @@ test "basicHashMapTest" {
}
fn hash_i32(x: i32) -> u32 {
*@ptrcast(&u32, &x)
*@ptrCast(&u32, &x)
}
fn eql_i32(a: i32, b: i32) -> bool {

View File

@ -59,7 +59,7 @@ pub fn exit(status: usize) -> noreturn {
/// Get the errno from a syscall return value, or 0 for no error.
pub fn getErrno(r: usize) -> usize {
const signed_r = *@ptrcast(&const isize, &r);
const signed_r = *@ptrCast(&const isize, &r);
if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
}

View File

@ -752,7 +752,7 @@ pub const Dir = struct {
break;
}
}
const linux_entry = @ptrcast(&LinuxEntry, &self.buf[self.index]);
const linux_entry = @ptrCast(&LinuxEntry, &self.buf[self.index]);
const next_index = self.index + linux_entry.d_reclen;
self.index = next_index;

View File

@ -251,8 +251,8 @@ pub const DT_LNK = 10;
pub const DT_SOCK = 12;
pub const DT_WHT = 14;
fn unsigned(s: i32) -> u32 { *@ptrcast(&u32, &s) }
fn signed(s: u32) -> i32 { *@ptrcast(&i32, &s) }
fn unsigned(s: i32) -> u32 { *@ptrCast(&u32, &s) }
fn signed(s: u32) -> i32 { *@ptrCast(&i32, &s) }
pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) }
pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) }
pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) }
@ -262,7 +262,7 @@ pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff }
/// Get the errno from a syscall return value, or 0 for no error.
pub fn getErrno(r: usize) -> usize {
const signed_r = *@ptrcast(&const isize, &r);
const signed_r = *@ptrCast(&const isize, &r);
if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
}

View File

@ -31,8 +31,8 @@ export nakedcc fn _start() -> noreturn {
fn callMainAndExit() -> noreturn {
const argc = *argc_ptr;
const argv = @ptrcast(&&u8, &argc_ptr[1]);
const envp = @ptrcast(&?&u8, &argv[argc + 1]);
const argv = @ptrCast(&&u8, &argc_ptr[1]);
const envp = @ptrCast(&?&u8, &argv[argc + 1]);
callMain(argc, argv, envp) %% exit(1);
exit(0);
}
@ -42,7 +42,7 @@ fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void {
var env_count: usize = 0;
while (envp[env_count] != null; env_count += 1) {}
std.os.environ_raw = @ptrcast(&&u8, envp)[0...env_count];
std.os.environ_raw = @ptrCast(&&u8, envp)[0...env_count];
return root.main();
}

View File

@ -15,7 +15,7 @@ export fn __udivdi3(a: du_int, b: du_int) -> du_int {
fn du_int_to_udwords(x: du_int) -> udwords {
@setDebugSafety(this, false);
return *@ptrcast(&udwords, &x);
return *@ptrCast(&udwords, &x);
}
export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
@ -66,7 +66,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
if (var rem ?= maybe_rem) {
r[high] = n[high] % d[high];
r[low] = 0;
*rem = *@ptrcast(&du_int, &r[0]);
*rem = *@ptrCast(&du_int, &r[0]);
}
return n[high] / d[high];
}
@ -78,7 +78,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
if (var rem ?= maybe_rem) {
r[low] = n[low];
r[high] = n[high] & (d[high] - 1);
*rem = *@ptrcast(&du_int, &r[0]);
*rem = *@ptrCast(&du_int, &r[0]);
}
return n[high] >> @ctz(d[high]);
}
@ -89,7 +89,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
// 0 <= sr <= n_uword_bits - 2 or sr large
if (sr > n_uword_bits - 2) {
if (var rem ?= maybe_rem) {
*rem = *@ptrcast(&du_int, &n[0]);
*rem = *@ptrCast(&du_int, &n[0]);
}
return 0;
}
@ -113,12 +113,12 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
*rem = n[low] & (d[low] - 1);
}
if (d[low] == 1) {
return *@ptrcast(&du_int, &n[0]);
return *@ptrCast(&du_int, &n[0]);
}
sr = @ctz(d[low]);
q[high] = n[high] >> sr;
q[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
return *@ptrcast(&du_int, &q[0]);
return *@ptrCast(&du_int, &q[0]);
}
// K X
// ---
@ -154,7 +154,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
// 0 <= sr <= n_uword_bits - 1 or sr large
if (sr > n_uword_bits - 1) {
if (var rem ?= maybe_rem) {
*rem = *@ptrcast(&du_int, &n[0]);
*rem = *@ptrCast(&du_int, &n[0]);
}
return 0;
}
@ -191,17 +191,17 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
// r.all -= d.all;
// carry = 1;
// }
const s: di_int = (di_int)(*@ptrcast(&du_int, &d[0]) - *@ptrcast(&du_int, &r[0]) - 1) >> (n_udword_bits - 1);
const s: di_int = (di_int)(*@ptrCast(&du_int, &d[0]) - *@ptrCast(&du_int, &r[0]) - 1) >> (n_udword_bits - 1);
carry = su_int(s & 1);
*@ptrcast(&du_int, &r[0]) -= *@ptrcast(&du_int, &d[0]) & u64(s);
*@ptrCast(&du_int, &r[0]) -= *@ptrCast(&du_int, &d[0]) & u64(s);
sr -= 1;
}
*@ptrcast(&du_int, &q[0]) = (*@ptrcast(&du_int, &q[0]) << 1) | u64(carry);
*@ptrCast(&du_int, &q[0]) = (*@ptrCast(&du_int, &q[0]) << 1) | u64(carry);
if (var rem ?= maybe_rem) {
*rem = *@ptrcast(&du_int, &r[0]);
*rem = *@ptrCast(&du_int, &r[0]);
}
return *@ptrcast(&du_int, &q[0]);
return *@ptrCast(&du_int, &q[0]);
}
export fn __umoddi3(a: du_int, b: du_int) -> du_int {

View File

@ -16,7 +16,7 @@ test "numLitIntToPtrCast" {
test "pointerReinterpretConstFloatToInt" {
const float: f64 = 5.99999999999994648725e-01;
const float_ptr = &float;
const int_ptr = @ptrcast(&i32, float_ptr);
const int_ptr = @ptrCast(&i32, float_ptr);
const int_val = *int_ptr;
assert(int_val == 858993411);
}

View File

@ -121,5 +121,5 @@ test "genericFnWithImplicitCast" {
}
fn getByte(ptr: ?&const u8) -> u8 {*??ptr}
fn getFirstByte(comptime T: type, mem: []const T) -> u8 {
getByte(@ptrcast(&const u8, &mem[0]))
getByte(@ptrCast(&const u8, &mem[0]))
}

View File

@ -246,15 +246,15 @@ test "typeEquality" {
const global_a: i32 = 1234;
const global_b: &const i32 = &global_a;
const global_c: &const f32 = @ptrcast(&const f32, global_b);
const global_c: &const f32 = @ptrCast(&const f32, global_b);
test "compileTimeGlobalReinterpret" {
const d = @ptrcast(&const i32, global_c);
const d = @ptrCast(&const i32, global_c);
assert(*d == 1234);
}
test "explicitCastMaybePointers" {
const a: ?&i32 = undefined;
const b: ?&f32 = @ptrcast(?&f32, a);
const b: ?&f32 = @ptrCast(?&f32, a);
}
test "genericMallocFree" {
@ -263,7 +263,7 @@ test "genericMallocFree" {
}
const some_mem : [100]u8 = undefined;
fn memAlloc(comptime T: type, n: usize) -> %[]T {
return @ptrcast(&T, &some_mem[0])[0...n];
return @ptrCast(&T, &some_mem[0])[0...n];
}
fn memFree(comptime T: type, memory: []T) { }

View File

@ -41,7 +41,7 @@ const VoidStructFieldsFoo = struct {
test "fn" {
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);

View File

@ -262,8 +262,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\const c = @cImport(@cInclude("stdlib.h"));
\\
\\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
\\ const a_int = @ptrcast(&i32, a ?? unreachable);
\\ const b_int = @ptrcast(&i32, b ?? unreachable);
\\ const a_int = @ptrCast(&i32, a ?? unreachable);
\\ const b_int = @ptrCast(&i32, b ?? unreachable);
\\ if (*a_int < *b_int) {
\\ -1
\\ } else if (*a_int > *b_int) {
@ -276,7 +276,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\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) {

View File

@ -1475,7 +1475,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("ptrcast to non-pointer",
\\export fn entry(a: &i32) -> usize {
\\ return @ptrcast(usize, a);
\\ return @ptrCast(usize, a);
\\}
, ".tmp_source.zig:2:21: error: expected pointer, found 'usize'");