X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=type.c;h=88219a441197435c5ac7395c3a9e34ce7a4b590b;hb=bf92df408b5fef01d5ee065b02c1deb7e4289a5b;hp=c877093ddb98ddcd3ea2c78cda539ac46b85e23f;hpb=9e70c75f052386442d9cbe5cc170a98d2fab24da;p=cparser diff --git a/type.c b/type.c index c877093..88219a4 100644 --- a/type.c +++ b/type.c @@ -37,9 +37,8 @@ /** The default calling convention. */ cc_kind_t default_calling_convention = CC_CDECL; -static struct obstack _type_obst; -struct obstack *type_obst = &_type_obst; -static bool print_implicit_array_size = false; +static struct obstack type_obst; +static bool print_implicit_array_size = false; static void intern_print_type_pre(const type_t *type); static void intern_print_type_post(const type_t *type); @@ -68,6 +67,7 @@ static size_t get_type_struct_size(type_kind_t kind) [TYPE_ENUM] = sizeof(enum_type_t), [TYPE_FUNCTION] = sizeof(function_type_t), [TYPE_POINTER] = sizeof(pointer_type_t), + [TYPE_REFERENCE] = sizeof(reference_type_t), [TYPE_ARRAY] = sizeof(array_type_t), [TYPE_TYPEDEF] = sizeof(typedef_type_t), [TYPE_TYPEOF] = sizeof(typeof_type_t), @@ -80,8 +80,8 @@ static size_t get_type_struct_size(type_kind_t kind) type_t *allocate_type_zero(type_kind_t kind) { - size_t size = get_type_struct_size(kind); - type_t *res = obstack_alloc(type_obst, size); + size_t const size = get_type_struct_size(kind); + type_t *const res = obstack_alloc(&type_obst, size); memset(res, 0, size); res->base.kind = kind; @@ -198,7 +198,7 @@ static inline bool is_po2(unsigned x) void init_types(void) { - obstack_init(type_obst); + obstack_init(&type_obst); atomic_type_properties_t *props = atomic_type_properties; @@ -258,7 +258,7 @@ void init_types(void) void exit_types(void) { - obstack_free(type_obst, NULL); + obstack_free(&type_obst, NULL); } void print_type_qualifiers(type_qualifiers_t const qualifiers, QualifierSeparators const q) @@ -813,7 +813,7 @@ type_t *duplicate_type(const type_t *type) { size_t size = get_type_struct_size(type->kind); - type_t *copy = obstack_alloc(type_obst, size); + type_t *const copy = obstack_alloc(&type_obst, size); memcpy(copy, type, size); copy->base.firm_type = NULL; @@ -1542,7 +1542,7 @@ type_t *identify_new_type(type_t *type) { type_t *result = typehash_insert(type); if (result != type) { - obstack_free(type_obst, type); + obstack_free(&type_obst, type); } return result; } @@ -1555,10 +1555,7 @@ type_t *identify_new_type(type_t *type) */ type_t *make_atomic_type(atomic_type_kind_t akind, 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_t *const type = allocate_type_zero(TYPE_ATOMIC); type->base.qualifiers = qualifiers; type->atomic.akind = akind; @@ -1573,10 +1570,7 @@ type_t *make_atomic_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers) */ type_t *make_complex_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers) { - type_t *type = obstack_alloc(type_obst, sizeof(complex_type_t)); - memset(type, 0, sizeof(complex_type_t)); - - type->kind = TYPE_COMPLEX; + type_t *const type = allocate_type_zero(TYPE_COMPLEX); type->base.qualifiers = qualifiers; type->complex.akind = akind; @@ -1591,10 +1585,7 @@ type_t *make_complex_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers */ type_t *make_imaginary_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers) { - type_t *type = obstack_alloc(type_obst, sizeof(imaginary_type_t)); - memset(type, 0, sizeof(imaginary_type_t)); - - type->kind = TYPE_IMAGINARY; + type_t *const type = allocate_type_zero(TYPE_IMAGINARY); type->base.qualifiers = qualifiers; type->imaginary.akind = akind; @@ -1609,10 +1600,7 @@ type_t *make_imaginary_type(atomic_type_kind_t akind, type_qualifiers_t qualifie */ type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers) { - type_t *type = obstack_alloc(type_obst, sizeof(pointer_type_t)); - memset(type, 0, sizeof(pointer_type_t)); - - type->kind = TYPE_POINTER; + type_t *const type = allocate_type_zero(TYPE_POINTER); type->base.qualifiers = qualifiers; type->pointer.points_to = points_to; type->pointer.base_variable = NULL; @@ -1627,11 +1615,8 @@ type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers) */ type_t *make_reference_type(type_t *refers_to) { - type_t *type = obstack_alloc(type_obst, sizeof(reference_type_t)); - memset(type, 0, sizeof(reference_type_t)); - - type->kind = TYPE_REFERENCE; - type->base.qualifiers = 0; + type_t *const type = allocate_type_zero(TYPE_REFERENCE); + type->base.qualifiers = TYPE_QUALIFIER_NONE; type->reference.refers_to = refers_to; return identify_new_type(type); @@ -1647,10 +1632,7 @@ type_t *make_reference_type(type_t *refers_to) type_t *make_based_pointer_type(type_t *points_to, type_qualifiers_t qualifiers, variable_t *variable) { - type_t *type = obstack_alloc(type_obst, sizeof(pointer_type_t)); - memset(type, 0, sizeof(pointer_type_t)); - - type->kind = TYPE_POINTER; + type_t *const type = allocate_type_zero(TYPE_POINTER); type->base.qualifiers = qualifiers; type->pointer.points_to = points_to; type->pointer.base_variable = variable; @@ -1662,10 +1644,7 @@ type_t *make_based_pointer_type(type_t *points_to, 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_t *const type = allocate_type_zero(TYPE_ARRAY); type->base.qualifiers = qualifiers; type->array.element_type = element_type; type->array.size = size; @@ -1793,14 +1772,11 @@ void layout_struct_type(compound_type_t *type) } } + source_position_t const *const pos = &compound->base.source_position; if (need_pad) { - if (warning.padded) { - warningf(&compound->base.source_position, "'%T' needs padding", - type); - } - } else if (compound->packed && warning.packed) { - warningf(&compound->base.source_position, - "superfluous packed attribute on '%T'", type); + warningf(WARN_PADDED, pos, "'%T' needs padding", type); + } else if (compound->packed) { + warningf(WARN_PACKED, pos, "superfluous packed attribute on '%T'", type); } compound->size = offset; @@ -1842,10 +1818,9 @@ void layout_union_type(compound_type_t *type) compound->alignment = alignment; } -static function_parameter_t *allocate_parameter(type_t *const type) +function_parameter_t *allocate_parameter(type_t *const type) { - function_parameter_t *const param - = obstack_alloc(type_obst, sizeof(*param)); + function_parameter_t *const param = obstack_alloc(&type_obst, sizeof(*param)); memset(param, 0, sizeof(*param)); param->type = type; return param; @@ -1911,15 +1886,11 @@ type_t *make_function_type(type_t *return_type, int n_types, type->function.modifiers |= modifiers; type->function.linkage = LINKAGE_C; - function_parameter_t *last = NULL; + function_parameter_t **anchor = &type->function.parameters; for (int i = 0; i < n_types; ++i) { function_parameter_t *parameter = allocate_parameter(argument_types[i]); - if (last == NULL) { - type->function.parameters = parameter; - } else { - last->next = parameter; - } - last = parameter; + *anchor = parameter; + anchor = ¶meter->next; } return identify_new_type(type);