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;
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:
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);
}
{
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;
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;
}
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);
}
finish_specifiers:
if(type == NULL) {
- atomic_type_type_t atomic_type;
+ atomic_type_kind_t atomic_type;
/* match valid basic types */
switch(type_specifiers) {
}
type = allocate_type_zero(TYPE_ATOMIC);
- type->atomic.atype = atomic_type;
+ type->atomic.akind = atomic_type;
newtype = 1;
} else {
if(type_specifiers != 0) {
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)
{
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);
}
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;
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 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_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);
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);
}
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;
}
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,
ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
#endif
ATOMIC_TYPE_LAST
-} atomic_type_type_t;
+} atomic_type_kind_t;
typedef enum {
TYPE_QUALIFIER_NONE = 0,
struct atomic_type_t {
type_base_t type;
- atomic_type_type_t atype;
+ atomic_type_kind_t akind;
};
struct builtin_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);
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));
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)
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";
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)