mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 20:00:09 +00:00
Make core and vendor adhere to -vet, -strict-style, and -disallow-do
This commit is contained in:
@@ -182,18 +182,20 @@ FP_SUBNORMAL :: 4
|
||||
@(private)
|
||||
_fpclassify :: #force_inline proc(x: double) -> int {
|
||||
u := transmute(uint64_t)x
|
||||
e := u >> 52 & 0x7ff
|
||||
if e == 0 do return FP_SUBNORMAL if (u << 1) != 0 else FP_ZERO
|
||||
if e == 0x7ff do return FP_NAN if (u << 12) != 0 else FP_INFINITE
|
||||
switch e := u >> 52 & 0x7ff; e {
|
||||
case 0: return FP_SUBNORMAL if (u << 1) != 0 else FP_ZERO
|
||||
case 0x7ff: return FP_NAN if (u << 12) != 0 else FP_INFINITE
|
||||
}
|
||||
return FP_NORMAL
|
||||
}
|
||||
|
||||
@(private)
|
||||
_fpclassifyf :: #force_inline proc(x: float) -> int {
|
||||
u := transmute(uint32_t)x
|
||||
e := u >> 23 & 0xff
|
||||
if e == 0 do return FP_SUBNORMAL if (u << 1) != 0 else FP_ZERO
|
||||
if e == 0xff do return FP_NAN if (u << 9) != 0 else FP_INFINITE
|
||||
switch e := u >> 23 & 0xff; e {
|
||||
case 0: return FP_SUBNORMAL if (u << 1) != 0 else FP_ZERO
|
||||
case 0xff: return FP_NAN if (u << 9) != 0 else FP_INFINITE
|
||||
}
|
||||
return FP_NORMAL
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ atomic_exchange_explicit :: #force_inline proc(object: ^$T, desired: T, order: m
|
||||
// [success = acq_rel, failure = relaxed] => acqrel_failrelaxed
|
||||
atomic_compare_exchange_strong :: #force_inline proc(object, expected: ^$T, desired: T) {
|
||||
value, ok := intrinsics.atomic_cxchg(object, expected^, desired)
|
||||
if !ok do expected^ = value
|
||||
if !ok { expected^ = value }
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -236,13 +236,13 @@ atomic_compare_exchange_strong_explicit :: #force_inline proc(object, expected:
|
||||
value, ok := intrinsics.atomic_cxchg_failacq(object, expected^, desired)
|
||||
|
||||
}
|
||||
if !ok do expected^ = value
|
||||
if !ok { expected^ = value }
|
||||
return ok
|
||||
}
|
||||
|
||||
atomic_compare_exchange_weak :: #force_inline proc(object, expected: ^$T, desired: T) {
|
||||
value, ok := intrinsics.atomic_cxchgweak(object, expected^, desired)
|
||||
if !ok do expected^ = value
|
||||
if !ok { expected^ = value }
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ atomic_compare_exchange_weak_explicit :: #force_inline proc(object, expected: ^$
|
||||
value, ok := intrinsics.atomic_cxchgweak_failacq(object, expected^, desired)
|
||||
|
||||
}
|
||||
if !ok do expected^ = value
|
||||
if !ok { expected^ = value }
|
||||
return ok
|
||||
}
|
||||
|
||||
|
||||
@@ -71,13 +71,17 @@ priority_queue_push :: proc(q: ^$Q/Priority_Queue($T), item: T) {
|
||||
i := q.len
|
||||
for i > 0 {
|
||||
p := (i - 1) / 2
|
||||
if q.priority(s[p]) <= q.priority(item) do break
|
||||
if q.priority(s[p]) <= q.priority(item) {
|
||||
break
|
||||
}
|
||||
s[i] = s[p]
|
||||
i = p
|
||||
}
|
||||
|
||||
q.len += 1
|
||||
if q.len > 0 do s[i] = item
|
||||
if q.len > 0 {
|
||||
s[i] = item
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,12 +100,16 @@ priority_queue_pop :: proc(q: ^$Q/Priority_Queue($T)) -> T {
|
||||
b := i * 2 + 2
|
||||
c := b < q.len && q.priority(s[b]) < q.priority(s[a]) ? b : a
|
||||
|
||||
if q.priority(s[c]) >= q.priority(root) do break
|
||||
if q.priority(s[c]) >= q.priority(root) {
|
||||
break
|
||||
}
|
||||
s[i] = s[c]
|
||||
i = c
|
||||
}
|
||||
|
||||
if q.len > 0 do s[i] = root
|
||||
if q.len > 0 {
|
||||
s[i] = root
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ clone_array :: proc(array: $A/[]^$T) -> A {
|
||||
}
|
||||
res := make(A, len(array))
|
||||
for elem, i in array {
|
||||
res[i] = auto_cast clone(elem)
|
||||
res[i] = (^T)(clone(elem))
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -40,7 +40,7 @@ clone_dynamic_array :: proc(array: $A/[dynamic]^$T) -> A {
|
||||
}
|
||||
res := make(A, len(array))
|
||||
for elem, i in array {
|
||||
res[i] = auto_cast clone(elem)
|
||||
res[i] = (^T)(clone(elem))
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -169,10 +169,10 @@ clone_node :: proc(node: ^Node) -> ^Node {
|
||||
r.lhs = clone(r.lhs)
|
||||
r.rhs = clone(r.rhs)
|
||||
case Block_Stmt:
|
||||
r.label = auto_cast clone(r.label)
|
||||
r.label = clone(r.label)
|
||||
r.stmts = clone(r.stmts)
|
||||
case If_Stmt:
|
||||
r.label = auto_cast clone(r.label)
|
||||
r.label = clone(r.label)
|
||||
r.init = clone(r.init)
|
||||
r.cond = clone(r.cond)
|
||||
r.body = clone(r.body)
|
||||
@@ -186,13 +186,13 @@ clone_node :: proc(node: ^Node) -> ^Node {
|
||||
case Defer_Stmt:
|
||||
r.stmt = clone(r.stmt)
|
||||
case For_Stmt:
|
||||
r.label = auto_cast clone(r.label)
|
||||
r.label = clone(r.label)
|
||||
r.init = clone(r.init)
|
||||
r.cond = clone(r.cond)
|
||||
r.post = clone(r.post)
|
||||
r.body = clone(r.body)
|
||||
case Range_Stmt:
|
||||
r.label = auto_cast clone(r.label)
|
||||
r.label = clone(r.label)
|
||||
r.vals = clone(r.vals)
|
||||
r.expr = clone(r.expr)
|
||||
r.body = clone(r.body)
|
||||
@@ -200,12 +200,12 @@ clone_node :: proc(node: ^Node) -> ^Node {
|
||||
r.list = clone(r.list)
|
||||
r.body = clone(r.body)
|
||||
case Switch_Stmt:
|
||||
r.label = auto_cast clone(r.label)
|
||||
r.label = clone(r.label)
|
||||
r.init = clone(r.init)
|
||||
r.cond = clone(r.cond)
|
||||
r.body = clone(r.body)
|
||||
case Type_Switch_Stmt:
|
||||
r.label = auto_cast clone(r.label)
|
||||
r.label = clone(r.label)
|
||||
r.tag = clone(r.tag)
|
||||
r.expr = clone(r.expr)
|
||||
r.body = clone(r.body)
|
||||
|
||||
@@ -414,7 +414,7 @@ expect_closing_brace_of_field_list :: proc(p: ^Parser) -> tokenizer.Token {
|
||||
}
|
||||
if allow_token(p, .Semicolon) {
|
||||
str := tokenizer.token_to_string(token)
|
||||
error(p, end_of_line_pos(p, p.prev_tok), "expected a comma, got %s", p)
|
||||
error(p, end_of_line_pos(p, p.prev_tok), "expected a comma, got %s", str)
|
||||
}
|
||||
return expect_token(p, .Close_Brace)
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ format_value_decl :: proc(p: ^Printer, index: int) {
|
||||
align_next := false
|
||||
|
||||
//check to see if there is a binary operator in the last token(this is guaranteed by the ast visit), otherwise it's not multilined
|
||||
for line, line_index in p.lines[eq_line:] {
|
||||
for line in p.lines[eq_line:] {
|
||||
|
||||
if len(line.format_tokens) == 0 {
|
||||
break
|
||||
@@ -309,7 +309,7 @@ format_call :: proc(p: ^Printer, line_index: int, format_index: int) {
|
||||
paren_count := 1
|
||||
done := false
|
||||
|
||||
for line, line_index in p.lines[paren_line:] {
|
||||
for line in p.lines[paren_line:] {
|
||||
|
||||
if len(line.format_tokens) == 0 {
|
||||
continue
|
||||
@@ -374,7 +374,7 @@ format_keyword_to_brace :: proc(p: ^Printer, line_index: int, format_index: int,
|
||||
panic("Should not be possible")
|
||||
}
|
||||
|
||||
for line, line_index in p.lines[keyword_line:] {
|
||||
for line, line_idx in p.lines[keyword_line:] {
|
||||
|
||||
if len(line.format_tokens) == 0 {
|
||||
continue
|
||||
@@ -388,7 +388,7 @@ format_keyword_to_brace :: proc(p: ^Printer, line_index: int, format_index: int,
|
||||
return
|
||||
}
|
||||
|
||||
if line_index == 0 && i <= format_index {
|
||||
if line_idx == 0 && i <= format_index {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ format_keyword_to_brace :: proc(p: ^Printer, line_index: int, format_index: int,
|
||||
}
|
||||
}
|
||||
|
||||
if line_index != 0 {
|
||||
if line_idx != 0 {
|
||||
line.format_tokens[0].spaces_before = largest + 1
|
||||
}
|
||||
|
||||
@@ -908,7 +908,7 @@ align_comments :: proc(p: ^Printer) {
|
||||
|
||||
length := 0
|
||||
|
||||
for format_token, i in l.format_tokens {
|
||||
for format_token in l.format_tokens {
|
||||
if format_token.kind == .Comment {
|
||||
if len(l.format_tokens) == 1 {
|
||||
l.format_tokens[i].spaces_before = info.length + 1
|
||||
|
||||
@@ -499,7 +499,7 @@ visit_attributes :: proc(p: ^Printer, attributes: [dynamic]^ast.Attribute) {
|
||||
return
|
||||
}
|
||||
|
||||
for attribute, i in attributes {
|
||||
for attribute in attributes {
|
||||
move_line_limit(p, attribute.pos, 1)
|
||||
|
||||
push_generic_token(p, .At, 0)
|
||||
@@ -1389,7 +1389,6 @@ visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type, is_proc_lit := fa
|
||||
push_generic_token(p, .Gt, 0)
|
||||
|
||||
use_parens := false
|
||||
use_named := false
|
||||
|
||||
if len(proc_type.results.list) > 1 {
|
||||
use_parens = true
|
||||
|
||||
@@ -135,9 +135,13 @@ has_suffix :: proc(array: $T/[]$E, needle: E) -> bool where intrinsics.type_is_c
|
||||
return false
|
||||
}
|
||||
|
||||
fill :: proc(array: $T/[]$E, value: E) {
|
||||
for _, i in array {
|
||||
array[i] = value
|
||||
fill :: proc(array: $T/[]$E, value: E) #no_bounds_check {
|
||||
if len(array) <= 0 {
|
||||
return
|
||||
}
|
||||
array[0] = value
|
||||
for i := 1; i < len(array); i *= 2 {
|
||||
copy(array[i:], array[:i])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,9 @@ _open_file_dialog :: proc(title: string, dir: string,
|
||||
|
||||
// Filters need to be passed as a pair of strings (title, filter)
|
||||
filter_len := u32(len(filters))
|
||||
if filter_len % 2 != 0 do return "", false
|
||||
if filter_len % 2 != 0 {
|
||||
return "", false
|
||||
}
|
||||
|
||||
filter: string
|
||||
filter = strings.join(filters, "\u0000", context.temp_allocator)
|
||||
|
||||
@@ -837,7 +837,9 @@ wstring_to_utf8 :: proc(s: Wstring, N: int, allocator := context.temp_allocator)
|
||||
}
|
||||
|
||||
utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string {
|
||||
if len(s) == 0 do return ""
|
||||
if len(s) == 0 {
|
||||
return ""
|
||||
}
|
||||
return wstring_to_utf8(cast(Wstring)&s[0], len(s), allocator)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user