+/* Compares type A to type B returns 1 if the represent the same type
+ 0 otherwise. */
+
+int
+types_equal (struct type *a, struct type *b)
+{
+ /* Identical type pointers. */
+ /* However, this still doesn't catch all cases of same type for b
+ and a. The reason is that builtin types are different from
+ the same ones constructed from the object. */
+ if (a == b)
+ return 1;
+
+ /* Resolve typedefs */
+ if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
+ a = check_typedef (a);
+ if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
+ b = check_typedef (b);
+
+ /* If after resolving typedefs a and b are not of the same type
+ code then they are not equal. */
+ if (TYPE_CODE (a) != TYPE_CODE (b))
+ return 0;
+
+ /* If a and b are both pointers types or both reference types then
+ they are equal of the same type iff the objects they refer to are
+ of the same type. */
+ if (TYPE_CODE (a) == TYPE_CODE_PTR
+ || TYPE_CODE (a) == TYPE_CODE_REF)
+ return types_equal (TYPE_TARGET_TYPE (a),
+ TYPE_TARGET_TYPE (b));
+
+ /* Well, damnit, if the names are exactly the same, I'll say they
+ are exactly the same. This happens when we generate method
+ stubs. The types won't point to the same address, but they
+ really are the same. */
+
+ if (TYPE_NAME (a) && TYPE_NAME (b)
+ && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
+ return 1;
+
+ /* Check if identical after resolving typedefs. */
+ if (a == b)
+ return 1;
+
+ /* Two function types are equal if their argument and return types
+ are equal. */
+ if (TYPE_CODE (a) == TYPE_CODE_FUNC)
+ {
+ int i;
+
+ if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
+ return 0;
+
+ if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
+ return 0;
+
+ for (i = 0; i < TYPE_NFIELDS (a); ++i)
+ if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
+ return 0;
+
+ return 1;
+ }
+
+ return 0;
+}
+