introduce distinct complex and imaginary types
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 22 Mar 2008 22:54:50 +0000 (22:54 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 22 Mar 2008 22:54:50 +0000 (22:54 +0000)
[r19021]

ast2firm.c
parser.c
type.c
type.h
type_hash.c
type_t.h
write_fluffy.c

index d6981ef..ffddd48 100644 (file)
@@ -221,6 +221,10 @@ static unsigned get_type_size_const(type_t *type)
                panic("error type occured");
        case TYPE_ATOMIC:
                return get_atomic_type_size(type->atomic.akind);
+       case TYPE_COMPLEX:
+               return 2 * get_atomic_type_size(type->complex.akind);
+       case TYPE_IMAGINARY:
+               return get_atomic_type_size(type->imaginary.akind);
        case TYPE_ENUM:
                return get_mode_size_bytes(mode_int);
        case TYPE_COMPOUND_UNION:
@@ -281,19 +285,48 @@ static unsigned count_parameters(const function_type_t *function_type)
        return count;
 }
 
+/**
+ * Creates a Firm type for an atomic type
+ */
 static ir_type *create_atomic_type(const atomic_type_t *type)
 {
        dbg_info           *dbgi      = get_dbg_info(&type->base.source_position);
        atomic_type_kind_t  kind      = type->akind;
        ir_mode            *mode      = _atomic_modes[kind];
-       unsigned            alignment = get_atomic_type_alignment(kind);
        ident              *id        = get_mode_ident(mode);
        ir_type            *irtype    = new_d_type_primitive(id, mode, dbgi);
 
-       if(type->base.alignment > alignment)
-               alignment = type->base.alignment;
+       set_type_alignment_bytes(irtype, type->base.alignment);
+
+       return irtype;
+}
+
+/**
+ * Creates a Firm type for a complex type
+ */
+static ir_type *create_complex_type(const complex_type_t *type)
+{
+       dbg_info           *dbgi      = get_dbg_info(&type->base.source_position);
+       atomic_type_kind_t  kind      = type->akind;
+       ir_mode            *mode      = _atomic_modes[kind];
+       ident              *id        = get_mode_ident(mode);
 
-       set_type_alignment_bytes(irtype, alignment);
+       /* FIXME: finish the array */
+       return NULL;
+}
+
+/**
+ * Creates a Firm type for an imaginary type
+ */
+static ir_type *create_imaginary_type(const imaginary_type_t *type)
+{
+       dbg_info           *dbgi      = get_dbg_info(&type->base.source_position);
+       atomic_type_kind_t  kind      = type->akind;
+       ir_mode            *mode      = _atomic_modes[kind];
+       ident              *id        = get_mode_ident(mode);
+       ir_type            *irtype    = new_d_type_primitive(id, mode, dbgi);
+
+       set_type_alignment_bytes(irtype, type->base.alignment);
 
        return irtype;
 }
@@ -759,10 +792,16 @@ static ir_type *get_ir_type(type_t *type)
        ir_type *firm_type = NULL;
        switch(type->kind) {
        case TYPE_ERROR:
-               panic("error type occured");
+               panic("error type occurred");
        case TYPE_ATOMIC:
                firm_type = create_atomic_type(&type->atomic);
                break;
+       case TYPE_COMPLEX:
+               firm_type = create_complex_type(&type->complex);
+               break;
+       case TYPE_IMAGINARY:
+               firm_type = create_imaginary_type(&type->imaginary);
+               break;
        case TYPE_FUNCTION:
                firm_type = create_method_type(&type->function);
                break;
@@ -2534,7 +2573,7 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex
        {
                case TYPE_ATOMIC: {
                        const atomic_type_t *const atomic_type = &type->atomic;
-                       switch ((atomic_type_kind_t) atomic_type->akind) {
+                       switch (atomic_type->akind) {
                                /* should not be reached */
                                case ATOMIC_TYPE_INVALID:
                                        tc = no_type_class;
@@ -2565,21 +2604,12 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex
                                case ATOMIC_TYPE_LONG_DOUBLE:
                                        tc = real_type_class;
                                        goto make_const;
-
-                               case ATOMIC_TYPE_FLOAT_COMPLEX:
-                               case ATOMIC_TYPE_DOUBLE_COMPLEX:
-                               case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX:
-                                       tc = complex_type_class;
-                                       goto make_const;
-                               case ATOMIC_TYPE_FLOAT_IMAGINARY:
-                               case ATOMIC_TYPE_DOUBLE_IMAGINARY:
-                               case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY:
-                                       tc = complex_type_class;
-                                       goto make_const;
                        }
                        panic("Unexpected atomic type in classify_type_to_firm().");
                }
 
+               case TYPE_COMPLEX:         tc = complex_type_class; goto make_const;
+               case TYPE_IMAGINARY:       tc = complex_type_class; goto make_const;
                case TYPE_BITFIELD:        tc = integer_type_class; goto make_const;
                case TYPE_ARRAY:           /* gcc handles this as pointer */
                case TYPE_FUNCTION:        /* gcc handles this as pointer */
index d83c261..b6d0f4a 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -366,6 +366,8 @@ static size_t get_type_struct_size(type_kind_t kind)
 {
        static const size_t sizes[] = {
                [TYPE_ATOMIC]          = sizeof(atomic_type_t),
+               [TYPE_COMPLEX]         = sizeof(complex_type_t),
+               [TYPE_IMAGINARY]       = sizeof(imaginary_type_t),
                [TYPE_BITFIELD]        = sizeof(bitfield_type_t),
                [TYPE_COMPOUND_STRUCT] = sizeof(compound_type_t),
                [TYPE_COMPOUND_UNION]  = sizeof(compound_type_t),
@@ -2071,7 +2073,7 @@ static void skip_until(int type) {
 }
 
 /**
- * skip any {...} blocks until a closing braket is reached.
+ * skip any {...} blocks until a closing bracket is reached.
  */
 static void skip_initializers(void)
 {
@@ -2614,10 +2616,8 @@ typedef enum {
        SPECIFIER_INT32     = 1 << 13,
        SPECIFIER_INT64     = 1 << 14,
        SPECIFIER_INT128    = 1 << 15,
-#ifdef PROVIDE_COMPLEX
        SPECIFIER_COMPLEX   = 1 << 16,
        SPECIFIER_IMAGINARY = 1 << 17,
-#endif
 } specifiers_t;
 
 static type_t *create_builtin_type(symbol_t *const symbol,
@@ -2628,7 +2628,7 @@ static type_t *create_builtin_type(symbol_t *const symbol,
        type->builtin.real_type = real_type;
 
        type_t *result = typehash_insert(type);
-       if (type != result) {
+       if(type != result) {
                free_type(type);
        }
 
@@ -2638,8 +2638,8 @@ static type_t *create_builtin_type(symbol_t *const symbol,
 static type_t *get_typedef_type(symbol_t *symbol)
 {
        declaration_t *declaration = get_declaration(symbol, NAMESPACE_NORMAL);
-       if(declaration == NULL
-                       || declaration->storage_class != STORAGE_CLASS_TYPEDEF)
+       if(declaration == NULL ||
+          declaration->storage_class != STORAGE_CLASS_TYPEDEF)
                return NULL;
 
        type_t *type               = allocate_type_zero(TYPE_TYPEDEF, &declaration->source_position);
@@ -2757,7 +2757,7 @@ static void parse_microsoft_extended_decl_modifier(declaration_specifiers_t *spe
                                        }
                                }
                                next_token();
-                           if(token.type == ',') {
+                               if(token.type == ',') {
                                        next_token();
                                        continue;
                                }
@@ -2910,10 +2910,9 @@ static void parse_declaration_specifiers(declaration_specifiers_t *specifiers)
                MATCH_SPECIFIER(T__int32,     SPECIFIER_INT32,     "_int32")
                MATCH_SPECIFIER(T__int64,     SPECIFIER_INT64,     "_int64")
                MATCH_SPECIFIER(T__int128,    SPECIFIER_INT128,    "_int128")
-#ifdef PROVIDE_COMPLEX
                MATCH_SPECIFIER(T__Complex,   SPECIFIER_COMPLEX,   "_Complex")
                MATCH_SPECIFIER(T__Imaginary, SPECIFIER_IMAGINARY, "_Imaginary")
-#endif
+
                case T__forceinline:
                        /* only in microsoft mode */
                        specifiers->decl_modifiers |= DM_FORCEINLINE;
@@ -3100,26 +3099,18 @@ finish_specifiers:
                case SPECIFIER_BOOL:
                        atomic_type = ATOMIC_TYPE_BOOL;
                        break;
-#ifdef PROVIDE_COMPLEX
                case SPECIFIER_FLOAT | SPECIFIER_COMPLEX:
-                       atomic_type = ATOMIC_TYPE_FLOAT_COMPLEX;
-                       break;
-               case SPECIFIER_DOUBLE | SPECIFIER_COMPLEX:
-                       atomic_type = ATOMIC_TYPE_DOUBLE_COMPLEX;
-                       break;
-               case SPECIFIER_LONG | SPECIFIER_DOUBLE | SPECIFIER_COMPLEX:
-                       atomic_type = ATOMIC_TYPE_LONG_DOUBLE_COMPLEX;
-                       break;
                case SPECIFIER_FLOAT | SPECIFIER_IMAGINARY:
-                       atomic_type = ATOMIC_TYPE_FLOAT_IMAGINARY;
+                       atomic_type = ATOMIC_TYPE_FLOAT;
                        break;
+               case SPECIFIER_DOUBLE | SPECIFIER_COMPLEX:
                case SPECIFIER_DOUBLE | SPECIFIER_IMAGINARY:
-                       atomic_type = ATOMIC_TYPE_DOUBLE_IMAGINARY;
+                       atomic_type = ATOMIC_TYPE_DOUBLE;
                        break;
+               case SPECIFIER_LONG | SPECIFIER_DOUBLE | SPECIFIER_COMPLEX:
                case SPECIFIER_LONG | SPECIFIER_DOUBLE | SPECIFIER_IMAGINARY:
-                       atomic_type = ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY;
+                       atomic_type = ATOMIC_TYPE_LONG_DOUBLE;
                        break;
-#endif
                default:
                        /* invalid specifier combination, give an error message */
                        if(type_specifiers == 0) {
@@ -3143,9 +3134,19 @@ finish_specifiers:
                        atomic_type = ATOMIC_TYPE_INVALID;
                }
 
-               type               = allocate_type_zero(TYPE_ATOMIC, &builtin_source_position);
-               type->atomic.akind = atomic_type;
-               newtype            = 1;
+               if(type_specifiers & SPECIFIER_COMPLEX &&
+                  atomic_type != ATOMIC_TYPE_INVALID) {
+                       type                = allocate_type_zero(TYPE_COMPLEX, &builtin_source_position);
+                       type->complex.akind = atomic_type;
+               } else if(type_specifiers & SPECIFIER_IMAGINARY &&
+                         atomic_type != ATOMIC_TYPE_INVALID) {
+                       type                  = allocate_type_zero(TYPE_IMAGINARY, &builtin_source_position);
+                       type->imaginary.akind = atomic_type;
+               } else {
+                       type               = allocate_type_zero(TYPE_ATOMIC, &builtin_source_position);
+                       type->atomic.akind = atomic_type;
+               }
+               newtype = 1;
        } else {
                if(type_specifiers != 0) {
                        errorf(HERE, "multiple datatypes in declaration");
diff --git a/type.c b/type.c
index 2bcc56c..49c1e7e 100644 (file)
--- a/type.c
+++ b/type.c
@@ -173,22 +173,6 @@ void init_types(void)
        props[ATOMIC_TYPE_ULONGLONG].alignment = 4;
 
        props[ATOMIC_TYPE_BOOL] = props[ATOMIC_TYPE_UINT];
-
-       /* initialize complex/imaginary types */
-       props[ATOMIC_TYPE_FLOAT_COMPLEX]              = props[ATOMIC_TYPE_FLOAT];
-       props[ATOMIC_TYPE_FLOAT_COMPLEX].flags       |= ATOMIC_TYPE_FLAG_COMPLEX;
-       props[ATOMIC_TYPE_FLOAT_COMPLEX].size        *= 2;
-       props[ATOMIC_TYPE_DOUBLE_COMPLEX]             = props[ATOMIC_TYPE_DOUBLE];
-       props[ATOMIC_TYPE_DOUBLE_COMPLEX].flags      |= ATOMIC_TYPE_FLAG_COMPLEX;
-       props[ATOMIC_TYPE_DOUBLE_COMPLEX].size       *= 2;
-       props[ATOMIC_TYPE_LONG_DOUBLE_COMPLEX]
-               = props[ATOMIC_TYPE_LONG_DOUBLE];
-       props[ATOMIC_TYPE_LONG_DOUBLE_COMPLEX].flags |= ATOMIC_TYPE_FLAG_COMPLEX;
-       props[ATOMIC_TYPE_LONG_DOUBLE_COMPLEX].size  *= 2;
-
-       props[ATOMIC_TYPE_FLOAT_IMAGINARY]       = props[ATOMIC_TYPE_FLOAT];
-       props[ATOMIC_TYPE_DOUBLE_IMAGINARY]      = props[ATOMIC_TYPE_DOUBLE];
-       props[ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY] = props[ATOMIC_TYPE_LONG_DOUBLE];
 }
 
 void exit_types(void)
@@ -214,7 +198,38 @@ void print_type_qualifiers(type_qualifiers_t qualifiers)
 }
 
 /**
- * Prints the name of a atomic type.
+ * Prints the name of an atomic type kinds.
+ *
+ * @param kind  The type kind.
+ */
+static
+void print_atomic_kinds(atomic_type_kind_t kind)
+{
+       const char *s = "INVALIDATOMIC";
+       switch(kind) {
+       case ATOMIC_TYPE_INVALID:                               break;
+       case ATOMIC_TYPE_VOID:        s = "void";               break;
+       case ATOMIC_TYPE_BOOL:        s = "_Bool";              break;
+       case ATOMIC_TYPE_CHAR:        s = "char";               break;
+       case ATOMIC_TYPE_SCHAR:       s = "signed char";        break;
+       case ATOMIC_TYPE_UCHAR:       s = "unsigned char";      break;
+       case ATOMIC_TYPE_INT:         s = "int";                break;
+       case ATOMIC_TYPE_UINT:        s = "unsigned int";       break;
+       case ATOMIC_TYPE_SHORT:       s = "short";              break;
+       case ATOMIC_TYPE_USHORT:      s = "unsigned short";     break;
+       case ATOMIC_TYPE_LONG:        s = "long";               break;
+       case ATOMIC_TYPE_ULONG:       s = "unsigned long";      break;
+       case ATOMIC_TYPE_LONGLONG:    s = "long long";          break;
+       case ATOMIC_TYPE_ULONGLONG:   s = "unsigned long long"; break;
+       case ATOMIC_TYPE_LONG_DOUBLE: s = "long double";        break;
+       case ATOMIC_TYPE_FLOAT:       s = "float";              break;
+       case ATOMIC_TYPE_DOUBLE:      s = "double";             break;
+       }
+       fputs(s, out);
+}
+
+/**
+ * Prints the name of an atomic type.
  *
  * @param type  The type.
  */
@@ -222,34 +237,33 @@ static
 void print_atomic_type(const atomic_type_t *type)
 {
        print_type_qualifiers(type->base.qualifiers);
+       print_atomic_kinds(type->akind);
+}
 
-       const char *s = "INVALIDATOMIC";
-       switch((atomic_type_kind_t) type->akind) {
-       case ATOMIC_TYPE_INVALID:     break;
-       case ATOMIC_TYPE_VOID:                  s = "void";               break;
-       case ATOMIC_TYPE_BOOL:                  s = "_Bool";              break;
-       case ATOMIC_TYPE_CHAR:                  s = "char";               break;
-       case ATOMIC_TYPE_SCHAR:                 s = "signed char";        break;
-       case ATOMIC_TYPE_UCHAR:                 s = "unsigned char";      break;
-       case ATOMIC_TYPE_INT:                   s = "int";                break;
-       case ATOMIC_TYPE_UINT:                  s = "unsigned int";       break;
-       case ATOMIC_TYPE_SHORT:                 s = "short";              break;
-       case ATOMIC_TYPE_USHORT:                s = "unsigned short";     break;
-       case ATOMIC_TYPE_LONG:                  s = "long";               break;
-       case ATOMIC_TYPE_ULONG:                 s = "unsigned long";      break;
-       case ATOMIC_TYPE_LONGLONG:              s = "long long";          break;
-       case ATOMIC_TYPE_ULONGLONG:             s = "unsigned long long"; break;
-       case ATOMIC_TYPE_LONG_DOUBLE:           s = "long double";        break;
-       case ATOMIC_TYPE_FLOAT:                 s = "float";              break;
-       case ATOMIC_TYPE_DOUBLE:                s = "double";             break;
-       case ATOMIC_TYPE_FLOAT_COMPLEX:         s = "_Complex float";     break;
-       case ATOMIC_TYPE_DOUBLE_COMPLEX:        s = "_Complex float";     break;
-       case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX:   s = "_Complex float";     break;
-       case ATOMIC_TYPE_FLOAT_IMAGINARY:       s = "_Imaginary float";   break;
-       case ATOMIC_TYPE_DOUBLE_IMAGINARY:      s = "_Imaginary float";   break;
-       case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY: s = "_Imaginary float";   break;
-       }
-       fputs(s, out);
+/**
+ * Prints the name of a complex type.
+ *
+ * @param type  The type.
+ */
+static
+void print_complex_type(const complex_type_t *type)
+{
+       print_type_qualifiers(type->base.qualifiers);
+       fputs("_Complex ", out);
+       print_atomic_kinds(type->akind);
+}
+
+/**
+ * Prints the name of an imaginary type.
+ *
+ * @param type  The type.
+ */
+static
+void print_imaginary_type(const imaginary_type_t *type)
+{
+       print_type_qualifiers(type->base.qualifiers);
+       fputs("_Imaginary ", out);
+       print_atomic_kinds(type->akind);
 }
 
 /**
@@ -535,6 +549,12 @@ static void intern_print_type_pre(const type_t *const type, const bool top)
        case TYPE_ATOMIC:
                print_atomic_type(&type->atomic);
                return;
+       case TYPE_COMPLEX:
+               print_complex_type(&type->complex);
+               return;
+       case TYPE_IMAGINARY:
+               print_imaginary_type(&type->imaginary);
+               return;
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:
                print_compound_type(&type->compound);
@@ -588,6 +608,8 @@ static void intern_print_type_post(const type_t *const type, const bool top)
        case TYPE_ERROR:
        case TYPE_INVALID:
        case TYPE_ATOMIC:
+       case TYPE_COMPLEX:
+       case TYPE_IMAGINARY:
        case TYPE_ENUM:
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:
@@ -637,6 +659,8 @@ static size_t get_type_size(const type_t *type)
 {
        switch(type->kind) {
        case TYPE_ATOMIC:          return sizeof(atomic_type_t);
+       case TYPE_COMPLEX:         return sizeof(complex_type_t);
+       case TYPE_IMAGINARY:       return sizeof(imaginary_type_t);
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:  return sizeof(compound_type_t);
        case TYPE_ENUM:            return sizeof(enum_type_t);
@@ -835,6 +859,12 @@ bool is_type_incomplete(const type_t *type)
        case TYPE_ATOMIC:
                return type->atomic.akind == ATOMIC_TYPE_VOID;
 
+       case TYPE_COMPLEX:
+               return type->complex.akind == ATOMIC_TYPE_VOID;
+
+       case TYPE_IMAGINARY:
+               return type->imaginary.akind == ATOMIC_TYPE_VOID;
+
        case TYPE_POINTER:
        case TYPE_BUILTIN:
        case TYPE_ERROR:
@@ -930,6 +960,10 @@ bool types_compatible(const type_t *type1, const type_t *type2)
                return function_types_compatible(&type1->function, &type2->function);
        case TYPE_ATOMIC:
                return type1->atomic.akind == type2->atomic.akind;
+       case TYPE_COMPLEX:
+               return type1->complex.akind == type2->complex.akind;
+       case TYPE_IMAGINARY:
+               return type1->imaginary.akind == type2->imaginary.akind;
        case TYPE_ARRAY:
                return array_types_compatible(&type1->array, &type2->array);
 
@@ -1141,17 +1175,53 @@ static type_t *identify_new_type(type_t *type)
  * @param akind       The kind of the atomic type.
  * @param qualifiers  Type qualifiers for the new type.
  */
-type_t *make_atomic_type(atomic_type_kind_t atype, type_qualifiers_t qualifiers)
+type_t *make_atomic_type(atomic_type_kind_t akind, 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->base.alignment  = 0;
-       type->atomic.akind    = atype;
+       type->base.alignment  = get_atomic_type_alignment(akind);
+       type->atomic.akind    = akind;
 
-       /* TODO: set the alignment depending on the atype here */
+       return identify_new_type(type);
+}
+
+/**
+ * Creates a new complex type.
+ *
+ * @param akind       The kind of the atomic type.
+ * @param qualifiers  Type qualifiers for the new type.
+ */
+type_t *make_complex_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers)
+{
+       type_t *type = obstack_alloc(type_obst, sizeof(complex_type_t));
+       memset(type, 0, sizeof(complex_type_t));
+
+       type->kind            = TYPE_COMPLEX;
+       type->base.qualifiers = qualifiers;
+       type->base.alignment  = get_atomic_type_alignment(akind);
+       type->complex.akind   = akind;
+
+       return identify_new_type(type);
+}
+
+/**
+ * Creates a new imaginary type.
+ *
+ * @param akind       The kind of the atomic type.
+ * @param qualifiers  Type qualifiers for the new type.
+ */
+type_t *make_imaginary_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers)
+{
+       type_t *type = obstack_alloc(type_obst, sizeof(imaginary_type_t));
+       memset(type, 0, sizeof(imaginary_type_t));
+
+       type->kind            = TYPE_IMAGINARY;
+       type->base.qualifiers = qualifiers;
+       type->base.alignment  = get_atomic_type_alignment(akind);
+       type->imaginary.akind = akind;
 
        return identify_new_type(type);
 }
diff --git a/type.h b/type.h
index e9fcb5e..bbebc33 100644 (file)
--- a/type.h
+++ b/type.h
@@ -46,14 +46,7 @@ typedef enum {
        ATOMIC_TYPE_LONG_DOUBLE,
        ATOMIC_TYPE_BOOL,
 
-       ATOMIC_TYPE_FLOAT_COMPLEX,
-       ATOMIC_TYPE_DOUBLE_COMPLEX,
-       ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
-       ATOMIC_TYPE_FLOAT_IMAGINARY,
-       ATOMIC_TYPE_DOUBLE_IMAGINARY,
-       ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
-
-       ATOMIC_TYPE_LAST = ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY
+       ATOMIC_TYPE_LAST = ATOMIC_TYPE_BOOL
 } atomic_type_kind_t;
 
 typedef enum {
@@ -67,6 +60,8 @@ typedef enum {
 
 typedef struct type_base_t           type_base_t;
 typedef struct atomic_type_t         atomic_type_t;
+typedef struct complex_type_t        complex_type_t;
+typedef struct imaginary_type_t      imaginary_type_t;
 typedef struct pointer_type_t        pointer_type_t;
 typedef struct function_parameter_t  function_parameter_t;
 typedef struct function_type_t       function_type_t;
index 8ec4171..175bab4 100644 (file)
@@ -53,6 +53,22 @@ static unsigned hash_atomic_type(const atomic_type_t *type)
        return result;
 }
 
+static unsigned hash_complex_type(const complex_type_t *type)
+{
+       unsigned some_prime = 27644437;
+       unsigned result     = type->akind * some_prime;
+
+       return result;
+}
+
+static unsigned hash_imaginary_type(const imaginary_type_t *type)
+{
+       unsigned some_prime = 27644437;
+       unsigned result     = type->akind * some_prime;
+
+       return result;
+}
+
 static unsigned hash_pointer_type(const pointer_type_t *type)
 {
        return hash_ptr(type->points_to);
@@ -117,6 +133,12 @@ static unsigned hash_type(const type_t *type)
        case TYPE_ATOMIC:
                hash = hash_atomic_type(&type->atomic);
                break;
+       case TYPE_COMPLEX:
+               hash = hash_complex_type(&type->complex);
+               break;
+       case TYPE_IMAGINARY:
+               hash = hash_imaginary_type(&type->imaginary);
+               break;
        case TYPE_ENUM:
                hash = hash_enum_type(&type->enumt);
                break;
@@ -154,7 +176,19 @@ static unsigned hash_type(const type_t *type)
 }
 
 static bool atomic_types_equal(const atomic_type_t *type1,
-                               const atomic_type_t *type2)
+                                                          const atomic_type_t *type2)
+{
+       return type1->akind == type2->akind;
+}
+
+static bool complex_types_equal(const complex_type_t *type1,
+                                                           const complex_type_t *type2)
+{
+       return type1->akind == type2->akind;
+}
+
+static bool imaginary_types_equal(const imaginary_type_t *type1,
+                                                             const imaginary_type_t *type2)
 {
        return type1->akind == type2->akind;
 }
@@ -274,6 +308,10 @@ static bool types_equal(const type_t *type1, const type_t *type2)
                return false;
        case TYPE_ATOMIC:
                return atomic_types_equal(&type1->atomic, &type2->atomic);
+       case TYPE_COMPLEX:
+               return complex_types_equal(&type1->complex, &type2->complex);
+       case TYPE_IMAGINARY:
+               return imaginary_types_equal(&type1->imaginary, &type2->imaginary);
        case TYPE_ENUM:
                return enum_types_equal(&type1->enumt, &type2->enumt);
        case TYPE_COMPOUND_STRUCT:
index 3536fad..f85e9d1 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -37,6 +37,8 @@ typedef enum {
        TYPE_INVALID,
        TYPE_ERROR,
        TYPE_ATOMIC,
+       TYPE_COMPLEX,
+       TYPE_IMAGINARY,
        TYPE_COMPOUND_STRUCT,
        TYPE_COMPOUND_UNION,
        TYPE_ENUM,
@@ -78,6 +80,16 @@ struct atomic_type_t {
        atomic_type_kind_t  akind;
 };
 
+struct complex_type_t {
+       type_base_t         base;
+       atomic_type_kind_t  akind;
+};
+
+struct imaginary_type_t {
+       type_base_t         base;
+       atomic_type_kind_t  akind;
+};
+
 struct builtin_type_t {
        type_base_t  base;
        symbol_t    *symbol;
@@ -156,6 +168,8 @@ union type_t {
        type_kind_t      kind;
        type_base_t      base;
        atomic_type_t    atomic;
+       complex_type_t   complex;
+       imaginary_type_t imaginary;
        builtin_type_t   builtin;
        pointer_type_t   pointer;
        array_type_t     array;
@@ -168,6 +182,8 @@ union type_t {
 };
 
 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
+type_t *make_complex_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
+type_t *make_imaginary_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
 type_t *make_array_type(type_t *element_type, size_t size,
                         type_qualifiers_t qualifiers);
index 8dda537..0d66b0b 100644 (file)
@@ -177,6 +177,8 @@ static void write_type(const type_t *type)
        case TYPE_INVALID:
                panic("invalid type found");
                break;
+       case TYPE_COMPLEX:
+       case TYPE_IMAGINARY:
        default:
                fprintf(out, "/* TODO type */");
                break;