mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-23 22:25:00 -07:00
Fix #1174
This commit is contained in:
+9
-7
@@ -2072,14 +2072,16 @@ void init_map_entry_type(Type *type) {
|
||||
Scope *s = create_scope(nullptr, builtin_pkg->scope);
|
||||
|
||||
auto fields = slice_make<Entity *>(permanent_allocator(), 4);
|
||||
fields[0] = alloc_entity_field(s, make_token_ident(str_lit("hash")), t_uintptr, false, cast(i32)fields.count, EntityState_Resolved);
|
||||
fields[1] = alloc_entity_field(s, make_token_ident(str_lit("next")), t_int, false, cast(i32)fields.count, EntityState_Resolved);
|
||||
fields[2] = alloc_entity_field(s, make_token_ident(str_lit("key")), type->Map.key, false, cast(i32)fields.count, EntityState_Resolved);
|
||||
fields[3] = alloc_entity_field(s, make_token_ident(str_lit("value")), type->Map.value, false, cast(i32)fields.count, EntityState_Resolved);
|
||||
fields[0] = alloc_entity_field(s, make_token_ident(str_lit("hash")), t_uintptr, false, 0, EntityState_Resolved);
|
||||
fields[1] = alloc_entity_field(s, make_token_ident(str_lit("next")), t_int, false, 1, EntityState_Resolved);
|
||||
fields[2] = alloc_entity_field(s, make_token_ident(str_lit("key")), type->Map.key, false, 2, EntityState_Resolved);
|
||||
fields[3] = alloc_entity_field(s, make_token_ident(str_lit("value")), type->Map.value, false, 3, EntityState_Resolved);
|
||||
|
||||
|
||||
entry_type->Struct.fields = fields;
|
||||
|
||||
entry_type->Struct.fields = fields;
|
||||
entry_type->Struct.tags = gb_alloc_array(permanent_allocator(), String, fields.count);
|
||||
|
||||
type_set_offsets(entry_type);
|
||||
type->Map.entry_type = entry_type;
|
||||
}
|
||||
|
||||
@@ -2113,8 +2115,8 @@ void init_map_internal_types(Type *type) {
|
||||
fields[1] = alloc_entity_field(s, make_token_ident(str_lit("entries")), entries_type, false, 1, EntityState_Resolved);
|
||||
|
||||
generated_struct_type->Struct.fields = fields;
|
||||
|
||||
type_set_offsets(generated_struct_type);
|
||||
|
||||
type->Map.generated_struct_type = generated_struct_type;
|
||||
type->Map.internal_type = generated_struct_type;
|
||||
type->Map.lookup_result_type = make_optional_ok_type(value);
|
||||
|
||||
@@ -322,6 +322,7 @@ lbValue lb_get_hasher_proc_for_type(lbModule *m, Type *type) {
|
||||
|
||||
auto args = array_make<lbValue>(permanent_allocator(), 2);
|
||||
for_array(i, type->Struct.fields) {
|
||||
GB_ASSERT(type->Struct.offsets != nullptr);
|
||||
i64 offset = type->Struct.offsets[i];
|
||||
Entity *field = type->Struct.fields[i];
|
||||
lbValue field_hasher = lb_get_hasher_proc_for_type(m, field->type);
|
||||
|
||||
@@ -714,6 +714,7 @@ void lb_debug_complete_types(lbModule *m) {
|
||||
|
||||
unsigned field_line = 0;
|
||||
LLVMDIFlags field_flags = LLVMDIFlagZero;
|
||||
GB_ASSERT(bt->Struct.offsets != nullptr);
|
||||
u64 offset_in_bits = 8*cast(u64)bt->Struct.offsets[j];
|
||||
|
||||
elements[element_offset+j] = LLVMDIBuilderCreateMemberType(
|
||||
|
||||
@@ -1667,6 +1667,8 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
|
||||
case Type_Struct:
|
||||
{
|
||||
type_set_offsets(type);
|
||||
|
||||
if (type->Struct.is_raw_union) {
|
||||
unsigned field_count = 2;
|
||||
LLVMTypeRef *fields = gb_alloc_array(permanent_allocator(), LLVMTypeRef, field_count);
|
||||
@@ -1695,8 +1697,10 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
|
||||
i64 padding_offset = 0;
|
||||
for_array(i, type->Struct.fields) {
|
||||
GB_ASSERT(type->Struct.offsets != nullptr);
|
||||
|
||||
Entity *field = type->Struct.fields[i];
|
||||
i64 padding = type->Struct.offsets[i]-padding_offset;
|
||||
i64 padding = type->Struct.offsets[i] - padding_offset;
|
||||
|
||||
LLVMTypeRef padding_type = nullptr;
|
||||
if (padding_offset == 0) {
|
||||
|
||||
@@ -728,7 +728,9 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
|
||||
lbValue tip = lb_get_type_info_ptr(m, f->type);
|
||||
i64 foffset = 0;
|
||||
if (!t->Struct.is_raw_union) {
|
||||
foffset = t->Struct.offsets[f->Variable.field_index];
|
||||
GB_ASSERT(t->Struct.offsets != nullptr);
|
||||
GB_ASSERT(0 <= f->Variable.field_index && f->Variable.field_index < count);
|
||||
foffset = t->Struct.offsets[source_index];
|
||||
}
|
||||
GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field);
|
||||
|
||||
@@ -779,11 +781,13 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
|
||||
case Type_Map: {
|
||||
tag = lb_const_ptr_cast(m, variant_ptr, t_type_info_map_ptr);
|
||||
init_map_internal_types(t);
|
||||
|
||||
lbValue gst = lb_get_type_info_ptr(m, t->Map.generated_struct_type);
|
||||
|
||||
LLVMValueRef vals[5] = {
|
||||
lb_get_type_info_ptr(m, t->Map.key).value,
|
||||
lb_get_type_info_ptr(m, t->Map.value).value,
|
||||
lb_get_type_info_ptr(m, t->Map.generated_struct_type).value,
|
||||
gst.value,
|
||||
lb_get_equal_proc_for_type(m, t->Map.key).value,
|
||||
lb_get_hasher_proc_for_type(m, t->Map.key).value
|
||||
};
|
||||
|
||||
@@ -3325,11 +3325,13 @@ i64 type_offset_of(Type *t, i32 index) {
|
||||
if (t->kind == Type_Struct) {
|
||||
type_set_offsets(t);
|
||||
if (gb_is_between(index, 0, t->Struct.fields.count-1)) {
|
||||
GB_ASSERT(t->Struct.offsets != nullptr);
|
||||
return t->Struct.offsets[index];
|
||||
}
|
||||
} else if (t->kind == Type_Tuple) {
|
||||
type_set_offsets(t);
|
||||
if (gb_is_between(index, 0, t->Tuple.variables.count-1)) {
|
||||
GB_ASSERT(t->Tuple.offsets != nullptr);
|
||||
return t->Tuple.offsets[index];
|
||||
}
|
||||
} else if (t->kind == Type_Basic) {
|
||||
|
||||
Reference in New Issue
Block a user