return result;
}
-/**
- * Free a type from the type obstack.
- */
-static void free_type(void *type)
-{
- obstack_free(type_obst, type);
-}
-
/**
* Returns the index of the top element of the environment stack.
*/
type_t *type = allocate_type_zero(TYPE_BUILTIN);
type->builtin.symbol = symbol;
type->builtin.real_type = real_type;
-
- type_t *result = typehash_insert(type);
- if (type != result) {
- free_type(type);
- }
-
- return result;
+ return identify_new_type(type);
}
static type_t *get_typedef_type(symbol_t *symbol)
type_t *copy = duplicate_type(type);
copy->atomic.akind = akind;
-
- type = typehash_insert(copy);
- if (type != copy) {
- obstack_free(type_obst, copy);
- }
- return type;
+ return identify_new_type(copy);
}
static type_t *handle_type_attributes(const gnu_attribute_t *attributes,
if (attribute->kind == GNU_AK_MODE) {
type = handle_mode_attribute(attribute, type);
} else if (attribute->kind == GNU_AK_ALIGNED) {
- int alignment = 32; /* TODO: fill in maximum usefull alignment for
+ int alignment = 32; /* TODO: fill in maximum useful alignment for
target machine */
if (attribute->has_arguments)
alignment = attribute->u.argument;
- type_t *copy = duplicate_type(type);
+ type_t *copy = duplicate_type(type);
copy->base.alignment = attribute->u.argument;
-
- type = typehash_insert(copy);
- if (type != copy) {
- obstack_free(type_obst, copy);
- }
+ type = identify_new_type(copy);
}
}
type->base.qualifiers = qualifiers;
type->base.modifiers = modifiers;
- type_t *result = typehash_insert(type);
- if (newtype && result != type) {
- free_type(type);
- }
+ type = identify_new_type(type);
- result = handle_type_attributes(specifiers->gnu_attributes, result);
- specifiers->type = result;
+ type = handle_type_attributes(specifiers->gnu_attributes, type);
+ specifiers->type = type;
return;
end_error:
alignment = attribute->u.argument;
if (entity->kind == ENTITY_TYPEDEF) {
- type_t *copy = duplicate_type(type);
+ type_t *copy = duplicate_type(type);
copy->base.alignment = attribute->u.argument;
-
- type = typehash_insert(copy);
- if (type != copy) {
- obstack_free(type_obst, copy);
- }
+ type = identify_new_type(copy);
} else if(entity->kind == ENTITY_VARIABLE) {
entity->variable.alignment = alignment;
} else if(entity->kind == ENTITY_COMPOUND_MEMBER) {
type_modifiers |= TYPE_MODIFIER_TRANSPARENT_UNION;
if (type->base.modifiers != type_modifiers) {
- type_t *copy = duplicate_type(type);
+ type_t *copy = duplicate_type(type);
copy->base.modifiers = type_modifiers;
-
- type = typehash_insert(copy);
- if (type != copy) {
- obstack_free(type_obst, copy);
- }
+ type = identify_new_type(copy);
}
if (entity->kind == ENTITY_TYPEDEF) {
}
}
- type_t *hashed_type = typehash_insert(type);
- if (hashed_type != type) {
- /* the function type was constructed earlier freeing it here will
- * destroy other types... */
- if (iter->kind != CONSTRUCT_FUNCTION) {
- free_type(type);
- }
- type = hashed_type;
+ /* The function type was constructed earlier. Freeing it here will
+ * destroy other types. */
+ if (iter->kind == CONSTRUCT_FUNCTION) {
+ type = typehash_insert(type);
+ } else {
+ type = identify_new_type(type);
}
}
new_type->function.parameters = parameters;
new_type->function.unspecified_parameters = true;
- type = typehash_insert(new_type);
- if (type != new_type) {
- obstack_free(type_obst, new_type);
- }
+ new_type = identify_new_type(new_type);
- entity->declaration.type = type;
+ entity->declaration.type = new_type;
rem_anchor_token('{');
}
ndeclaration->base.symbol);
}
- /* § 6.7.5.3 (14) a function definition with () means no
+ /* § 6.7.5.3:14 a function definition with () means no
* parameters (and not unspecified parameters) */
- if (type->function.unspecified_parameters
- && type->function.parameters == NULL
- && !type->function.kr_style_parameters) {
- type_t *duplicate = duplicate_type(type);
- duplicate->function.unspecified_parameters = false;
+ if (type->function.unspecified_parameters &&
+ type->function.parameters == NULL &&
+ !type->function.kr_style_parameters) {
+ type_t *copy = duplicate_type(type);
+ copy->function.unspecified_parameters = false;
+ type = identify_new_type(copy);
- type = typehash_insert(duplicate);
- if (type != duplicate) {
- obstack_free(type_obst, duplicate);
- }
ndeclaration->declaration.type = type;
}
ntype->function.return_type = type_int;
ntype->function.unspecified_parameters = true;
ntype->function.linkage = LINKAGE_C;
-
- type_t *type = typehash_insert(ntype);
- if (type != ntype) {
- free_type(ntype);
- }
+ type_t *type = identify_new_type(ntype);
entity_t *entity = allocate_entity_zero(ENTITY_FUNCTION);
entity->declaration.storage_class = STORAGE_CLASS_EXTERN;
type->function.return_type = return_type;
type->function.parameters = parameter1;
- type_t *result = typehash_insert(type);
- if (result != type) {
- free_type(type);
- }
-
- return result;
+ return identify_new_type(type);
}
/**
type->function.return_type = return_type;
type->function.parameters = parameter;
- type_t *result = typehash_insert(type);
- if (result != type) {
- free_type(type);
- }
-
- return result;
+ return identify_new_type(type);
}
static type_t *make_function_0_type(type_t *return_type)
type->function.return_type = return_type;
type->function.parameters = NULL;
- type_t *result = typehash_insert(type);
- if (result != type) {
- free_type(type);
- }
-
- return result;
+ return identify_new_type(type);
}
/**
new_type->array.has_implicit_size = true;
new_type->array.size = 1;
- type_t *const result = typehash_insert(new_type);
- if (type != result)
- free_type(type);
+ type_t *const result = identify_new_type(new_type);
decl->type = result;
}