{return operator()(type_base_sptr(l), type_base_sptr(r));}
}; // end struct type_name_comp
+/// Compare two types by comparing their canonical types if present.
+///
+/// If the canonical types are not present (because the types have not
+/// yet been canonicalized, for instance) then the types are compared
+/// structurally.
+///
+/// @param l the first type to take into account in the comparison.
+///
+/// @param r the second type to take into account in the comparison.
+template<typename T>
+bool
+try_canonical_compare(const T *l, const T *r)
+{
+ if (const type_base *lc = l->get_naked_canonical_type())
+ if (const type_base *rc = r->get_naked_canonical_type())
+ return lc == rc;
+ return equals(*l, *r, 0);
+}
+
/// Getter of all types types sorted by their pretty representation.
///
/// @return a sorted vector of all types sorted by their pretty
const type_decl* other = dynamic_cast<const type_decl*>(&o);
if (!other)
return false;
-
- if (get_naked_canonical_type() && other->get_naked_canonical_type())
- return get_naked_canonical_type() == other->get_naked_canonical_type();
-
- return equals(*this, *other, 0);
+ return try_canonical_compare(this, other);
}
/// Return true if both types equals.
const scope_type_decl* other = dynamic_cast<const scope_type_decl*>(&o);
if (!other)
return false;
-
- if (get_naked_canonical_type() && other->get_naked_canonical_type())
- return get_naked_canonical_type() == other->get_naked_canonical_type();
-
- return equals(*this, *other, 0);
+ return try_canonical_compare(this, other);
}
/// Equality operator between two scope_type_decl.
dynamic_cast<const qualified_type_def*>(&o);
if (!other)
return false;
-
- if (get_naked_canonical_type() && other->get_naked_canonical_type())
- return get_naked_canonical_type() == other->get_naked_canonical_type();
-
- return equals(*this, *other, 0);
+ return try_canonical_compare(this, other);
}
/// Equality operator for qualified types.
const pointer_type_def* other = is_pointer_type(&o);
if (!other)
return false;
-
- type_base* canonical_type = get_naked_canonical_type();
- type_base* other_canonical_type = other->get_naked_canonical_type();
-
- if (canonical_type && other_canonical_type)
- return canonical_type == other_canonical_type;
-
- return equals(*this, *other, 0);
+ return try_canonical_compare(this, other);
}
/// Return true iff both instances of pointer_type_def are equal.
dynamic_cast<const reference_type_def*>(&o);
if (!other)
return false;
-
- type_base* canonical_type = get_naked_canonical_type();
- type_base* other_canonical_type = other->get_naked_canonical_type();
-
- if (canonical_type && other_canonical_type)
- return canonical_type == other_canonical_type;
-
- return equals(*this, *other, 0);
+ return try_canonical_compare(this, other);
}
/// Equality operator of the @ref reference_type_def type.
dynamic_cast<const subrange_type*>(&o);
if (!other)
return false;
-
- if (get_naked_canonical_type() && other->get_naked_canonical_type())
- return get_naked_canonical_type() == other->get_naked_canonical_type();
-
- return equals(*this, *other, 0);
+ return try_canonical_compare(this, other);
}
/// Equality operator.
dynamic_cast<const array_type_def*>(&o);
if (!other)
return false;
-
- if (get_naked_canonical_type() && other->get_naked_canonical_type())
- return get_naked_canonical_type() == other->get_naked_canonical_type();
-
- return equals(*this, *other, 0);
+ return try_canonical_compare(this, other);
}
bool
const enum_type_decl* op = dynamic_cast<const enum_type_decl*>(&o);
if (!op)
return false;
-
- if (get_naked_canonical_type() && op->get_naked_canonical_type())
- return get_naked_canonical_type() == op->get_naked_canonical_type();
-
- return equals(*this, *op, 0);
+ return try_canonical_compare(this, op);
}
/// Equality operator.
const typedef_decl* other = dynamic_cast<const typedef_decl*>(&o);
if (!other)
return false;
-
- if (get_naked_canonical_type() && other->get_naked_canonical_type())
- return get_naked_canonical_type() == other->get_naked_canonical_type();
-
- return equals(*this, *other, 0);
+ return try_canonical_compare(this, other);
}
/// Equality operator
const function_type* o = dynamic_cast<const function_type*>(&other);
if (!o)
return false;
-
- type_base* canonical_type = get_naked_canonical_type();
- type_base* other_canonical_type = other.get_naked_canonical_type();
-
- if (canonical_type && other_canonical_type)
- return canonical_type == other_canonical_type;
-
- return equals(*this, *o, 0);
+ return try_canonical_compare(this, o);
}
/// Return a copy of the pretty representation of the current @ref
if (!op)
return false;
- type_base *canonical_type = get_naked_canonical_type(),
- *other_canonical_type = op->get_naked_canonical_type();
-
- // If this is a declaration only class with no canonical class, use
- // the canonical type of the definition, if any.
- if (!canonical_type
- && get_is_declaration_only()
- && get_naked_definition_of_declaration())
- canonical_type = is_class_or_union_type
- (get_naked_definition_of_declaration())->get_naked_canonical_type();
+ // If this is a decl-only type (and thus with no canonical type),
+ // use the canonical type of the definition, if any.
+ const class_or_union *l = 0;
+ if (get_is_declaration_only())
+ l = dynamic_cast<const class_or_union*>(get_naked_definition_of_declaration());
+ if (l == 0)
+ l = this;
// Likewise for the other class.
- if (!other_canonical_type
- && op->get_is_declaration_only()
- && op->get_naked_definition_of_declaration())
- other_canonical_type =
- is_class_or_union_type
- (op->get_naked_definition_of_declaration())->get_naked_canonical_type();
+ const class_or_union *r = 0;
+ if (op->get_is_declaration_only())
+ r = dynamic_cast<const class_or_union*>(op->get_naked_definition_of_declaration());
+ if (r == 0)
+ r = op;
- if (canonical_type && other_canonical_type)
- return canonical_type == other_canonical_type;
-
- return equals(*this, *op, 0);
+ return try_canonical_compare(l, r);
}
/// Equality operator.
if (!op)
return false;
- type_base *canonical_type = get_naked_canonical_type(),
- *other_canonical_type = op->get_naked_canonical_type();
+ // If this is a decl-only type (and thus with no canonical type),
+ // use the canonical type of the definition, if any.
+ const class_decl *l = 0;
+ if (get_is_declaration_only())
+ l = dynamic_cast<const class_decl*>(get_naked_definition_of_declaration());
+ if (l == 0)
+ l = this;
- // If this is a declaration only class with no canonical class, use
- // the canonical type of the definition, if any.
- if (!canonical_type
- && get_is_declaration_only()
- && get_naked_definition_of_declaration())
- canonical_type =
- is_class_type
- (get_naked_definition_of_declaration())->get_naked_canonical_type();
+ ABG_ASSERT(l);
- // Likewise for the other class.
- if (!other_canonical_type
- && op->get_is_declaration_only()
- && op->get_naked_definition_of_declaration())
- other_canonical_type =
- is_class_type
- (op->get_naked_definition_of_declaration())->get_naked_canonical_type();
+ // Likewise for the other type.
+ const class_decl *r = 0;
+ if (op->get_is_declaration_only())
+ r = dynamic_cast<const class_decl*>(op->get_naked_definition_of_declaration());
+ if (r == 0)
+ r = op;
- if (canonical_type && other_canonical_type)
- return canonical_type == other_canonical_type;
+ ABG_ASSERT(r);
- return equals(*this, *op, 0);
+ return try_canonical_compare(l, r);
}
/// Equality operator for class_decl.
const union_decl* op = dynamic_cast<const union_decl*>(&other);
if (!op)
return false;
-
- type_base *canonical_type = get_naked_canonical_type(),
- *other_canonical_type = op->get_naked_canonical_type();
-
- if (canonical_type && other_canonical_type)
- return canonical_type == other_canonical_type;
-
- return equals(*this, *op, 0);
+ return try_canonical_compare(this, op);
}
/// Equality operator for union_decl.