Commit e49d1e47 authored by Matthias Braun's avatar Matthias Braun
Browse files

remove equal_type

- Semantic was strange: shallow checking for pointers, deep checking for
  structs (because no real solution in case of cycles was implemented)
- Implementation was incomplete/buggy
- Nobody was using it anyway
parent 7807a7c5
......@@ -1153,43 +1153,6 @@ FIRM_API int is_type(const void *thing);
*/
FIRM_API long get_type_nr(const ir_type *tp);
/**
* Checks whether two types are structurally equal.
*
* @param typ1 the first type
* @param typ2 the second type
*
* @return
* true if the types are equal, else false.
*
* Types are equal if :
* - they are the same type kind
* - they have the same name
* - they have the same mode (if applicable)
* - they have the same type_state and, ev., the same size
* - they are class types and have:
* - the same members (see same_entity in entity.h)
* - the same supertypes -- the C-pointers are compared --> no recursive call.
* - the same number of subtypes. Subtypes are not compared,
* as this could cause a cyclic test.
* - they are structure types and have the same members
* - they are method types and have
* - the same parameter types
* - the same result types
* - they are union types and have the same members
* - they are array types and have
* - the same number of dimensions
* - the same dimension bounds
* - the same dimension order
* - the same element type
* - they are enumeration types and have the same enumerator names
* - they are pointer types and have the identical points_to type
* (i.e., the same C-struct to represent the type.
* This is to avoid endless recursions; with pointer types cyclic
* type graphs are possible.)
*/
FIRM_API int equal_type(ir_type *typ1, ir_type *typ2);
/**
* Checks whether two types are structural comparable.
*
......
......@@ -408,154 +408,6 @@ int (is_type)(const void *thing)
return _is_type(thing);
}
int equal_type(ir_type *typ1, ir_type *typ2)
{
ir_entity **m;
ir_type **t;
size_t i;
size_t j;
if (typ1 == typ2) return 1;
if ((get_type_tpop_code(typ1) != get_type_tpop_code(typ2)) ||
typ1->name != typ2->name ||
(get_type_mode(typ1) != get_type_mode(typ2)) ||
(get_type_state(typ1) != get_type_state(typ2)))
return 0;
if ((get_type_state(typ1) == layout_fixed) &&
(get_type_size_bytes(typ1) != get_type_size_bytes(typ2)))
return 0;
switch (get_type_tpop_code(typ1)) {
case tpo_class:
if (get_class_n_members(typ1) != get_class_n_members(typ2)) return 0;
if (get_class_n_subtypes(typ1) != get_class_n_subtypes(typ2)) return 0;
if (get_class_n_supertypes(typ1) != get_class_n_supertypes(typ2)) return 0;
if (get_class_peculiarity(typ1) != get_class_peculiarity(typ2)) return 0;
/** Compare the members **/
m = ALLOCANZ(ir_entity*, get_class_n_members(typ1));
/* First sort the members of typ2 */
for (i = 0; i < get_class_n_members(typ1); i++) {
ir_entity *e1 = get_class_member(typ1, i);
for (j = 0; j < get_class_n_members(typ2); j++) {
ir_entity *e2 = get_class_member(typ2, j);
if (get_entity_name(e1) == get_entity_name(e2))
m[i] = e2;
}
}
for (i = 0; i < get_class_n_members(typ1); i++) {
if (!m[i] || get_class_member(typ1, i) != m[i])
return 0;
}
/** Compare the supertypes **/
t = ALLOCANZ(ir_type*, get_class_n_supertypes(typ1));
/* First sort the supertypes of typ2 */
for (i = 0; i < get_class_n_supertypes(typ1); i++) {
ir_type *t1 = get_class_supertype(typ1, i);
for (j = 0; j < get_class_n_supertypes(typ2); j++) {
ir_type *t2 = get_class_supertype(typ2, j);
if (t2->name == t1->name)
t[i] = t2;
}
}
for (i = 0; i < get_class_n_supertypes(typ1); i++) {
if (!t[i] || /* Found no counterpart */
get_class_supertype(typ1, i) != t[i])
return 0;
}
break;
case tpo_struct:
if (get_struct_n_members(typ1) != get_struct_n_members(typ2)) return 0;
m = ALLOCANZ(ir_entity*, get_struct_n_members(typ1));
/* First sort the members of lt */
for (i = 0; i < get_struct_n_members(typ1); i++) {
ir_entity *e1 = get_struct_member(typ1, i);
for (j = 0; j < get_struct_n_members(typ2); j++) {
ir_entity *e2 = get_struct_member(typ2, j);
if (get_entity_name(e1) == get_entity_name(e2))
m[i] = e2;
}
}
for (i = 0; i < get_struct_n_members(typ1); i++) {
if (!m[i] || get_struct_member(typ1, i) != m[i])
return 0;
}
break;
case tpo_method: {
size_t n_param1;
size_t n_param2;
if (get_method_variadicity(typ1) != get_method_variadicity(typ2)) return 0;
if (get_method_n_ress(typ1) != get_method_n_ress(typ2)) return 0;
if (get_method_calling_convention(typ1) !=
get_method_calling_convention(typ2)) return 0;
n_param1 = get_method_n_params(typ1);
n_param2 = get_method_n_params(typ2);
if (n_param1 != n_param2) return 0;
for (i = 0; i < n_param1; i++) {
if (!equal_type(get_method_param_type(typ1, i), get_method_param_type(typ2, i)))
return 0;
}
for (i = 0; i < get_method_n_ress(typ1); i++) {
if (!equal_type(get_method_res_type(typ1, i), get_method_res_type(typ2, i)))
return 0;
}
} break;
case tpo_union:
if (get_union_n_members(typ1) != get_union_n_members(typ2)) return 0;
m = ALLOCANZ(ir_entity*, get_union_n_members(typ1));
/* First sort the members of lt */
for (i = 0; i < get_union_n_members(typ1); i++) {
ir_entity *e1 = get_union_member(typ1, i);
for (j = 0; j < get_union_n_members(typ2); j++) {
ir_entity *e2 = get_union_member(typ2, j);
if (get_entity_name(e1) == get_entity_name(e2))
m[i] = e2;
}
}
for (i = 0; i < get_union_n_members(typ1); i++) {
if (!m[i] || get_union_member(typ1, i) != m[i])
return 0;
}
break;
case tpo_array:
if (get_array_n_dimensions(typ1) != get_array_n_dimensions(typ2))
return 0;
if (!equal_type(get_array_element_type(typ1), get_array_element_type(typ2)))
return 0;
for (i = 0; i < get_array_n_dimensions(typ1); i++) {
if (get_array_lower_bound(typ1, i) != get_array_lower_bound(typ2, i) ||
get_array_upper_bound(typ1, i) != get_array_upper_bound(typ2, i))
return 0;
if (get_array_order(typ1, i) != get_array_order(typ2, i))
assert(0 && "type compare with different dimension orders not implemented");
}
break;
case tpo_enumeration:
assert(0 && "enumerations not implemented");
break;
case tpo_pointer:
if (get_pointer_points_to_type(typ1) != get_pointer_points_to_type(typ2))
return 0;
break;
case tpo_primitive:
break;
default: break;
}
return 1;
}
int smaller_type(ir_type *st, ir_type *lt)
{
ir_entity **m;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment