From caf131c26deaf363b2fce95a7fda676729eb2e65 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 4 Feb 2022 01:31:55 -0500 Subject: Some minor bug fixes (1) Return correct size for unions (2) Make sure function name identifier doesn't exist (3) Assign `` as display name for nested compound types --- src/types.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/types.c') diff --git a/src/types.c b/src/types.c index d004634..8ac4c77 100644 --- a/src/types.c +++ b/src/types.c @@ -37,6 +37,7 @@ i64 size_for_type(Type *type) case TYPE_CHAR: return 1; case TYPE_ARRAY: return type->array_size * size_for_type(type->ptr); case TYPE_STRUCT: return type->fields.size; + case TYPE_UNION: return type->fields.size; default: { printf("Unknown type: %d\n", type->type); assert(false && "Unreachable type"); @@ -89,10 +90,11 @@ bool is_int_type(Type *type) bool is_struct_or_struct_ptr(Type *type) { - if (type->type == TYPE_STRUCT) - return true; - if (type->type == TYPE_PTR && type->ptr->type == TYPE_STRUCT) + if (type->type == TYPE_STRUCT || type->type == TYPE_UNION) return true; + if (type->type == TYPE_PTR) + if (type->ptr->type == TYPE_STRUCT || type->ptr->type == TYPE_UNION) + return true; return false; } -- cgit v1.2.3