Remove bit_field type from Odin (keyword and dead runtime code still exists)

This commit is contained in:
gingerBill
2021-02-19 11:31:14 +00:00
parent f332cf498d
commit efdee0dafb
17 changed files with 77 additions and 911 deletions
+3 -101
View File
@@ -58,22 +58,6 @@ void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field
}
}
}
} else if (t->kind == Type_BitField) {
for_array(i, t->BitField.fields) {
Entity *f = t->BitField.fields[i];
String name = f->token.string;
Entity *e = scope_lookup_current(ctx->scope, name);
if ((e != nullptr && name != "_") && (e != f)) {
// TODO(bill): Better type error
if (str != nullptr) {
error(e->token, "'%.*s' is already declared in '%s'", LIT(name), str);
} else {
error(e->token, "'%.*s' is already declared", LIT(name));
}
} else {
add_entity(ctx->checker, ctx->scope, nullptr, f);
}
}
} else if (t->kind == Type_Array && t->Array.count <= 4) {
Entity *e = nullptr;
String name = {};
@@ -107,8 +91,6 @@ bool does_field_type_allow_using(Type *t) {
return true;
} else if (is_type_raw_union(t)) {
return true;
} else if (is_type_bit_field(t)) {
return true;
} else if (is_type_array(t)) {
return t->Array.count <= 4;
} else if (is_type_typeid(t)) {
@@ -981,82 +963,6 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast
enum_type->Enum.max_value_index = max_value_index;
}
void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type, Ast *node) {
ast_node(bft, BitFieldType, node);
GB_ASSERT(is_type_bit_field(bit_field_type));
auto fields = array_make<Entity*>(permanent_allocator(), 0, bft->fields.count);
auto sizes = array_make<u32> (permanent_allocator(), 0, bft->fields.count);
auto offsets = array_make<u32> (permanent_allocator(), 0, bft->fields.count);
scope_reserve(ctx->scope, bft->fields.count);
u32 curr_offset = 0;
for_array(i, bft->fields) {
Ast *field = bft->fields[i];
GB_ASSERT(field->kind == Ast_FieldValue);
Ast *ident = field->FieldValue.field;
Ast *value = field->FieldValue.value;
if (ident->kind != Ast_Ident) {
error(field, "A bit field value's name must be an identifier");
continue;
}
String name = ident->Ident.token.string;
Operand o = {};
check_expr(ctx, &o, value);
if (o.mode != Addressing_Constant) {
error(value, "Bit field bit size must be a constant");
continue;
}
ExactValue v = exact_value_to_integer(o.value);
if (v.kind != ExactValue_Integer) {
error(value, "Bit field bit size must be a constant integer");
continue;
}
i64 bits_ = big_int_to_i64(&v.value_integer); // TODO(bill): what if the integer is huge?
if (bits_ < 0 || bits_ > 64) {
error(value, "Bit field's bit size must be within the range 1...64, got %lld", cast(long long)bits_);
continue;
}
u32 bits = cast(u32)bits_;
Type *value_type = alloc_type_bit_field_value(bits);
Entity *e = alloc_entity_variable(bit_field_type->BitField.scope, ident->Ident.token, value_type);
e->identifier = ident;
e->flags |= EntityFlag_BitFieldValue;
if (!is_blank_ident(name) &&
scope_lookup_current(ctx->scope, name) != nullptr) {
error(ident, "'%.*s' is already declared in this bit field", LIT(name));
} else {
add_entity(ctx->checker, ctx->scope, nullptr, e);
// TODO(bill): Should this entity be "used"?
add_entity_use(ctx, field, e);
array_add(&fields, e);
array_add(&offsets, curr_offset);
array_add(&sizes, bits);
curr_offset += bits;
}
}
GB_ASSERT(fields.count <= bft->fields.count);
bit_field_type->BitField.fields = fields;
bit_field_type->BitField.sizes = sizes;
bit_field_type->BitField.offsets = offsets;
if (bft->align != nullptr) {
i64 custom_align = 1;
if (check_custom_align(ctx, bft->align, &custom_align)) {
bit_field_type->BitField.custom_align = custom_align;
}
}
}
bool is_type_valid_bit_set_range(Type *t) {
if (is_type_integer(t)) {
return true;
@@ -2066,7 +1972,6 @@ Array<Type *> systemv_distribute_struct_fields(Type *t) {
case Type_Union:
case Type_DynamicArray:
case Type_Map:
case Type_BitField: // TODO(bill): Ignore?
// NOTE(bill, 2019-10-10): Odin specific, don't worry about C calling convention yet
goto DEFAULT;
@@ -3619,12 +3524,9 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t
case_end;
case_ast_node(et, BitFieldType, e);
*type = alloc_type_bit_field();
set_base_type(named_type, *type);
check_open_scope(ctx, e);
check_bit_field_type(ctx, *type, e);
check_close_scope(ctx);
return true;
error(e, "'bit_field' types have now been removed");
error_line("\tSuggestion: package math/bits 'bitfield_extract' and 'bitfield_insert' are better replacements\n");
return false;
case_end;
case_ast_node(bs, BitSetType, e);