X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=type.c;h=b595215422c5a9ca027539e0a603cd0979dd6027;hb=4ea6966017e1519a46f887b8db6cb4023d9628c4;hp=49c1e7e6239e4271b3a3ff1ccd09793d512fb26d;hpb=f4ba96ac16e62370ded3eb1ee80f4ee39cdddbaa;p=cparser diff --git a/type.c b/type.c index 49c1e7e..b595215 100644 --- a/type.c +++ b/type.c @@ -167,10 +167,11 @@ void init_types(void) /* TODO: backend specific, need a way to query the backend for this. * The following are good settings for x86 */ - props[ATOMIC_TYPE_FLOAT].alignment = 4; - props[ATOMIC_TYPE_DOUBLE].alignment = 4; - props[ATOMIC_TYPE_LONGLONG].alignment = 4; - props[ATOMIC_TYPE_ULONGLONG].alignment = 4; + props[ATOMIC_TYPE_FLOAT].alignment = 4; + props[ATOMIC_TYPE_DOUBLE].alignment = 4; + props[ATOMIC_TYPE_LONG_DOUBLE].alignment = 4; + props[ATOMIC_TYPE_LONGLONG].alignment = 4; + props[ATOMIC_TYPE_ULONGLONG].alignment = 4; props[ATOMIC_TYPE_BOOL] = props[ATOMIC_TYPE_UINT]; } @@ -299,12 +300,12 @@ static void print_function_type_post(const function_type_t *type, fputc('(', out); - int first = 1; + bool first = true; if(scope == NULL) { function_parameter_t *parameter = type->parameters; for( ; parameter != NULL; parameter = parameter->next) { if(first) { - first = 0; + first = false; } else { fputs(", ", out); } @@ -314,7 +315,7 @@ static void print_function_type_post(const function_type_t *type, declaration_t *parameter = scope->declarations; for( ; parameter != NULL; parameter = parameter->next) { if(first) { - first = 0; + first = false; } else { fputs(", ", out); } @@ -324,7 +325,7 @@ static void print_function_type_post(const function_type_t *type, } if(type->variadic) { if(first) { - first = 0; + first = false; } else { fputs(", ", out); } @@ -747,6 +748,8 @@ 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; @@ -783,6 +786,8 @@ 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; @@ -800,12 +805,19 @@ bool is_type_arithmetic(const type_t *type) { assert(!is_typeref(type)); - if(type->kind == TYPE_BITFIELD || type->kind == TYPE_ENUM) + switch(type->kind) { + case TYPE_BITFIELD: + case TYPE_ENUM: return true; - if(type->kind != TYPE_ATOMIC) + case TYPE_ATOMIC: + return test_atomic_type_flag(type->atomic.akind, ATOMIC_TYPE_FLAG_ARITHMETIC); + case TYPE_COMPLEX: + return test_atomic_type_flag(type->complex.akind, ATOMIC_TYPE_FLAG_ARITHMETIC); + case TYPE_IMAGINARY: + return test_atomic_type_flag(type->imaginary.akind, ATOMIC_TYPE_FLAG_ARITHMETIC); + default: return false; - - return test_atomic_type_flag(type->atomic.akind, ATOMIC_TYPE_FLAG_ARITHMETIC); + } } /** @@ -842,19 +854,22 @@ bool is_type_incomplete(const type_t *type) case TYPE_COMPOUND_UNION: { const compound_type_t *compound_type = &type->compound; declaration_t *declaration = compound_type->declaration; - return !declaration->init.is_defined; + return !declaration->init.complete; } case TYPE_ENUM: { const enum_type_t *enum_type = &type->enumt; declaration_t *declaration = enum_type->declaration; - return !declaration->init.is_defined; + return !declaration->init.complete; } case TYPE_BITFIELD: + return false; + case TYPE_FUNCTION: return true; case TYPE_ARRAY: - return type->array.size_expression == NULL; + return type->array.size_expression == NULL + && !type->array.size_constant; case TYPE_ATOMIC: return type->atomic.akind == ATOMIC_TYPE_VOID;