mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Add another -vet-cast check
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
//+vet !cast
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import "base:intrinsics"
|
import "base:intrinsics"
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ Returns:
|
|||||||
- result: A valid version 8 UUID.
|
- result: A valid version 8 UUID.
|
||||||
*/
|
*/
|
||||||
stamp_v8_array :: proc(array: [16]u8) -> (result: Identifier) {
|
stamp_v8_array :: proc(array: [16]u8) -> (result: Identifier) {
|
||||||
result = transmute(Identifier)array
|
result = Identifier(array)
|
||||||
|
|
||||||
result[VERSION_BYTE_INDEX] &= 0x0F
|
result[VERSION_BYTE_INDEX] &= 0x0F
|
||||||
result[VERSION_BYTE_INDEX] |= 0x80
|
result[VERSION_BYTE_INDEX] |= 0x80
|
||||||
|
|||||||
+3
-4
@@ -370,7 +370,7 @@ parse_ip6_address :: proc(address_and_maybe_port: string) -> (addr: IP6_Address,
|
|||||||
val |= u16(ipv4[3])
|
val |= u16(ipv4[3])
|
||||||
piece_values[7] = u16be(val)
|
piece_values[7] = u16be(val)
|
||||||
}
|
}
|
||||||
return transmute(IP6_Address)piece_values, true
|
return IP6_Address(piece_values), true
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -522,10 +522,9 @@ address_to_string :: proc(addr: Address, allocator := context.temp_allocator) ->
|
|||||||
run := Zero_Run{-1, -1}
|
run := Zero_Run{-1, -1}
|
||||||
best := Zero_Run{-1, -1}
|
best := Zero_Run{-1, -1}
|
||||||
|
|
||||||
addr := transmute([8]u16be)v
|
|
||||||
|
|
||||||
last := u16be(1)
|
last := u16be(1)
|
||||||
for val, i in addr {
|
for val, i in v {
|
||||||
/*
|
/*
|
||||||
If we encounter adjacent zeroes, then start a new run if not already in one.
|
If we encounter adjacent zeroes, then start a new run if not already in one.
|
||||||
Also remember the rightmost index regardless, because it'll be the new
|
Also remember the rightmost index regardless, because it'll be the new
|
||||||
@@ -559,7 +558,7 @@ address_to_string :: proc(addr: Address, allocator := context.temp_allocator) ->
|
|||||||
last = val
|
last = val
|
||||||
}
|
}
|
||||||
|
|
||||||
for val, i in addr {
|
for val, i in v {
|
||||||
if best.start == i || best.end == i {
|
if best.start == i || best.end == i {
|
||||||
// For the left and right side of the best zero run, print a `:`.
|
// For the left and right side of the best zero run, print a `:`.
|
||||||
fmt.sbprint(&b, ":")
|
fmt.sbprint(&b, ":")
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ _unwrap_os_addr :: proc "contextless" (endpoint: Endpoint)->(linux.Sock_Addr_Any
|
|||||||
ipv4 = {
|
ipv4 = {
|
||||||
sin_family = .INET,
|
sin_family = .INET,
|
||||||
sin_port = u16be(endpoint.port),
|
sin_port = u16be(endpoint.port),
|
||||||
sin_addr = transmute([4]u8) endpoint.address.(IP4_Address),
|
sin_addr = ([4]u8)(endpoint.address.(IP4_Address)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case IP6_Address:
|
case IP6_Address:
|
||||||
return {
|
return {
|
||||||
ipv6 = {
|
ipv6 = {
|
||||||
sin6_port = u16be(endpoint.port),
|
sin6_port = u16be(endpoint.port),
|
||||||
sin6_addr = transmute([16]u8) endpoint.address.(IP6_Address),
|
sin6_addr = transmute([16]u8)endpoint.address.(IP6_Address),
|
||||||
sin6_family = .INET6,
|
sin6_family = .INET6,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -3501,21 +3501,21 @@ gb_internal bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type
|
|||||||
// forbidden, so just skip them.
|
// forbidden, so just skip them.
|
||||||
if (forbid_identical && check_vet_flags(c) & VetFlag_Cast &&
|
if (forbid_identical && check_vet_flags(c) & VetFlag_Cast &&
|
||||||
(c->curr_proc_sig == nullptr || !is_type_polymorphic(c->curr_proc_sig))) {
|
(c->curr_proc_sig == nullptr || !is_type_polymorphic(c->curr_proc_sig))) {
|
||||||
bool is_runtime = false;
|
|
||||||
if (c->pkg && (c->pkg->kind == Package_Runtime || c->pkg->kind == Package_Builtin)) {
|
|
||||||
is_runtime = true;
|
|
||||||
}
|
|
||||||
if (are_types_identical(src_t, dst_t)) {
|
if (are_types_identical(src_t, dst_t)) {
|
||||||
if (!is_runtime) {
|
gbString oper_str = expr_to_string(o->expr);
|
||||||
gbString oper_str = expr_to_string(o->expr);
|
gbString to_type = type_to_string(dst_t);
|
||||||
gbString to_type = type_to_string(dst_t);
|
error(o->expr, "Unneeded transmute of '%s' to identical type '%s'", oper_str, to_type);
|
||||||
error(o->expr, "Unneeded transmute of '%s' to identical type '%s'", oper_str, to_type);
|
gb_string_free(oper_str);
|
||||||
gb_string_free(oper_str);
|
gb_string_free(to_type);
|
||||||
gb_string_free(to_type);
|
|
||||||
}
|
|
||||||
} else if (is_type_internally_pointer_like(src_t) &&
|
} else if (is_type_internally_pointer_like(src_t) &&
|
||||||
is_type_internally_pointer_like(dst_t)) {
|
is_type_internally_pointer_like(dst_t)) {
|
||||||
error(o->expr, "Use of 'transmute' where 'cast' would be preferred since the types are pointer-like");
|
error(o->expr, "Use of 'transmute' where 'cast' would be preferred since the types are pointer-like");
|
||||||
|
} else if (are_types_identical(src_bt, dst_bt)) {
|
||||||
|
gbString oper_str = expr_to_string(o->expr);
|
||||||
|
gbString to_type = type_to_string(dst_t);
|
||||||
|
error(o->expr, "Unneeded transmute of '%s' to identical type '%s'", oper_str, to_type);
|
||||||
|
gb_string_free(oper_str);
|
||||||
|
gb_string_free(to_type);
|
||||||
} else if (is_type_integer(src_t) && is_type_integer(dst_t) &&
|
} else if (is_type_integer(src_t) && is_type_integer(dst_t) &&
|
||||||
types_have_same_internal_endian(src_t, dst_t)) {
|
types_have_same_internal_endian(src_t, dst_t)) {
|
||||||
gbString oper_type = type_to_string(src_t);
|
gbString oper_type = type_to_string(src_t);
|
||||||
|
|||||||
Reference in New Issue
Block a user