1 | //===------------------------- typeinfo.cpp -------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "typeinfo" |
10 | |
11 | #if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_VCRUNTIME) |
12 | #include <string.h> |
13 | |
14 | int std::type_info::__compare(const type_info &__rhs) const _NOEXCEPT { |
15 | if (&__data == &__rhs.__data) |
16 | return 0; |
17 | return strcmp(&__data.__decorated_name[1], &__rhs.__data.__decorated_name[1]); |
18 | } |
19 | |
20 | const char *std::type_info::name() const _NOEXCEPT { |
21 | // TODO(compnerd) cache demangled &__data.__decorated_name[1] |
22 | return &__data.__decorated_name[1]; |
23 | } |
24 | |
25 | size_t std::type_info::hash_code() const _NOEXCEPT { |
26 | #if defined(_WIN64) |
27 | constexpr size_t fnv_offset_basis = 14695981039346656037ull; |
28 | constexpr size_t fnv_prime = 10995116282110ull; |
29 | #else |
30 | constexpr size_t fnv_offset_basis = 2166136261ull; |
31 | constexpr size_t fnv_prime = 16777619ull; |
32 | #endif |
33 | |
34 | size_t value = fnv_offset_basis; |
35 | for (const char* c = &__data.__decorated_name[1]; *c; ++c) { |
36 | value ^= static_cast<size_t>(static_cast<unsigned char>(*c)); |
37 | value *= fnv_prime; |
38 | } |
39 | |
40 | #if defined(_WIN64) |
41 | value ^= value >> 32; |
42 | #endif |
43 | |
44 | return value; |
45 | } |
46 | #endif // _LIBCPP_ABI_MICROSOFT |
47 | |
48 | // FIXME: Remove the _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY configuration. |
49 | #if (!defined(LIBCXX_BUILDING_LIBCXXABI) && \ |
50 | !defined(LIBCXXRT) && \ |
51 | !defined(__GLIBCXX__) && \ |
52 | !defined(_LIBCPP_ABI_VCRUNTIME)) || \ |
53 | defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) |
54 | std::type_info::~type_info() |
55 | { |
56 | } |
57 | #endif |
58 | |