From 220bd1d88703eede6a4891f3014708c8259b303e Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 11 Dec 2007 23:30:58 +0000 Subject: [PATCH] - renamed atomic_type_type_t to atomic_type_kind_t - add a warning if the array subscript type is char [r18685] --- ast2firm.c | 12 ++++++------ parser.c | 25 +++++++++++++++++++++---- type.c | 16 ++++++++-------- type_hash.c | 4 ++-- type_t.h | 10 +++++----- write_fluffy.c | 4 ++-- 6 files changed, 44 insertions(+), 27 deletions(-) diff --git a/ast2firm.c b/ast2firm.c index 22b2e83..d54e01f 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -241,8 +241,8 @@ static void init_atomic_modes(void) { static ir_mode *get_atomic_mode(const atomic_type_t* atomic_type) { ir_mode *res = NULL; - if ((unsigned)atomic_type->atype < (unsigned)ATOMIC_TYPE_LAST) - res = _atomic_modes[(unsigned)atomic_type->atype]; + if ((unsigned)atomic_type->akind < (unsigned)ATOMIC_TYPE_LAST) + res = _atomic_modes[(unsigned)atomic_type->akind]; if (res == NULL) panic("Encountered unknown atomic type"); return res; @@ -252,7 +252,7 @@ static unsigned get_type_size(type_t *type); static unsigned get_atomic_type_size(const atomic_type_t *type) { - switch(type->atype) { + switch(type->akind) { case ATOMIC_TYPE_CHAR: case ATOMIC_TYPE_SCHAR: case ATOMIC_TYPE_UCHAR: @@ -361,8 +361,8 @@ static ir_type *create_atomic_type(const atomic_type_t *type) ident *id = get_mode_ident(mode); ir_type *irtype = new_type_primitive(id, mode); - if(type->atype == ATOMIC_TYPE_LONG_DOUBLE - || type->atype == ATOMIC_TYPE_DOUBLE) { + if(type->akind == ATOMIC_TYPE_LONG_DOUBLE + || type->akind == ATOMIC_TYPE_DOUBLE) { set_type_alignment_bytes(irtype, 4); } @@ -2289,7 +2289,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->atype) { + switch (atomic_type->akind) { /* should not be reached */ case ATOMIC_TYPE_INVALID: tc = no_type_class; diff --git a/parser.c b/parser.c index 78591cf..c7d39db 100644 --- a/parser.c +++ b/parser.c @@ -628,7 +628,7 @@ static int get_rank(const type_t *type) assert(type->kind == TYPE_ATOMIC); const atomic_type_t *atomic_type = &type->atomic; - atomic_type_type_t atype = atomic_type->atype; + atomic_type_kind_t atype = atomic_type->akind; return atype; } @@ -1008,7 +1008,7 @@ static initializer_t *initializer_from_expression(type_t *type, if (element_type->kind == TYPE_ATOMIC) { switch (expression->kind) { case EXPR_STRING_LITERAL: - if (element_type->atomic.atype == ATOMIC_TYPE_CHAR) { + if (element_type->atomic.akind == ATOMIC_TYPE_CHAR) { return initializer_from_string(array_type, expression->string.value); } @@ -1717,7 +1717,7 @@ static void parse_declaration_specifiers(declaration_specifiers_t *specifiers) finish_specifiers: if(type == NULL) { - atomic_type_type_t atomic_type; + atomic_type_kind_t atomic_type; /* match valid basic types */ switch(type_specifiers) { @@ -1828,7 +1828,7 @@ finish_specifiers: } type = allocate_type_zero(TYPE_ATOMIC); - type->atomic.atype = atomic_type; + type->atomic.akind = atomic_type; newtype = 1; } else { if(type_specifiers != 0) { @@ -3554,6 +3554,21 @@ static expression_t *parse_primary_expression(void) return create_invalid_expression(); } +/** + * Check if the expression has the character type and issue a warning then. + */ +static void check_for_char_index_type(const expression_t *expression) { + type_t *type = expression->base.datatype; + type_t *base_type = skip_typeref(type); + + if (base_type->base.kind == TYPE_ATOMIC) { + if (base_type->atomic.akind == ATOMIC_TYPE_CHAR) { + warningf(expression->base.source_position, + "array subscript has type '%T'", type); + } + } +} + static expression_t *parse_array_expression(unsigned precedence, expression_t *left) { @@ -3581,12 +3596,14 @@ static expression_t *parse_array_expression(unsigned precedence, return_type = pointer->points_to; array_access->array_ref = left; array_access->index = inside; + check_for_char_index_type(inside); } else if(is_type_pointer(type_inside)) { pointer_type_t *pointer = &type_inside->pointer; return_type = pointer->points_to; array_access->array_ref = inside; array_access->index = left; array_access->flipped = true; + check_for_char_index_type(left); } else { errorf(HERE, "array access on object with non-pointer types '%T', '%T'", type_left, type_inside); } diff --git a/type.c b/type.c index ddfb8d0..d4ad8b9 100644 --- a/type.c +++ b/type.c @@ -47,7 +47,7 @@ void print_atomic_type(const atomic_type_t *type) 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; @@ -416,7 +416,7 @@ bool is_type_integer(const type_t *type) 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: @@ -442,7 +442,7 @@ bool is_type_floating(const type_t *type) 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: @@ -471,7 +471,7 @@ bool is_type_signed(const type_t *type) 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: @@ -554,7 +554,7 @@ bool is_type_incomplete(const type_t *type) 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: @@ -643,7 +643,7 @@ bool types_compatible(const type_t *type1, const type_t *type2) 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); @@ -742,14 +742,14 @@ static type_t *identify_new_type(type_t *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); } diff --git a/type_hash.c b/type_hash.c index be14de6..ed07122 100644 --- a/type_hash.c +++ b/type_hash.c @@ -29,7 +29,7 @@ static unsigned hash_ptr(const void *ptr) static unsigned hash_atomic_type(const atomic_type_t *type) { unsigned some_prime = 27644437; - unsigned result = type->atype * some_prime; + unsigned result = type->akind * some_prime; return result; } @@ -135,7 +135,7 @@ static unsigned hash_type(const type_t *type) static bool atomic_types_equal(const atomic_type_t *type1, const atomic_type_t *type2) { - return type1->atype == type2->atype; + return type1->akind == type2->akind; } static bool function_types_equal(const function_type_t *type1, diff --git a/type_t.h b/type_t.h index 10ce845..62a0e49 100644 --- a/type_t.h +++ b/type_t.h @@ -58,7 +58,7 @@ typedef enum { ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY, #endif ATOMIC_TYPE_LAST -} atomic_type_type_t; +} atomic_type_kind_t; typedef enum { TYPE_QUALIFIER_NONE = 0, @@ -78,7 +78,7 @@ struct type_base_t { struct atomic_type_t { type_base_t type; - atomic_type_type_t atype; + atomic_type_kind_t akind; }; struct builtin_type_t { @@ -163,7 +163,7 @@ union type_t { typeof_type_t typeoft; }; -type_t *make_atomic_type(atomic_type_type_t type, type_qualifiers_t qualifiers); +type_t *make_atomic_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 *duplicate_type(type_t *type); @@ -173,7 +173,7 @@ static inline bool is_typeref(const type_t *type) return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF; } -static inline bool is_type_atomic(const type_t *type, atomic_type_type_t atype) +static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype) { assert(!is_typeref(type)); @@ -181,7 +181,7 @@ static inline bool is_type_atomic(const type_t *type, atomic_type_type_t atype) return false; const atomic_type_t *atomic_type = &type->atomic; - return atomic_type->atype == atype; + return atomic_type->akind == atype; } static inline bool is_type_pointer(const type_t *type) diff --git a/write_fluffy.c b/write_fluffy.c index 3c870da..bd979c3 100644 --- a/write_fluffy.c +++ b/write_fluffy.c @@ -14,7 +14,7 @@ static FILE *out; static void write_type(const type_t *type); -static const char *get_atomic_type_string(const atomic_type_type_t type) +static const char *get_atomic_type_string(const atomic_type_kind_t type) { switch(type) { case ATOMIC_TYPE_VOID: return "void"; @@ -39,7 +39,7 @@ static const char *get_atomic_type_string(const atomic_type_type_t type) static void write_atomic_type(const atomic_type_t *type) { - fprintf(out, "%s", get_atomic_type_string(type->atype)); + fprintf(out, "%s", get_atomic_type_string(type->akind)); } static void write_pointer_type(const pointer_type_t *type) -- 2.20.1