aboutsummaryrefslogtreecommitdiff
path: root/src/types.c
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-04 01:31:55 -0500
committerMustafa Quraish <[email protected]>2022-02-04 01:31:55 -0500
commitcaf131c26deaf363b2fce95a7fda676729eb2e65 (patch)
tree75d6aa001969645fdbbe9a1890b85f63ce361f9f /src/types.c
parentMinor fixes, rearranging, whitespace trimming. No functional changes. (diff)
downloadcup-caf131c26deaf363b2fce95a7fda676729eb2e65.tar.xz
cup-caf131c26deaf363b2fce95a7fda676729eb2e65.zip
Some minor bug fixes
(1) Return correct size for unions (2) Make sure function name identifier doesn't exist (3) Assign `<anonymous>` as display name for nested compound types
Diffstat (limited to 'src/types.c')
-rw-r--r--src/types.c8
1 files changed, 5 insertions, 3 deletions
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;
}