#include "adt/error.h"
static struct obstack _type_obst;
-struct obstack *type_obst = &_type_obst;
static FILE *out;
-static int type_visited = 0;
+struct obstack *type_obst = &_type_obst;
+static int type_visited = 0;
+static bool print_implicit_array_size = true;
static void intern_print_type_pre(const type_t *type, bool top);
static void intern_print_type_post(const type_t *type, bool top);
fputs("static ", out);
}
print_type_qualifiers(type->type.qualifiers);
- if(type->size != NULL) {
- print_expression(type->size);
+ if(type->size_expression != NULL
+ && (print_implicit_array_size || !type->has_implicit_size)) {
+ print_expression(type->size_expression);
}
fputc(']', out);
intern_print_type_post(type->element_type, false);
return true;
case TYPE_ARRAY:
- return type->array.size == NULL;
+ return type->array.size_expression == NULL;
case TYPE_ATOMIC:
return type->atomic.akind == ATOMIC_TYPE_VOID;
if(!types_compatible(element_type1, element_type2))
return false;
- if(array1->size != NULL && array2->size != NULL) {
- /* TODO: check if size expression evaluate to the same value
- * if they are constant */
- }
+ if(!array1->size_constant || !array2->size_constant)
+ return true;
- return true;
+ return array1->size == array2->size;
}
/**
assert(type1->kind == TYPE_POINTER);
assert(type2->kind == TYPE_POINTER);
+ (void) type1;
+ (void) type2;
/* TODO */
return true;
}
return identify_new_type(type);
}
+type_t *make_array_type(type_t *element_type, size_t size,
+ type_qualifiers_t qualifiers)
+{
+ type_t *type = obstack_alloc(type_obst, sizeof(array_type_t));
+ memset(type, 0, sizeof(array_type_t));
+
+ type->kind = TYPE_ARRAY;
+ type->base.qualifiers = qualifiers;
+ type->array.element_type = element_type;
+ type->array.size = size;
+ type->array.size_constant = true;
+
+ return identify_new_type(type);
+}
+
/**
* Debug helper. Prints the given type to stdout.
*/