type_dereference
This commit is contained in:
parent
2188448b19
commit
246f7a3b71
17
src/types.h
17
src/types.h
@ -6,6 +6,8 @@
|
||||
#include<stdbool.h>
|
||||
#include<string.h>
|
||||
#include<stdio.h>
|
||||
#include<assert.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user