all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
This commit is contained in:
@@ -73,25 +73,25 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
|
||||
const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
|
||||
|
||||
//read bytes as container
|
||||
const value_ptr = @ptrCast(*align(1) const Container, &bytes[start_byte]);
|
||||
const value_ptr = @as(*align(1) const Container, @ptrCast(&bytes[start_byte]));
|
||||
var value = value_ptr.*;
|
||||
|
||||
if (endian != native_endian) value = @byteSwap(value);
|
||||
|
||||
switch (endian) {
|
||||
.Big => {
|
||||
value <<= @intCast(Shift, head_keep_bits);
|
||||
value >>= @intCast(Shift, head_keep_bits);
|
||||
value >>= @intCast(Shift, tail_keep_bits);
|
||||
value <<= @as(Shift, @intCast(head_keep_bits));
|
||||
value >>= @as(Shift, @intCast(head_keep_bits));
|
||||
value >>= @as(Shift, @intCast(tail_keep_bits));
|
||||
},
|
||||
.Little => {
|
||||
value <<= @intCast(Shift, tail_keep_bits);
|
||||
value >>= @intCast(Shift, tail_keep_bits);
|
||||
value >>= @intCast(Shift, head_keep_bits);
|
||||
value <<= @as(Shift, @intCast(tail_keep_bits));
|
||||
value >>= @as(Shift, @intCast(tail_keep_bits));
|
||||
value >>= @as(Shift, @intCast(head_keep_bits));
|
||||
},
|
||||
}
|
||||
|
||||
return @bitCast(Int, @truncate(UnInt, value));
|
||||
return @as(Int, @bitCast(@as(UnInt, @truncate(value))));
|
||||
}
|
||||
|
||||
/// Sets the integer at `index` to `val` within the packed data beginning
|
||||
@@ -115,21 +115,21 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
|
||||
const head_keep_bits = bit_index - (start_byte * 8);
|
||||
const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
|
||||
const keep_shift = switch (endian) {
|
||||
.Big => @intCast(Shift, tail_keep_bits),
|
||||
.Little => @intCast(Shift, head_keep_bits),
|
||||
.Big => @as(Shift, @intCast(tail_keep_bits)),
|
||||
.Little => @as(Shift, @intCast(head_keep_bits)),
|
||||
};
|
||||
|
||||
//position the bits where they need to be in the container
|
||||
const value = @intCast(Container, @bitCast(UnInt, int)) << keep_shift;
|
||||
const value = @as(Container, @intCast(@as(UnInt, @bitCast(int)))) << keep_shift;
|
||||
|
||||
//read existing bytes
|
||||
const target_ptr = @ptrCast(*align(1) Container, &bytes[start_byte]);
|
||||
const target_ptr = @as(*align(1) Container, @ptrCast(&bytes[start_byte]));
|
||||
var target = target_ptr.*;
|
||||
|
||||
if (endian != native_endian) target = @byteSwap(target);
|
||||
|
||||
//zero the bits we want to replace in the existing bytes
|
||||
const inv_mask = @intCast(Container, std.math.maxInt(UnInt)) << keep_shift;
|
||||
const inv_mask = @as(Container, @intCast(std.math.maxInt(UnInt))) << keep_shift;
|
||||
const mask = ~inv_mask;
|
||||
target &= mask;
|
||||
|
||||
@@ -156,7 +156,7 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
|
||||
if (length == 0) return PackedIntSliceEndian(Int, endian).init(new_bytes[0..0], 0);
|
||||
|
||||
var new_slice = PackedIntSliceEndian(Int, endian).init(new_bytes, length);
|
||||
new_slice.bit_offset = @intCast(u3, (bit_index - (start_byte * 8)));
|
||||
new_slice.bit_offset = @as(u3, @intCast((bit_index - (start_byte * 8))));
|
||||
return new_slice;
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ test "PackedIntArray init" {
|
||||
const PackedArray = PackedIntArray(u3, 8);
|
||||
var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
|
||||
var i = @as(usize, 0);
|
||||
while (i < packed_array.len) : (i += 1) try testing.expectEqual(@intCast(u3, i), packed_array.get(i));
|
||||
while (i < packed_array.len) : (i += 1) try testing.expectEqual(@as(u3, @intCast(i)), packed_array.get(i));
|
||||
}
|
||||
|
||||
test "PackedIntArray initAllTo" {
|
||||
@@ -469,7 +469,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
|
||||
|
||||
var i = @as(usize, 0);
|
||||
while (i < packed_array.len) : (i += 1) {
|
||||
packed_array.set(i, @intCast(Int, i % limit));
|
||||
packed_array.set(i, @as(Int, @intCast(i % limit)));
|
||||
}
|
||||
|
||||
//slice of array
|
||||
|
||||
Reference in New Issue
Block a user