diff --git a/src/types.h b/src/types.h index 561a437..75c8a84 100644 --- a/src/types.h +++ b/src/types.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include typedef enum { TYPE_TYPE_PRIMITIVE, TYPE_TYPE_RECORD, TYPE_TYPE_POINTER, TYPE_TYPE_FUNCTION, TYPE_TYPE_ARRAY, TYPE_TYPE_GENERIC, TYPE_TYPE_ERROR @@ -117,6 +119,21 @@ static inline bool type_is_segmented_pointer(Type *type) { return type->type == TYPE_TYPE_RECORD && !!strstr(type->record.name, " @far*"); } +static inline bool type_is_any_pointer(Type *type) { + return type->type == TYPE_TYPE_POINTER || type_is_segmented_pointer(type); +} +static inline Type *type_dereference(Type *type) { + assert(type_is_any_pointer(type)); + + if(type->type == TYPE_TYPE_POINTER) { + return type->pointer.of; + } else if(type_is_segmented_pointer(type)) { + return type->record.fieldTypes[1]->pointer.of; + } + + abort(); +} + static inline Type *type_u(size_t bits) { char buf[32]; snprintf(buf, sizeof(buf), "u%lu", bits);