]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libc++/include/typeinfo
Update the GNU DTS file from Linux 4.11
[FreeBSD/FreeBSD.git] / contrib / libc++ / include / typeinfo
1 // -*- C++ -*-
2 //===-------------------------- typeinfo ----------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef __LIBCPP_TYPEINFO
12 #define __LIBCPP_TYPEINFO
13
14 /*
15
16     typeinfo synopsis
17
18 namespace std {
19
20 class type_info
21 {
22 public:
23     virtual ~type_info();
24
25     bool operator==(const type_info& rhs) const noexcept;
26     bool operator!=(const type_info& rhs) const noexcept;
27
28     bool before(const type_info& rhs) const noexcept;
29     size_t hash_code() const noexcept;
30     const char* name() const noexcept;
31
32     type_info(const type_info& rhs) = delete;
33     type_info& operator=(const type_info& rhs) = delete;
34 };
35
36 class bad_cast
37     : public exception
38 {
39 public:
40     bad_cast() noexcept;
41     bad_cast(const bad_cast&) noexcept;
42     bad_cast& operator=(const bad_cast&) noexcept;
43     virtual const char* what() const noexcept;
44 };
45
46 class bad_typeid
47     : public exception
48 {
49 public:
50     bad_typeid() noexcept;
51     bad_typeid(const bad_typeid&) noexcept;
52     bad_typeid& operator=(const bad_typeid&) noexcept;
53     virtual const char* what() const noexcept;
54 };
55
56 }  // std
57
58 */
59
60 #include <__config>
61 #include <exception>
62 #include <cstddef>
63 #include <cstdint>
64 #ifdef _LIBCPP_NO_EXCEPTIONS
65 #include <cstdlib>
66 #endif
67
68 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
69 #pragma GCC system_header
70 #endif
71
72 #if defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
73 #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
74 #else
75 #define _LIBCPP_HAS_UNIQUE_TYPEINFO
76 #endif
77
78 namespace std  // purposefully not using versioning namespace
79 {
80
81 class _LIBCPP_EXCEPTION_ABI type_info
82 {
83     type_info& operator=(const type_info&);
84     type_info(const type_info&);
85
86 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
87     _LIBCPP_INLINE_VISIBILITY
88     int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
89     { return __builtin_strcmp(name(), __arg.name()); }
90 #endif
91
92 protected:
93 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
94     // A const char* with the non-unique RTTI bit possibly set.
95     uintptr_t __type_name;
96
97     _LIBCPP_INLINE_VISIBILITY
98     explicit type_info(const char* __n)
99       : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
100 #else
101     const char *__type_name;
102
103     _LIBCPP_INLINE_VISIBILITY
104     explicit type_info(const char* __n) : __type_name(__n) {}
105 #endif
106
107 public:
108     virtual ~type_info();
109
110 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
111     _LIBCPP_INLINE_VISIBILITY
112     const char* name() const _NOEXCEPT
113     {
114       return reinterpret_cast<const char*>(__type_name &
115                                            ~_LIBCPP_NONUNIQUE_RTTI_BIT);
116     }
117
118     _LIBCPP_INLINE_VISIBILITY
119     bool before(const type_info& __arg) const _NOEXCEPT
120     {
121       if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
122         return __type_name < __arg.__type_name;
123       return __compare_nonunique_names(__arg) < 0;
124     }
125
126     _LIBCPP_INLINE_VISIBILITY
127     size_t hash_code() const _NOEXCEPT
128     {
129       if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT))
130         return __type_name;
131
132       const char* __ptr = name();
133       size_t __hash = 5381;
134       while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
135         __hash = (__hash * 33) ^ __c;
136       return __hash;
137     }
138
139     _LIBCPP_INLINE_VISIBILITY
140     bool operator==(const type_info& __arg) const _NOEXCEPT
141     {
142       if (__type_name == __arg.__type_name)
143         return true;
144
145       if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
146         return false;
147       return __compare_nonunique_names(__arg) == 0;
148     }
149 #else
150     _LIBCPP_INLINE_VISIBILITY
151     const char* name() const _NOEXCEPT
152     { return __type_name; }
153
154     _LIBCPP_INLINE_VISIBILITY
155     bool before(const type_info& __arg) const _NOEXCEPT
156     { return __type_name < __arg.__type_name; }
157
158     _LIBCPP_INLINE_VISIBILITY
159     size_t hash_code() const _NOEXCEPT
160     { return reinterpret_cast<size_t>(__type_name); }
161
162     _LIBCPP_INLINE_VISIBILITY
163     bool operator==(const type_info& __arg) const _NOEXCEPT
164     { return __type_name == __arg.__type_name; }
165 #endif
166
167     _LIBCPP_INLINE_VISIBILITY
168     bool operator!=(const type_info& __arg) const _NOEXCEPT
169     { return !operator==(__arg); }
170 };
171
172 class _LIBCPP_EXCEPTION_ABI bad_cast
173     : public exception
174 {
175 public:
176     bad_cast() _NOEXCEPT;
177     virtual ~bad_cast() _NOEXCEPT;
178     virtual const char* what() const _NOEXCEPT;
179 };
180
181 class _LIBCPP_EXCEPTION_ABI bad_typeid
182     : public exception
183 {
184 public:
185     bad_typeid() _NOEXCEPT;
186     virtual ~bad_typeid() _NOEXCEPT;
187     virtual const char* what() const _NOEXCEPT;
188 };
189
190 }  // std
191
192 _LIBCPP_BEGIN_NAMESPACE_STD
193 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
194 void __throw_bad_cast()
195 {
196 #ifndef _LIBCPP_NO_EXCEPTIONS
197     throw bad_cast();
198 #else
199         _VSTD::abort();
200 #endif
201 }
202 _LIBCPP_END_NAMESPACE_STD
203
204 #endif  // __LIBCPP_TYPEINFO