+/* @@@ name clash with master flag
+int (type_visited)(const type *tp) {
+ return _type_visited(tp);
+}*/
+
+int (type_not_visited)(const type *tp) {
+ return _type_not_visited(tp);
+}
+
+int (is_type)(const void *thing) {
+ return _is_type(thing);
+}
+
+/* Checks whether two types are structural equal.*/
+int equal_type(type *typ1, type *typ2) {
+ entity **m;
+ type **t;
+ int i, j;
+
+ if (typ1 == typ2) return 1;
+
+ if ((get_type_tpop_code(typ1) != get_type_tpop_code(typ2)) ||
+ (get_type_ident(typ1) != get_type_ident(typ2)) ||
+ (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_bits(typ1) != get_type_size_bits(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 = alloca(sizeof(entity *) * get_class_n_members(typ1));
+ memset(m, 0, sizeof(entity *) * get_class_n_members(typ1));
+ /* First sort the members of typ2 */
+ for (i = 0; i < get_class_n_members(typ1); i++) {
+ entity *e1 = get_class_member(typ1, i);
+ for (j = 0; j < get_class_n_members(typ2); j++) {
+ 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] || /* Found no counterpart */
+ !equal_entity(get_class_member(typ1, i), m[i]))
+ return 0;
+ }
+ /** Compare the supertypes **/
+ t = alloca(sizeof(entity *) * get_class_n_supertypes(typ1));
+ memset(t, 0, sizeof(entity *) * get_class_n_supertypes(typ1));
+ /* First sort the supertypes of typ2 */
+ for (i = 0; i < get_class_n_supertypes(typ1); i++) {
+ type *t1 = get_class_supertype(typ1, i);
+ for (j = 0; j < get_class_n_supertypes(typ2); j++) {
+ type *t2 = get_class_supertype(typ2, j);
+ if (get_type_ident(t2) == get_type_ident(t1))
+ 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 = alloca(sizeof(entity *) * get_struct_n_members(typ1));
+ memset(m, 0, sizeof(entity *) * get_struct_n_members(typ1));
+ /* First sort the members of lt */
+ for (i = 0; i < get_struct_n_members(typ1); i++) {
+ entity *e1 = get_struct_member(typ1, i);
+ for (j = 0; j < get_struct_n_members(typ2); j++) {
+ 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] || /* Found no counterpart */
+ !equal_entity(get_struct_member(typ1, i), m[i]))
+ return 0;
+ }
+ } break;
+ case tpo_method: {
+ int n_param1, 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_variadicity(typ1) == variadicity_non_variadic) {
+ n_param1 = get_method_n_params(typ1);
+ n_param2 = get_method_n_params(typ2);
+ }
+ else {
+ n_param1 = get_method_first_variadic_param_index(typ1);
+ n_param2 = get_method_first_variadic_param_index(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)))