mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Minor refactor
This commit is contained in:
+9
-14
@@ -694,6 +694,8 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) {
|
|||||||
ast_node(bs, BitSetType, node);
|
ast_node(bs, BitSetType, node);
|
||||||
GB_ASSERT(type->kind == Type_BitSet);
|
GB_ASSERT(type->kind == Type_BitSet);
|
||||||
|
|
||||||
|
i64 const MAX_BITS = 64;
|
||||||
|
|
||||||
Ast *base = unparen_expr(bs->base);
|
Ast *base = unparen_expr(bs->base);
|
||||||
if (is_ast_range(base)) {
|
if (is_ast_range(base)) {
|
||||||
ast_node(be, BinaryExpr, base);
|
ast_node(be, BinaryExpr, base);
|
||||||
@@ -701,10 +703,7 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) {
|
|||||||
Operand rhs = {};
|
Operand rhs = {};
|
||||||
check_expr(c, &lhs, be->left);
|
check_expr(c, &lhs, be->left);
|
||||||
check_expr(c, &rhs, be->right);
|
check_expr(c, &rhs, be->right);
|
||||||
if (lhs.mode == Addressing_Invalid) {
|
if (lhs.mode == Addressing_Invalid || rhs.mode == Addressing_Invalid) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (rhs.mode == Addressing_Invalid) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
convert_to_typed(c, &lhs, rhs.type);
|
convert_to_typed(c, &lhs, rhs.type);
|
||||||
@@ -760,9 +759,7 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) {
|
|||||||
|
|
||||||
Type *t = default_type(lhs.type);
|
Type *t = default_type(lhs.type);
|
||||||
|
|
||||||
bool ok = true;
|
if (!check_representable_as_constant(c, iv, t, nullptr)) {
|
||||||
ok = check_representable_as_constant(c, iv, t, nullptr);
|
|
||||||
if (!ok) {
|
|
||||||
gbAllocator a = heap_allocator();
|
gbAllocator a = heap_allocator();
|
||||||
String s = big_int_to_string(a, &i);
|
String s = big_int_to_string(a, &i);
|
||||||
gbString ts = type_to_string(t);
|
gbString ts = type_to_string(t);
|
||||||
@@ -771,8 +768,7 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) {
|
|||||||
gb_free(a, s.text);
|
gb_free(a, s.text);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ok = check_representable_as_constant(c, iv, t, nullptr);
|
if (!check_representable_as_constant(c, iv, t, nullptr)) {
|
||||||
if (!ok) {
|
|
||||||
gbAllocator a = heap_allocator();
|
gbAllocator a = heap_allocator();
|
||||||
String s = big_int_to_string(a, &j);
|
String s = big_int_to_string(a, &j);
|
||||||
gbString ts = type_to_string(t);
|
gbString ts = type_to_string(t);
|
||||||
@@ -784,8 +780,8 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) {
|
|||||||
i64 lower = big_int_to_i64(&i);
|
i64 lower = big_int_to_i64(&i);
|
||||||
i64 upper = big_int_to_i64(&j);
|
i64 upper = big_int_to_i64(&j);
|
||||||
|
|
||||||
if (upper - lower > 64) {
|
if (upper - lower > MAX_BITS) {
|
||||||
error(bs->base, "bit_set range is greater than 64 bits, %lld bits are required", (upper-lower+1));
|
error(bs->base, "bit_set range is greater than %lld bits, %lld bits are required", MAX_BITS, (upper-lower+1));
|
||||||
}
|
}
|
||||||
type->BitSet.base = t;
|
type->BitSet.base = t;
|
||||||
type->BitSet.lower = lower;
|
type->BitSet.lower = lower;
|
||||||
@@ -806,7 +802,6 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) {
|
|||||||
}
|
}
|
||||||
i64 lower = 0;
|
i64 lower = 0;
|
||||||
i64 upper = 0;
|
i64 upper = 0;
|
||||||
BigInt v64 = {}; big_int_from_i64(&v64, 64);
|
|
||||||
|
|
||||||
for_array(i, et->Enum.fields) {
|
for_array(i, et->Enum.fields) {
|
||||||
Entity *e = et->Enum.fields[i];
|
Entity *e = et->Enum.fields[i];
|
||||||
@@ -823,8 +818,8 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) {
|
|||||||
|
|
||||||
GB_ASSERT(lower <= upper);
|
GB_ASSERT(lower <= upper);
|
||||||
|
|
||||||
if (upper - lower > 64) {
|
if (upper - lower > MAX_BITS) {
|
||||||
error(bs->base, "bit_set range is greater than 64 bits, %lld bits are required", (upper-lower+1));
|
error(bs->base, "bit_set range is greater than %lld bits, %lld bits are required", MAX_BITS, (upper-lower+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
type->BitSet.lower = lower;
|
type->BitSet.lower = lower;
|
||||||
|
|||||||
Reference in New Issue
Block a user