X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=type.c;h=efe7d0e590d56dc56bf76f9696a8d951ec980c16;hb=f017f4f5080052f95185056b3af472ab737bc64a;hp=a3e48329f0ee0127d425e26564ed51e8503324dc;hpb=c1f09ffd706bd46c9785ccb187da54536f566e2e;p=cparser diff --git a/type.c b/type.c index a3e4832..efe7d0e 100644 --- a/type.c +++ b/type.c @@ -7,9 +7,10 @@ #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); @@ -189,8 +190,9 @@ static void print_array_type_post(const array_type_t *type) 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); @@ -706,7 +708,7 @@ bool is_type_incomplete(const type_t *type) 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; @@ -778,12 +780,10 @@ static bool array_types_compatible(const array_type_t *array1, 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; } /** @@ -853,6 +853,8 @@ bool pointers_compatible(const type_t *type1, const type_t *type2) assert(type1->kind == TYPE_POINTER); assert(type2->kind == TYPE_POINTER); + (void) type1; + (void) type2; /* TODO */ return true; } @@ -955,6 +957,21 @@ type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers) 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. */