bitfields are an entity attribute now, not a type
authorMatthias Braun <matze@braunis.de>
Tue, 9 Aug 2011 13:14:51 +0000 (15:14 +0200)
committerMatthias Braun <matze@braunis.de>
Tue, 9 Aug 2011 18:19:27 +0000 (20:19 +0200)
ast.c
ast2firm.c
entity_t.h
mangle.c
parser.c
type.c
type_hash.c
type_t.h
wrappergen/write_jna.c

diff --git a/ast.c b/ast.c
index dc551de..2f327f2 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1424,6 +1424,13 @@ void print_declaration(const entity_t *entity)
                        }
                        break;
 
+               case ENTITY_COMPOUND_MEMBER:
+                       print_type_ext(declaration->type, declaration->base.symbol, NULL);
+                       if (entity->compound_member.bitfield) {
+                               print_format(" : %u", entity->compound_member.bit_size);
+                       }
+                       break;
+
                default:
                        print_type_ext(declaration->type, declaration->base.symbol, NULL);
                        break;
index 61fc5da..b81722d 100644 (file)
@@ -81,7 +81,6 @@ static label_t  **all_labels;
 static entity_t **inner_functions;
 static ir_node   *ijmp_list;
 static bool       constant_folding;
-static bool       initializer_use_bitfield_basetype;
 
 static const entity_t     *current_function_entity;
 static ir_node            *current_function_name;
@@ -536,21 +535,20 @@ static ir_type *get_unsigned_int_type_for_bit_size(ir_type *base_tp,
        return res;
 }
 
-static ir_type *create_bitfield_type(bitfield_type_t *const type)
+static ir_type *create_bitfield_type(const entity_t *entity)
 {
-       type_t *base = skip_typeref(type->base_type);
+       assert(entity->kind == ENTITY_COMPOUND_MEMBER);
+       type_t *base = skip_typeref(entity->declaration.type);
        assert(base->kind == TYPE_ATOMIC || base->kind == TYPE_ENUM);
        ir_type *irbase = get_ir_type(base);
 
-       unsigned size = type->bit_size;
+       unsigned bit_size = entity->compound_member.bit_size;
 
        assert(!is_type_float(base));
        if (is_type_signed(base)) {
-               return get_signed_int_type_for_bit_size(irbase, size,
-                                                       (const type_t*) type);
+               return get_signed_int_type_for_bit_size(irbase, bit_size, base);
        } else {
-               return get_unsigned_int_type_for_bit_size(irbase, size,
-                                                         (const type_t*) type);
+               return get_unsigned_int_type_for_bit_size(irbase, bit_size, base);
        }
 }
 
@@ -616,7 +614,7 @@ static ir_type *create_compound_type(compound_type_t *type,
                ident    *ident;
                if (symbol == NULL) {
                        /* anonymous bitfield member, skip */
-                       if (entry_type->kind == TYPE_BITFIELD)
+                       if (entry->compound_member.bitfield)
                                continue;
                        assert(entry_type->kind == TYPE_COMPOUND_STRUCT
                                        || entry_type->kind == TYPE_COMPOUND_UNION);
@@ -627,7 +625,12 @@ static ir_type *create_compound_type(compound_type_t *type,
 
                dbg_info *dbgi       = get_dbg_info(&entry->base.source_position);
 
-               ir_type   *entry_irtype = get_ir_type(entry_type);
+               ir_type *entry_irtype;
+               if (entry->compound_member.bitfield) {
+                       entry_irtype = create_bitfield_type(entry);
+               } else {
+                       entry_irtype = get_ir_type(entry_type);
+               }
                ir_entity *entity = new_d_entity(irtype, ident, entry_irtype, dbgi);
 
                set_entity_offset(entity, entry->compound_member.offset);
@@ -747,9 +750,6 @@ ir_type *get_ir_type(type_t *type)
        case TYPE_ENUM:
                firm_type = create_enum_type(&type->enumt);
                break;
-       case TYPE_BITFIELD:
-               firm_type = create_bitfield_type(&type->bitfield);
-               break;
 
        case TYPE_TYPEOF:
        case TYPE_TYPEDEF:
@@ -2147,9 +2147,8 @@ static ir_node *bitfield_store_to_firm(dbg_info *dbgi,
        value = create_conv(dbgi, value, mode);
 
        /* kill upper bits of value and shift to right position */
-       int      bitoffset    = get_entity_offset_bits_remainder(entity);
-       int      bitsize      = get_mode_size_bits(get_type_mode(entity_type));
-
+       int        bitoffset       = get_entity_offset_bits_remainder(entity);
+       int        bitsize         = get_mode_size_bits(get_type_mode(entity_type));
        ir_tarval *mask            = create_bitfield_mask(mode, 0, bitsize);
        ir_node   *mask_node       = new_d_Const(dbgi, mask);
        ir_node   *value_masked    = new_d_And(dbgi, value, mask_node, mode);
@@ -2179,44 +2178,45 @@ static ir_node *bitfield_store_to_firm(dbg_info *dbgi,
 }
 
 static ir_node *bitfield_extract_to_firm(const select_expression_t *expression,
-               ir_node *addr)
+                                         ir_node *addr)
 {
-       dbg_info *dbgi     = get_dbg_info(&expression->base.source_position);
-       type_t   *type     = expression->base.type;
-       ir_mode  *mode     = get_ir_mode_storage(type);
-       ir_node  *mem      = get_store();
-       ir_node  *load     = new_d_Load(dbgi, mem, addr, mode, cons_none);
-       ir_node  *load_mem = new_d_Proj(dbgi, load, mode_M, pn_Load_M);
-       ir_node  *load_res = new_d_Proj(dbgi, load, mode, pn_Load_res);
+       dbg_info *dbgi      = get_dbg_info(&expression->base.source_position);
+       entity_t *entity    = expression->compound_entry;
+       type_t   *base_type = entity->declaration.type;
+       ir_mode  *mode      = get_ir_mode_storage(base_type);
+       ir_node  *mem       = get_store();
+       ir_node  *load      = new_d_Load(dbgi, mem, addr, mode, cons_none);
+       ir_node  *load_mem  = new_d_Proj(dbgi, load, mode_M, pn_Load_M);
+       ir_node  *load_res  = new_d_Proj(dbgi, load, mode, pn_Load_res);
 
-       load_res           = create_conv(dbgi, load_res, mode_int);
+       type_t   *type     = expression->base.type;
+       ir_mode  *resmode  = get_ir_mode_arithmetic(type);
+       unsigned  res_size = get_mode_size_bits(resmode);
+       load_res = create_conv(dbgi, load_res, resmode);
 
        set_store(load_mem);
 
        /* kill upper bits */
        assert(expression->compound_entry->kind == ENTITY_COMPOUND_MEMBER);
-       ir_entity *entity       = expression->compound_entry->compound_member.entity;
-       int        bitoffset    = get_entity_offset_bits_remainder(entity);
-       ir_type   *entity_type  = get_entity_type(entity);
-       int        bitsize      = get_mode_size_bits(get_type_mode(entity_type));
-       long       shift_bitsl  = machine_size - bitoffset - bitsize;
-       assert(shift_bitsl >= 0);
-       ir_tarval *tvl          = new_tarval_from_long(shift_bitsl, mode_uint);
-       ir_node   *countl       = new_d_Const(dbgi, tvl);
-       ir_node   *shiftl       = new_d_Shl(dbgi, load_res, countl, mode_int);
-
-       long       shift_bitsr  = bitoffset + shift_bitsl;
-       assert(shift_bitsr <= (long) machine_size);
-       ir_tarval *tvr          = new_tarval_from_long(shift_bitsr, mode_uint);
-       ir_node   *countr       = new_d_Const(dbgi, tvr);
+       int        bitoffset   = entity->compound_member.bit_offset;
+       int        bitsize     = entity->compound_member.bit_size;
+       unsigned   shift_bitsl = res_size - bitoffset - bitsize;
+       ir_tarval *tvl         = new_tarval_from_long((long)shift_bitsl, mode_uint);
+       ir_node   *countl      = new_d_Const(dbgi, tvl);
+       ir_node   *shiftl      = new_d_Shl(dbgi, load_res, countl, resmode);
+
+       unsigned   shift_bitsr = bitoffset + shift_bitsl;
+       assert(shift_bitsr <= res_size);
+       ir_tarval *tvr         = new_tarval_from_long((long)shift_bitsr, mode_uint);
+       ir_node   *countr      = new_d_Const(dbgi, tvr);
        ir_node   *shiftr;
        if (mode_is_signed(mode)) {
-               shiftr = new_d_Shrs(dbgi, shiftl, countr, mode_int);
+               shiftr = new_d_Shrs(dbgi, shiftl, countr, resmode);
        } else {
-               shiftr = new_d_Shr(dbgi, shiftl, countr, mode_int);
+               shiftr = new_d_Shr(dbgi, shiftl, countr, resmode);
        }
 
-       return create_conv(dbgi, shiftr, mode);
+       return create_conv(dbgi, shiftr, resmode);
 }
 
 /* make sure the selected compound type is constructed */
@@ -2267,7 +2267,7 @@ static ir_node *set_value_for_expression_addr(const expression_t *expression,
 
                entity_t *entity = select->compound_entry;
                assert(entity->kind == ENTITY_COMPOUND_MEMBER);
-               if (entity->declaration.type->kind == TYPE_BITFIELD) {
+               if (entity->compound_member.bitfield) {
                        ir_entity *irentity = entity->compound_member.entity;
                        bool       set_volatile
                                = select->base.type->base.qualifiers & TYPE_QUALIFIER_VOLATILE;
@@ -2320,7 +2320,7 @@ static ir_node *get_value_from_lvalue(const expression_t *expression,
 
        ir_node *value;
        if (expression->kind == EXPR_SELECT &&
-           expression->select.compound_entry->declaration.type->kind == TYPE_BITFIELD){
+           expression->select.compound_entry->compound_member.bitfield) {
            construct_select_compound(&expression->select);
                value = bitfield_extract_to_firm(&expression->select, addr);
        } else {
@@ -3221,11 +3221,10 @@ static ir_node *select_to_firm(const select_expression_t *expression)
                        (const expression_t*) expression);
        type           = skip_typeref(type);
 
-       entity_t *entry      = expression->compound_entry;
+       entity_t *entry = expression->compound_entry;
        assert(entry->kind == ENTITY_COMPOUND_MEMBER);
-       type_t   *entry_type = skip_typeref(entry->declaration.type);
 
-       if (entry_type->kind == TYPE_BITFIELD) {
+       if (entry->compound_member.bitfield) {
                return bitfield_extract_to_firm(expression, addr);
        }
 
@@ -3307,7 +3306,6 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex
 
                        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 */
                        case TYPE_POINTER:         tc = pointer_type_class; goto make_const;
@@ -4032,15 +4030,6 @@ static ir_initializer_t *create_ir_initializer_value(
        }
        type_t       *type = initializer->value->base.type;
        expression_t *expr = initializer->value;
-       if (initializer_use_bitfield_basetype) {
-               type_t *skipped = skip_typeref(type);
-               if (skipped->kind == TYPE_BITFIELD) {
-                       /* remove the bitfield cast... */
-                       assert(expr->kind == EXPR_UNARY_CAST && expr->base.implicit);
-                       expr = expr->unary.value;
-                       type = skipped->bitfield.base_type;
-               }
-       }
        ir_node *value = expression_to_firm(expr);
        ir_mode *mode  = get_ir_mode_storage(type);
        value          = create_conv(NULL, value, mode);
@@ -4375,13 +4364,8 @@ static void create_local_initializer(initializer_t *initializer, dbg_info *dbgi,
        }
 
        if (is_constant_initializer(initializer) == EXPR_CLASS_VARIABLE) {
-               bool old_initializer_use_bitfield_basetype
-                       = initializer_use_bitfield_basetype;
-               initializer_use_bitfield_basetype = true;
                ir_initializer_t *irinitializer
                        = create_ir_initializer(initializer, type);
-               initializer_use_bitfield_basetype
-                       = old_initializer_use_bitfield_basetype;
 
                create_dynamic_initializer(irinitializer, dbgi, entity);
                return;
index a543a89..673a0e2 100644 (file)
@@ -210,6 +210,8 @@ struct compound_member_t {
        declaration_t  base;
        il_size_t      offset;     /**< the offset of this member in the compound */
        unsigned char  bit_offset; /**< extra bit offset for bitfield members */
+       unsigned char  bit_size;   /**< bitsize for bitfield members */
+       bool           bitfield      : 1;  /**< member is (part of) a bitfield */
        bool           read          : 1;
        bool           address_taken : 1;  /**< Set if the address of this
                                                declaration was taken. */
index 585ecaa..d932f27 100644 (file)
--- a/mangle.c
+++ b/mangle.c
@@ -218,9 +218,6 @@ static void mangle_type(type_t *orig_type)
        case TYPE_TYPEDEF:
        case TYPE_TYPEOF:
                panic("typeref not resolved while manging?!?");
-
-       case TYPE_BITFIELD:
-               panic("no mangling for this type implemented yet");
        }
        panic("invalid type encountered while mangling");
 }
index c6d38f3..0f40e75 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -878,9 +878,6 @@ static int get_rank(const type_t *type)
  */
 static type_t *promote_integer(type_t *type)
 {
-       if (type->kind == TYPE_BITFIELD)
-               type = type->bitfield.base_type;
-
        if (get_rank(type) < get_akind_rank(ATOMIC_TYPE_INT))
                type = type_int;
 
@@ -1927,14 +1924,11 @@ static bool walk_designator(type_path_t *path, const designator_t *designator,
                                        return false;
                                }
                                assert(iter->kind == ENTITY_COMPOUND_MEMBER);
-                               if (used_in_offsetof) {
-                                       type_t *real_type = skip_typeref(iter->declaration.type);
-                                       if (real_type->kind == TYPE_BITFIELD) {
-                                               errorf(&designator->source_position,
-                                                      "offsetof designator '%Y' must not specify bitfield",
-                                                      symbol);
-                                               return false;
-                                       }
+                               if (used_in_offsetof && iter->compound_member.bitfield) {
+                                       errorf(&designator->source_position,
+                                                  "offsetof designator '%Y' must not specify bitfield",
+                                                  symbol);
+                                       return false;
                                }
 
                                top->type             = orig_type;
@@ -5504,45 +5498,6 @@ static void parse_external_declaration(void)
        POP_SCOPE();
 }
 
-static type_t *make_bitfield_type(type_t *base_type, expression_t *size,
-                                  source_position_t *source_position,
-                                  const symbol_t *symbol)
-{
-       type_t *type = allocate_type_zero(TYPE_BITFIELD);
-
-       type->bitfield.base_type       = base_type;
-       type->bitfield.size_expression = size;
-
-       il_size_t bit_size;
-       type_t *skipped_type = skip_typeref(base_type);
-       if (!is_type_integer(skipped_type)) {
-               errorf(source_position, "bitfield base type '%T' is not an integer type", base_type);
-               bit_size = 0;
-       } else {
-               bit_size = get_type_size(base_type) * 8;
-       }
-
-       if (is_constant_expression(size) == EXPR_CLASS_CONSTANT) {
-               long v = fold_constant_to_int(size);
-               const symbol_t *user_symbol = symbol == NULL ? sym_anonymous : symbol;
-
-               if (v < 0) {
-                       errorf(source_position, "negative width in bit-field '%Y'",
-                              user_symbol);
-               } else if (v == 0 && symbol != NULL) {
-                       errorf(source_position, "zero width for bit-field '%Y'",
-                              user_symbol);
-               } else if (bit_size > 0 && (il_size_t)v > bit_size) {
-                       errorf(source_position, "width of '%Y' exceeds its type",
-                              user_symbol);
-               } else {
-                       type->bitfield.bit_size = v;
-               }
-       }
-
-       return type;
-}
-
 static entity_t *find_compound_entry(compound_t *compound, symbol_t *symbol)
 {
        entity_t *iter = compound->members.entities;
@@ -5601,12 +5556,19 @@ static expression_t *create_select(const source_position_t *pos,
        type_t *entry_type = entry->declaration.type;
        type_t *res_type   = get_qualified_type(entry_type, qualifiers);
 
+       /* bitfields need special treatment */
+       if (entry->compound_member.bitfield) {
+               unsigned bit_size = entry->compound_member.bit_size;
+               /* if fewer bits than an int, convert to int (see Â§6.3.1.1) */
+               if (bit_size < get_atomic_type_size(ATOMIC_TYPE_INT) * BITS_PER_BYTE) {
+                       res_type = type_int;
+               }
+       }
+
        /* we always do the auto-type conversions; the & and sizeof parser contains
         * code to revert this! */
        select->base.type = automatic_type_conversion(res_type);
-       if (res_type->kind == TYPE_BITFIELD) {
-               select->base.type = res_type->bitfield.base_type;
-       }
+
 
        return select;
 }
@@ -5653,6 +5615,49 @@ static expression_t *find_create_select(const source_position_t *pos,
        return NULL;
 }
 
+static void parse_bitfield_member(entity_t *entity)
+{
+       eat(':');
+
+       expression_t *size = parse_constant_expression();
+       long          size_long;
+
+       assert(entity->kind == ENTITY_COMPOUND_MEMBER);
+       type_t *type = entity->declaration.type;
+       if (!is_type_integer(skip_typeref(type))) {
+               errorf(HERE, "bitfield base type '%T' is not an integer type",
+                          type);
+       }
+
+       if (is_constant_expression(size) != EXPR_CLASS_CONSTANT) {
+               /* error already reported by parse_constant_expression */
+               size_long = get_type_size(type) * 8;
+       } else {
+               size_long = fold_constant_to_int(size);
+
+               const symbol_t *symbol = entity->base.symbol;
+               const symbol_t *user_symbol
+                       = symbol == NULL ? sym_anonymous : symbol;
+               unsigned bit_size = get_type_size(type) * 8;
+               if (size_long < 0) {
+                       errorf(HERE, "negative width in bit-field '%Y'", user_symbol);
+               } else if (size_long == 0 && symbol != NULL) {
+                       errorf(HERE, "zero width for bit-field '%Y'", user_symbol);
+               } else if (bit_size > 0 && (unsigned)size_long > bit_size) {
+                       errorf(HERE, "width of bitfield '%Y' exceeds its type",
+                                  user_symbol);
+               } else {
+                       /* hope that people don't invent crazy types with more bits
+                        * than our struct can hold */
+                       assert(size_long <
+                                  (1 << sizeof(entity->compound_member.bit_size)*8));
+               }
+       }
+
+       entity->compound_member.bitfield = true;
+       entity->compound_member.bit_size = (unsigned char)size_long;
+}
+
 static void parse_compound_declarators(compound_t *compound,
                const declaration_specifiers_t *specifiers)
 {
@@ -5660,31 +5665,27 @@ static void parse_compound_declarators(compound_t *compound,
                entity_t *entity;
 
                if (token.kind == ':') {
-                       source_position_t source_position = *HERE;
-                       next_token();
-
-                       type_t *base_type = specifiers->type;
-                       expression_t *size = parse_constant_expression();
+                       /* anonymous bitfield */
+                       type_t *type = specifiers->type;
+                       entity_t *entity = allocate_entity_zero(ENTITY_COMPOUND_MEMBER,
+                                                               NAMESPACE_NORMAL, NULL);
+                       entity->base.source_position               = *HERE;
+                       entity->declaration.declared_storage_class = STORAGE_CLASS_NONE;
+                       entity->declaration.storage_class          = STORAGE_CLASS_NONE;
+                       entity->declaration.type                   = type;
 
-                       type_t *type = make_bitfield_type(base_type, size,
-                                       &source_position, NULL);
+                       parse_bitfield_member(entity);
 
                        attribute_t  *attributes = parse_attributes(NULL);
                        attribute_t **anchor     = &attributes;
                        while (*anchor != NULL)
                                anchor = &(*anchor)->next;
                        *anchor = specifiers->attributes;
-
-                       entity = allocate_entity_zero(ENTITY_COMPOUND_MEMBER, NAMESPACE_NORMAL, NULL);
-                       entity->base.source_position               = source_position;
-                       entity->declaration.declared_storage_class = STORAGE_CLASS_NONE;
-                       entity->declaration.storage_class          = STORAGE_CLASS_NONE;
-                       entity->declaration.type                   = type;
-                       entity->declaration.attributes             = attributes;
-
                        if (attributes != NULL) {
                                handle_entity_attributes(attributes, entity);
                        }
+                       entity->declaration.attributes = attributes;
+
                        append_entity(&compound->members, entity);
                } else {
                        entity = parse_declarator(specifiers,
@@ -5706,16 +5707,9 @@ static void parse_compound_declarators(compound_t *compound,
                                }
 
                                if (token.kind == ':') {
-                                       source_position_t source_position = *HERE;
-                                       next_token();
-                                       expression_t *size = parse_constant_expression();
-
-                                       type_t *type          = entity->declaration.type;
-                                       type_t *bitfield_type = make_bitfield_type(type, size,
-                                                       &source_position, entity->base.symbol);
+                                       parse_bitfield_member(entity);
 
                                        attribute_t *attributes = parse_attributes(NULL);
-                                       entity->declaration.type = bitfield_type;
                                        handle_entity_attributes(attributes, entity);
                                } else {
                                        type_t *orig_type = entity->declaration.type;
@@ -6101,8 +6095,7 @@ type_t *revert_automatic_type_conversion(const expression_t *expression)
                entity_t *entity = expression->select.compound_entry;
                assert(is_declaration(entity));
                type_t   *type   = entity->declaration.type;
-               return get_qualified_type(type,
-                               expression->base.type->base.qualifiers);
+               return get_qualified_type(type, expression->base.type->base.qualifiers);
        }
 
        case EXPR_UNARY_DEREFERENCE: {
@@ -7012,6 +7005,12 @@ end_error:
        return expr;
 }
 
+static bool is_bitfield(const expression_t *expression)
+{
+       return expression->kind == EXPR_SELECT
+               && expression->select.compound_entry->compound_member.bitfield;
+}
+
 static expression_t *parse_typeprop(expression_kind_t const kind)
 {
        expression_t  *tp_expression = allocate_expression_zero(kind);
@@ -7039,6 +7038,12 @@ static expression_t *parse_typeprop(expression_kind_t const kind)
                expression = parse_subexpression(PREC_UNARY);
 
 typeprop_expression:
+               if (is_bitfield(expression)) {
+                       char const* const what = kind == EXPR_SIZEOF ? "sizeof" : "alignof";
+                       errorf(&tp_expression->base.source_position,
+                                  "operand of %s expression must not be a bitfield", what);
+               }
+
                tp_expression->typeprop.tp_expression = expression;
 
                orig_type = revert_automatic_type_conversion(expression);
@@ -7060,12 +7065,7 @@ typeprop_expression:
                } else {
                        wrong_type = "function";
                }
-       } else {
-               if (is_type_incomplete(type))
-                       wrong_type = "incomplete";
        }
-       if (type->kind == TYPE_BITFIELD)
-               wrong_type = "bitfield";
 
        if (wrong_type != NULL) {
                char const* const what = kind == EXPR_SIZEOF ? "sizeof" : "alignof";
@@ -7844,10 +7844,9 @@ static void semantic_take_addr(unary_expression_t *expression)
        if (!is_lvalue(value)) {
                errorf(&expression->base.source_position, "'&' requires an lvalue");
        }
-       if (type->kind == TYPE_BITFIELD) {
+       if (is_bitfield(value)) {
                errorf(&expression->base.source_position,
-                      "'&' not allowed on object with bitfield type '%T'",
-                      type);
+                      "'&' not allowed on bitfield");
        }
 
        set_address_taken(value, false);
diff --git a/type.c b/type.c
index df0b759..3ca2071 100644 (file)
--- a/type.c
+++ b/type.c
@@ -61,7 +61,6 @@ static size_t get_type_struct_size(type_kind_t kind)
                [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),
                [TYPE_ENUM]            = sizeof(enum_type_t),
@@ -540,18 +539,6 @@ static void print_array_type_post(const array_type_t *type)
        intern_print_type_post(type->element_type);
 }
 
-/**
- * Prints the postfix part of a bitfield type.
- *
- * @param type   The array type.
- */
-static void print_bitfield_type_post(const bitfield_type_t *type)
-{
-       print_string(" : ");
-       print_expression(type->size_expression);
-       intern_print_type_post(type->base_type);
-}
-
 /**
  * Prints an enum definition.
  *
@@ -720,9 +707,6 @@ static void intern_print_type_pre(const type_t *const type)
        case TYPE_REFERENCE:
                print_reference_type_pre(&type->reference);
                return;
-       case TYPE_BITFIELD:
-               intern_print_type_pre(type->bitfield.base_type);
-               return;
        case TYPE_ARRAY:
                print_array_type_pre(&type->array);
                return;
@@ -756,9 +740,6 @@ static void intern_print_type_post(const type_t *const type)
        case TYPE_ARRAY:
                print_array_type_post(&type->array);
                return;
-       case TYPE_BITFIELD:
-               print_bitfield_type_post(&type->bitfield);
-               return;
        case TYPE_ERROR:
        case TYPE_INVALID:
        case TYPE_ATOMIC:
@@ -894,9 +875,6 @@ bool is_type_integer(const type_t *type)
 
        if (type->kind == TYPE_ENUM)
                return true;
-       if (type->kind == TYPE_BITFIELD)
-               return true;
-
        if (type->kind != TYPE_ATOMIC)
                return false;
 
@@ -960,9 +938,6 @@ bool is_type_signed(const type_t *type)
        /* enum types are int for now */
        if (type->kind == TYPE_ENUM)
                return true;
-       if (type->kind == TYPE_BITFIELD)
-               return is_type_signed(type->bitfield.base_type);
-
        if (type->kind != TYPE_ATOMIC)
                return false;
 
@@ -980,7 +955,6 @@ bool is_type_arithmetic(const type_t *type)
        assert(!is_typeref(type));
 
        switch(type->kind) {
-       case TYPE_BITFIELD:
        case TYPE_ENUM:
                return true;
        case TYPE_ATOMIC:
@@ -1054,7 +1028,6 @@ bool is_type_incomplete(const type_t *type)
        case TYPE_IMAGINARY:
                return type->imaginary.akind == ATOMIC_TYPE_VOID;
 
-       case TYPE_BITFIELD:
        case TYPE_FUNCTION:
        case TYPE_POINTER:
        case TYPE_REFERENCE:
@@ -1194,19 +1167,12 @@ bool types_compatible(const type_t *type1, const type_t *type2)
 
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION: {
-
-
                break;
        }
        case TYPE_ENUM:
                /* TODO: not implemented */
                break;
 
-       case TYPE_BITFIELD:
-               /* not sure if this makes sense or is even needed, implement it if you
-                * 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;
@@ -1305,8 +1271,6 @@ unsigned get_type_size(type_t *type)
                il_size_t element_size = get_type_size(type->array.element_type);
                return type->array.size * element_size;
        }
-       case TYPE_BITFIELD:
-               return 0;
        case TYPE_TYPEDEF:
                return get_type_size(type->typedeft.typedefe->type);
        case TYPE_TYPEOF:
@@ -1349,8 +1313,6 @@ unsigned get_type_alignment(type_t *type)
                return 4;
        case TYPE_ARRAY:
                return get_type_alignment(type->array.element_type);
-       case TYPE_BITFIELD:
-               return 0;
        case TYPE_TYPEDEF: {
                il_alignment_t alignment
                        = get_type_alignment(type->typedeft.typedefe->type);
@@ -1386,7 +1348,6 @@ decl_modifiers_t get_type_modifiers(const type_t *type)
        case TYPE_IMAGINARY:
        case TYPE_REFERENCE:
        case TYPE_POINTER:
-       case TYPE_BITFIELD:
        case TYPE_ARRAY:
                return 0;
        case TYPE_TYPEDEF: {
@@ -1662,18 +1623,16 @@ static entity_t *pack_bitfield_members(il_size_t *struct_offset,
        for (member = first; member != NULL; member = member->base.next) {
                if (member->kind != ENTITY_COMPOUND_MEMBER)
                        continue;
-
-               type_t *type = member->declaration.type;
-               if (type->kind != TYPE_BITFIELD)
+               if (!member->compound_member.bitfield)
                        break;
 
-               type_t *base_type = skip_typeref(type->bitfield.base_type);
+               type_t *base_type = member->declaration.type;
                il_alignment_t base_alignment = get_type_alignment(base_type);
                il_alignment_t alignment_mask = base_alignment-1;
                if (base_alignment > alignment)
                        alignment = base_alignment;
 
-               size_t bit_size = type->bitfield.bit_size;
+               size_t bit_size = member->compound_member.bit_size;
                if (!packed) {
                        bit_offset += (offset & alignment_mask) * BITS_PER_BYTE;
                        offset     &= ~alignment_mask;
@@ -1736,7 +1695,7 @@ void layout_struct_type(compound_type_t *type)
                        continue;
                }
 
-               if (skipped->kind == TYPE_BITFIELD) {
+               if (entry->compound_member.bitfield) {
                        entry = pack_bitfield_members(&offset, &alignment,
                                                      compound->packed, entry);
                        continue;
index 78658bc..a931f7d 100644 (file)
@@ -121,14 +121,6 @@ static unsigned hash_typeof_type(const typeof_type_t *type)
        return result;
 }
 
-static unsigned hash_bitfield_type(const bitfield_type_t *type)
-{
-       unsigned result  = hash_ptr(type->base_type);
-       result          ^= 27172145;
-
-       return result;
-}
-
 static unsigned hash_type(const type_t *type)
 {
        unsigned hash = 0;
@@ -172,9 +164,6 @@ static unsigned hash_type(const type_t *type)
        case TYPE_TYPEOF:
                hash = hash_typeof_type(&type->typeoft);
                break;
-       case TYPE_BITFIELD:
-               hash = hash_bitfield_type(&type->bitfield);
-               break;
        }
 
        unsigned some_prime = 99991;
@@ -297,15 +286,6 @@ static bool typeof_types_equal(const typeof_type_t *type1,
        return true;
 }
 
-static bool bitfield_types_equal(const bitfield_type_t *type1,
-                                 const bitfield_type_t *type2)
-{
-       if (type1->base_type != type2->base_type)
-               return false;
-       /* TODO: compare size expression */
-       return false;
-}
-
 static bool types_equal(const type_t *type1, const type_t *type2)
 {
        if (type1 == type2)
@@ -344,8 +324,6 @@ static bool types_equal(const type_t *type1, const type_t *type2)
                return typeof_types_equal(&type1->typeoft, &type2->typeoft);
        case TYPE_TYPEDEF:
                return typedef_types_equal(&type1->typedeft, &type2->typedeft);
-       case TYPE_BITFIELD:
-               return bitfield_types_equal(&type1->bitfield, &type2->bitfield);
        }
 
        abort();
index 600222d..f1e2332 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -44,7 +44,6 @@ typedef enum type_kind_t {
        TYPE_POINTER,
        TYPE_REFERENCE,
        TYPE_ARRAY,
-       TYPE_BITFIELD,
        TYPE_TYPEDEF,
        TYPE_TYPEOF,
 } type_kind_t;
@@ -167,13 +166,6 @@ struct typeof_type_t {
        type_t       *resolved_type;
 };
 
-struct bitfield_type_t {
-       type_base_t   base;
-       type_t       *base_type;
-       expression_t *size_expression; /**< The expression for the bit size. */
-       il_size_t     bit_size;        /**< Size of this bitfield in bits. */
-};
-
 union type_t {
        type_kind_t      kind;
        type_base_t      base;
@@ -187,7 +179,6 @@ union type_t {
        compound_type_t  compound;
        enum_type_t      enumt;
        typedef_type_t   typedeft;
-       bitfield_type_t  bitfield;
        typeof_type_t    typeoft;
 };
 
index ad3b9e6..6f51464 100644 (file)
@@ -228,7 +228,6 @@ static void write_type(type_t *type)
        case TYPE_TYPEDEF:
                panic("invalid type found");
        case TYPE_ARRAY:
-       case TYPE_BITFIELD:
        case TYPE_REFERENCE:
        case TYPE_FUNCTION:
        case TYPE_COMPLEX: