Simplify condition.
[cparser] / type.c
diff --git a/type.c b/type.c
index d4ad8b9..2725265 100644 (file)
--- a/type.c
+++ b/type.c
@@ -262,8 +262,10 @@ static void print_typeof_type_pre(const typeof_type_t *const type)
 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);
@@ -315,6 +317,7 @@ static void intern_print_type_post(const type_t *const type, const bool top)
        case TYPE_BITFIELD:
                print_bitfield_type_post(&type->bitfield);
                return;
+       case TYPE_ERROR:
        case TYPE_INVALID:
        case TYPE_ATOMIC:
        case TYPE_ENUM:
@@ -366,6 +369,7 @@ static size_t get_type_size(type_t *type)
        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");
@@ -535,6 +539,9 @@ bool is_type_scalar(const type_t *type)
        return is_type_arithmetic(type);
 }
 
+/**
+ * Check if a given type is incomplete
+ */
 bool is_type_incomplete(const type_t *type)
 {
        assert(!is_typeref(type));
@@ -546,6 +553,11 @@ bool is_type_incomplete(const type_t *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;
@@ -557,8 +569,8 @@ bool is_type_incomplete(const type_t *type)
                return type->atomic.akind == ATOMIC_TYPE_VOID;
 
        case TYPE_POINTER:
-       case TYPE_ENUM:
        case TYPE_BUILTIN:
+       case TYPE_ERROR:
                return false;
 
        case TYPE_TYPEDEF:
@@ -665,6 +677,9 @@ bool types_compatible(const type_t *type1, const type_t *type2)
                 * 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:
@@ -687,12 +702,17 @@ bool pointers_compatible(const type_t *type1, const type_t *type2)
        return true;
 }
 
+/**
+ * Skip all typerefs and return the underlying type.
+ */
 type_t *skip_typeref(type_t *type)
 {
        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;