print_type_qualifiers(type->type.qualifiers);
const char *s;
- switch(type->atype) {
+ switch(type->akind) {
case ATOMIC_TYPE_INVALID: s = "INVALIDATOMIC"; break;
case ATOMIC_TYPE_VOID: s = "void"; break;
case ATOMIC_TYPE_BOOL: s = "_Bool"; break;
static void intern_print_type_pre(const type_t *const type, const bool top)
{
switch(type->kind) {
+ case TYPE_ERROR:
+ fputs("<error>", out);
case TYPE_INVALID:
- fputs("invalid", out);
+ fputs("<invalid>", out);
return;
case TYPE_ENUM:
print_type_enum(&type->enumt);
case TYPE_BITFIELD:
print_bitfield_type_post(&type->bitfield);
return;
+ case TYPE_ERROR:
case TYPE_INVALID:
case TYPE_ATOMIC:
case TYPE_ENUM:
case TYPE_TYPEDEF: return sizeof(typedef_type_t);
case TYPE_TYPEOF: return sizeof(typeof_type_t);
case TYPE_BITFIELD: return sizeof(bitfield_type_t);
+ case TYPE_ERROR: panic("error type found");
case TYPE_INVALID: panic("invalid type found");
}
panic("unknown type found");
if(type->kind != TYPE_ATOMIC)
return false;
- switch(type->atomic.atype) {
+ switch(type->atomic.akind) {
case ATOMIC_TYPE_BOOL:
case ATOMIC_TYPE_CHAR:
case ATOMIC_TYPE_SCHAR:
if(type->kind != TYPE_ATOMIC)
return false;
- switch(type->atomic.atype) {
+ switch(type->atomic.akind) {
case ATOMIC_TYPE_FLOAT:
case ATOMIC_TYPE_DOUBLE:
case ATOMIC_TYPE_LONG_DOUBLE:
if(type->kind != TYPE_ATOMIC)
return false;
- switch(type->atomic.atype) {
+ switch(type->atomic.akind) {
case ATOMIC_TYPE_CHAR:
case ATOMIC_TYPE_SCHAR:
case ATOMIC_TYPE_SHORT:
return is_type_arithmetic(type);
}
+/**
+ * Check if a given type is incomplete
+ */
bool is_type_incomplete(const type_t *type)
{
assert(!is_typeref(type));
declaration_t *declaration = compound_type->declaration;
return !declaration->init.is_defined;
}
+ case TYPE_ENUM: {
+ const enum_type_t *enum_type = &type->enumt;
+ declaration_t *declaration = enum_type->declaration;
+ return !declaration->init.is_defined;
+ }
case TYPE_BITFIELD:
case TYPE_FUNCTION:
return true;
return type->array.size == NULL;
case TYPE_ATOMIC:
- return type->atomic.atype == ATOMIC_TYPE_VOID;
+ return type->atomic.akind == ATOMIC_TYPE_VOID;
case TYPE_POINTER:
- case TYPE_ENUM:
case TYPE_BUILTIN:
+ case TYPE_ERROR:
return false;
case TYPE_TYPEDEF:
case TYPE_FUNCTION:
return function_types_compatible(&type1->function, &type2->function);
case TYPE_ATOMIC:
- return type1->atomic.atype == type2->atomic.atype;
+ return type1->atomic.akind == type2->atomic.akind;
case TYPE_ARRAY:
return array_types_compatible(&type1->array, &type2->array);
* really need it! */
panic("type compatibility check for bitfield type");
+ case TYPE_ERROR:
+ /* Hmm, the error type should be compatible to all other types */
+ return true;
case TYPE_INVALID:
panic("invalid type found in compatible types");
case TYPE_TYPEDEF:
return true;
}
+/**
+ * Skip all typerefs and return the underlying type.
+ */
type_t *skip_typeref(type_t *type)
{
- unsigned qualifiers = type->base.qualifiers;
+ unsigned qualifiers = TYPE_QUALIFIER_NONE;
while(true) {
switch(type->kind) {
+ case TYPE_ERROR:
+ return type;
case TYPE_TYPEDEF: {
qualifiers |= type->base.qualifiers;
const typedef_type_t *typedef_type = &type->typedeft;
break;
}
+ if (qualifiers != TYPE_QUALIFIER_NONE) {
+ type_t *const copy = duplicate_type(type);
+ copy->base.qualifiers |= qualifiers;
+
+ type = typehash_insert(copy);
+ if (type != copy) {
+ obstack_free(type_obst, copy);
+ }
+ }
+
return type;
}
return result;
}
-type_t *make_atomic_type(atomic_type_type_t atype, type_qualifiers_t qualifiers)
+type_t *make_atomic_type(atomic_type_kind_t atype, type_qualifiers_t qualifiers)
{
type_t *type = obstack_alloc(type_obst, sizeof(atomic_type_t));
memset(type, 0, sizeof(atomic_type_t));
type->kind = TYPE_ATOMIC;
type->base.qualifiers = qualifiers;
- type->atomic.atype = atype;
+ type->atomic.akind = atype;
return identify_new_type(type);
}