diff options
| author | gingerBill <bill@gingerbill.org> | 2018-08-16 20:52:46 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-08-16 20:52:46 +0100 |
| commit | 7d39b26cf4537943ecd668777d830dfa8579edbe (patch) | |
| tree | d5a86b976933723b742969b933640b216fc7993b /src | |
| parent | 884d5fed9f2894a91ede38fb073338b1fe94a483 (diff) | |
Minor refactor
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_type.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index bbae12654..dccaafae0 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -694,6 +694,8 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) { ast_node(bs, BitSetType, node); GB_ASSERT(type->kind == Type_BitSet); + i64 const MAX_BITS = 64; + Ast *base = unparen_expr(bs->base); if (is_ast_range(base)) { ast_node(be, BinaryExpr, base); @@ -701,10 +703,7 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) { Operand rhs = {}; check_expr(c, &lhs, be->left); check_expr(c, &rhs, be->right); - if (lhs.mode == Addressing_Invalid) { - return; - } - if (rhs.mode == Addressing_Invalid) { + if (lhs.mode == Addressing_Invalid || rhs.mode == Addressing_Invalid) { return; } 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); - bool ok = true; - ok = check_representable_as_constant(c, iv, t, nullptr); - if (!ok) { + if (!check_representable_as_constant(c, iv, t, nullptr)) { gbAllocator a = heap_allocator(); String s = big_int_to_string(a, &i); 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); return; } - ok = check_representable_as_constant(c, iv, t, nullptr); - if (!ok) { + if (!check_representable_as_constant(c, iv, t, nullptr)) { gbAllocator a = heap_allocator(); String s = big_int_to_string(a, &j); 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 upper = big_int_to_i64(&j); - if (upper - lower > 64) { - error(bs->base, "bit_set range is greater than 64 bits, %lld bits are required", (upper-lower+1)); + if (upper - lower > MAX_BITS) { + 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.lower = lower; @@ -806,7 +802,6 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) { } i64 lower = 0; i64 upper = 0; - BigInt v64 = {}; big_int_from_i64(&v64, 64); for_array(i, et->Enum.fields) { 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); - if (upper - lower > 64) { - error(bs->base, "bit_set range is greater than 64 bits, %lld bits are required", (upper-lower+1)); + if (upper - lower > MAX_BITS) { + error(bs->base, "bit_set range is greater than %lld bits, %lld bits are required", MAX_BITS, (upper-lower+1)); } type->BitSet.lower = lower; |