return result;
}
+/// Hash an ABI artifact that is either a type.
+///
+/// This function intends to provides the fastest possible hashing for
+/// types while being completely correct.
+///
+/// Note that if the type artifact has a canonical type, the hash
+/// value is going to be the pointer value of the canonical type.
+/// Otherwise, this function computes a hash value for the type by
+/// recursively walking the type members. This last code path is
+/// possibly *very* slow and should only be used when only handful of
+/// types are going to be hashed.
+///
+/// @param t the type or decl to hash.
+///
+/// @return the resulting hash value.
+size_t
+hash_type(const type_base *t)
+{
+ size_t result = 0;
+
+ // If the type has a canonical type, then use the pointer value
+ // as a hash. This is the fastest we can get.
+ if (type_base* ct = t->get_naked_canonical_type())
+ result = reinterpret_cast<size_t>(ct);
+ else if (const class_decl* cl = is_class_type(t))
+ {
+ if (cl->get_is_declaration_only()
+ && cl->get_naked_definition_of_declaration())
+ // The is a declaration-only class, so it has no canonical
+ // type; but then it's class definition has one. Let's
+ // use that one.
+ return hash_type(cl->get_naked_definition_of_declaration());
+ else
+ {
+ // The class really has no canonical type, let's use the
+ // slow path of hashing the class recursively. Well
+ // it's not that slow as the hash value is quickly going
+ // to result to zero anyway.
+ type_base::dynamic_hash hash;
+ result = hash(t);
+ }
+ }
+ else
+ {
+ // Let's use the slow path of hashing the class recursively.
+ type_base::dynamic_hash hash;
+ result = hash(t);
+ }
+
+ return result;
+}
+
/// Hash an ABI artifact that is either a type of a decl.
///
/// @param tod the ABI artifact to hash.