fix sizeof array types

This commit is contained in:
Nikita Smith
2024-10-19 20:39:40 -07:00
parent 68c0906570
commit dbcecd99af
+17 -20
View File
@@ -1177,29 +1177,26 @@ internal U64
rdib_sizeof_type(RDIB_Type *type) rdib_sizeof_type(RDIB_Type *type)
{ {
U64 size = 0; U64 size = 0;
if (RDI_TypeKind_FirstBuiltIn <= type->kind && type->kind < RDI_TypeKind_LastBuiltIn) {
RDIB_Type *curr = type; size = type->builtin.size;
while (curr->kind == RDI_TypeKind_Modifier) { } else if (type->kind == RDI_TypeKind_Modifier) {
curr = curr->modifier.type_ref; size = rdib_sizeof_type(type->modifier.type_ref);
} } else if (type->kind == RDI_TypeKind_Ptr || type->kind == RDI_TypeKind_LRef || type->kind == RDI_TypeKind_RRef) {
size = type->ptr.size;
if (RDI_TypeKind_FirstBuiltIn <= curr->kind && curr->kind < RDI_TypeKind_LastBuiltIn) { } else if (type->kind == RDI_TypeKind_Struct || type->kind == RDI_TypeKind_Class ||
size = curr->builtin.size; type->kind == RDI_TypeKind_IncompleteStruct || type->kind == RDI_TypeKind_IncompleteClass) {
} else if (curr->kind == RDI_TypeKind_Ptr || curr->kind == RDI_TypeKind_LRef || curr->kind == RDI_TypeKind_RRef) { size = type->udt.struct_type.size;
size = curr->ptr.size; } else if (type->kind == RDI_TypeKind_Union || type->kind == RDI_TypeKind_IncompleteUnion) {
} else if (curr->kind == RDI_TypeKind_Struct || curr->kind == RDI_TypeKind_Class || size = type->udt.union_type.size;
curr->kind == RDI_TypeKind_IncompleteStruct || curr->kind == RDI_TypeKind_IncompleteClass) { } else if (type->kind == RDI_TypeKind_Enum || type->kind == RDI_TypeKind_IncompleteEnum) {
size = curr->udt.struct_type.size; size = rdib_sizeof_type(type->udt.enum_type.base_type);
} else if (curr->kind == RDI_TypeKind_Union || curr->kind == RDI_TypeKind_IncompleteUnion) { } else if (type->kind == RDI_TypeKind_Bitfield) {
size = curr->udt.union_type.size; size = rdib_sizeof_type(type->bitfield.value_type);
} else if (curr->kind == RDI_TypeKind_Enum || curr->kind == RDI_TypeKind_IncompleteEnum) { } else if (type->kind == RDI_TypeKind_Array) {
size = rdib_sizeof_type(curr->udt.enum_type.base_type); size = type->array.size;
} else if (curr->kind == RDI_TypeKind_Bitfield) {
size = rdib_sizeof_type(curr->bitfield.value_type);
} else { } else {
Assert(!"error: type doens't have a size"); Assert(!"error: type doens't have a size");
} }
return size; return size;
} }