blob: 3922ae6ef56ebb835db2e0c04c0415850dc46f9c [file] [log] [blame]
Howard Hinnant152beb72012-01-09 17:10:00 +00001//===------------------------ private_typeinfo.h --------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef __PRIVATE_TYPEINFO_H_
11#define __PRIVATE_TYPEINFO_H_
12
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000013#include "__cxxabi_config.h"
14
Howard Hinnant152beb72012-01-09 17:10:00 +000015#include <typeinfo>
Howard Hinnantf877d212012-01-11 23:49:18 +000016#include <cstddef>
Howard Hinnant152beb72012-01-09 17:10:00 +000017
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +000018namespace __cxxabiv1 {
Howard Hinnantfacfc462012-01-22 01:23:02 +000019
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000020class _LIBCXXABI_TYPE_VIS __shim_type_info : public std::type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +000021public:
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000022 _LIBCXXABI_HIDDEN virtual ~__shim_type_info();
Howard Hinnantfacfc462012-01-22 01:23:02 +000023
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000024 _LIBCXXABI_HIDDEN virtual void noop1() const;
25 _LIBCXXABI_HIDDEN virtual void noop2() const;
26 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *thrown_type,
27 void *&adjustedPtr) const = 0;
Howard Hinnantfacfc462012-01-22 01:23:02 +000028};
29
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000030class _LIBCXXABI_TYPE_VIS __fundamental_type_info : public __shim_type_info {
Howard Hinnantfacfc462012-01-22 01:23:02 +000031public:
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000032 _LIBCXXABI_HIDDEN virtual ~__fundamental_type_info();
33 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
34 void *&) const;
Howard Hinnant152beb72012-01-09 17:10:00 +000035};
36
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000037class _LIBCXXABI_TYPE_VIS __array_type_info : public __shim_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +000038public:
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000039 _LIBCXXABI_HIDDEN virtual ~__array_type_info();
40 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
41 void *&) const;
Howard Hinnant152beb72012-01-09 17:10:00 +000042};
43
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000044class _LIBCXXABI_TYPE_VIS __function_type_info : public __shim_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +000045public:
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000046 _LIBCXXABI_HIDDEN virtual ~__function_type_info();
47 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
48 void *&) const;
Howard Hinnant152beb72012-01-09 17:10:00 +000049};
50
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000051class _LIBCXXABI_TYPE_VIS __enum_type_info : public __shim_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +000052public:
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000053 _LIBCXXABI_HIDDEN virtual ~__enum_type_info();
54 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
55 void *&) const;
Howard Hinnant152beb72012-01-09 17:10:00 +000056};
57
Howard Hinnantf877d212012-01-11 23:49:18 +000058enum
59{
60 unknown = 0,
61 public_path,
Howard Hinnant13093662012-01-16 00:13:46 +000062 not_public_path,
63 yes,
64 no
Howard Hinnantf877d212012-01-11 23:49:18 +000065};
66
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +000067class _LIBCXXABI_TYPE_VIS __class_type_info;
Howard Hinnantf877d212012-01-11 23:49:18 +000068
Shoaib Meenai54227ae2017-03-01 03:55:57 +000069struct _LIBCXXABI_HIDDEN __dynamic_cast_info
Howard Hinnantf877d212012-01-11 23:49:18 +000070{
Howard Hinnantcc614df2012-01-16 17:06:51 +000071// const data supplied to the search:
Howard Hinnantf877d212012-01-11 23:49:18 +000072
Howard Hinnant326aca32012-09-28 22:43:50 +000073 const __class_type_info* dst_type;
74 const void* static_ptr;
75 const __class_type_info* static_type;
76 std::ptrdiff_t src2dst_offset;
Howard Hinnantf877d212012-01-11 23:49:18 +000077
Howard Hinnantcc614df2012-01-16 17:06:51 +000078// Data that represents the answer:
Howard Hinnantf877d212012-01-11 23:49:18 +000079
80 // pointer to a dst_type which has (static_ptr, static_type) above it
81 const void* dst_ptr_leading_to_static_ptr;
82 // pointer to a dst_type which does not have (static_ptr, static_type) above it
83 const void* dst_ptr_not_leading_to_static_ptr;
Howard Hinnantcc614df2012-01-16 17:06:51 +000084
85 // The following three paths are either unknown, public_path or not_public_path.
Howard Hinnantf877d212012-01-11 23:49:18 +000086 // access of path from dst_ptr_leading_to_static_ptr to (static_ptr, static_type)
87 int path_dst_ptr_to_static_ptr;
88 // access of path from (dynamic_ptr, dynamic_type) to (static_ptr, static_type)
89 // when there is no dst_type along the path
90 int path_dynamic_ptr_to_static_ptr;
91 // access of path from (dynamic_ptr, dynamic_type) to dst_type
92 // (not used if there is a (static_ptr, static_type) above a dst_type).
93 int path_dynamic_ptr_to_dst_ptr;
Howard Hinnantcc614df2012-01-16 17:06:51 +000094
Howard Hinnantf877d212012-01-11 23:49:18 +000095 // Number of dst_types below (static_ptr, static_type)
96 int number_to_static_ptr;
97 // Number of dst_types not below (static_ptr, static_type)
98 int number_to_dst_ptr;
Howard Hinnantcc614df2012-01-16 17:06:51 +000099
100// Data that helps stop the search before the entire tree is searched:
101
102 // is_dst_type_derived_from_static_type is either unknown, yes or no.
Howard Hinnant13093662012-01-16 00:13:46 +0000103 int is_dst_type_derived_from_static_type;
104 // Number of dst_type in tree. If 0, then that means unknown.
105 int number_of_dst_type;
Howard Hinnantf877d212012-01-11 23:49:18 +0000106 // communicates to a dst_type node that (static_ptr, static_type) was found
107 // above it.
Howard Hinnant13093662012-01-16 00:13:46 +0000108 bool found_our_static_ptr;
109 // communicates to a dst_type node that a static_type was found
110 // above it, but it wasn't (static_ptr, static_type)
111 bool found_any_static_type;
112 // Set whenever a search can be stopped
113 bool search_done;
Howard Hinnantf877d212012-01-11 23:49:18 +0000114};
115
Howard Hinnant16650b52012-01-11 00:11:17 +0000116// Has no base class
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000117class _LIBCXXABI_TYPE_VIS __class_type_info : public __shim_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +0000118public:
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000119 _LIBCXXABI_HIDDEN virtual ~__class_type_info();
Howard Hinnant16650b52012-01-11 00:11:17 +0000120
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000121 _LIBCXXABI_HIDDEN void process_static_type_above_dst(__dynamic_cast_info *,
122 const void *,
123 const void *, int) const;
124 _LIBCXXABI_HIDDEN void process_static_type_below_dst(__dynamic_cast_info *,
125 const void *, int) const;
126 _LIBCXXABI_HIDDEN void process_found_base_class(__dynamic_cast_info *, void *,
127 int) const;
128 _LIBCXXABI_HIDDEN virtual void search_above_dst(__dynamic_cast_info *,
129 const void *, const void *,
130 int, bool) const;
131 _LIBCXXABI_HIDDEN virtual void
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000132 search_below_dst(__dynamic_cast_info *, const void *, int, bool) const;
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000133 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
134 void *&) const;
135 _LIBCXXABI_HIDDEN virtual void
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000136 has_unambiguous_public_base(__dynamic_cast_info *, void *, int) const;
Howard Hinnant152beb72012-01-09 17:10:00 +0000137};
138
Howard Hinnant16650b52012-01-11 00:11:17 +0000139// Has one non-virtual public base class at offset zero
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000140class _LIBCXXABI_TYPE_VIS __si_class_type_info : public __class_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +0000141public:
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000142 const __class_type_info *__base_type;
Howard Hinnant152beb72012-01-09 17:10:00 +0000143
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000144 _LIBCXXABI_HIDDEN virtual ~__si_class_type_info();
Howard Hinnant16650b52012-01-11 00:11:17 +0000145
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000146 _LIBCXXABI_HIDDEN virtual void search_above_dst(__dynamic_cast_info *,
147 const void *, const void *,
148 int, bool) const;
149 _LIBCXXABI_HIDDEN virtual void
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000150 search_below_dst(__dynamic_cast_info *, const void *, int, bool) const;
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000151 _LIBCXXABI_HIDDEN virtual void
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000152 has_unambiguous_public_base(__dynamic_cast_info *, void *, int) const;
Howard Hinnant152beb72012-01-09 17:10:00 +0000153};
154
Shoaib Meenai54227ae2017-03-01 03:55:57 +0000155struct _LIBCXXABI_HIDDEN __base_class_type_info
Howard Hinnant152beb72012-01-09 17:10:00 +0000156{
157public:
158 const __class_type_info* __base_type;
159 long __offset_flags;
160
161 enum __offset_flags_masks
162 {
163 __virtual_mask = 0x1,
Howard Hinnant16650b52012-01-11 00:11:17 +0000164 __public_mask = 0x2, // base is public
Howard Hinnant152beb72012-01-09 17:10:00 +0000165 __offset_shift = 8
166 };
Howard Hinnant16650b52012-01-11 00:11:17 +0000167
Howard Hinnant326aca32012-09-28 22:43:50 +0000168 void search_above_dst(__dynamic_cast_info*, const void*, const void*, int, bool) const;
169 void search_below_dst(__dynamic_cast_info*, const void*, int, bool) const;
Howard Hinnanta1919d22012-01-23 18:39:47 +0000170 void has_unambiguous_public_base(__dynamic_cast_info*, void*, int) const;
Howard Hinnant152beb72012-01-09 17:10:00 +0000171};
172
Howard Hinnant16650b52012-01-11 00:11:17 +0000173// Has one or more base classes
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000174class _LIBCXXABI_TYPE_VIS __vmi_class_type_info : public __class_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +0000175public:
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000176 unsigned int __flags;
177 unsigned int __base_count;
178 __base_class_type_info __base_info[1];
Howard Hinnant152beb72012-01-09 17:10:00 +0000179
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000180 enum __flags_masks {
181 __non_diamond_repeat_mask = 0x1, // has two or more distinct base class
182 // objects of the same type
183 __diamond_shaped_mask = 0x2 // has base class object with two or
184 // more derived objects
185 };
Howard Hinnant152beb72012-01-09 17:10:00 +0000186
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000187 _LIBCXXABI_HIDDEN virtual ~__vmi_class_type_info();
Howard Hinnant16650b52012-01-11 00:11:17 +0000188
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000189 _LIBCXXABI_HIDDEN virtual void search_above_dst(__dynamic_cast_info *,
190 const void *, const void *,
191 int, bool) const;
192 _LIBCXXABI_HIDDEN virtual void
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000193 search_below_dst(__dynamic_cast_info *, const void *, int, bool) const;
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000194 _LIBCXXABI_HIDDEN virtual void
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000195 has_unambiguous_public_base(__dynamic_cast_info *, void *, int) const;
Howard Hinnant152beb72012-01-09 17:10:00 +0000196};
197
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000198class _LIBCXXABI_TYPE_VIS __pbase_type_info : public __shim_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +0000199public:
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000200 unsigned int __flags;
201 const __shim_type_info *__pointee;
Howard Hinnant152beb72012-01-09 17:10:00 +0000202
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000203 enum __masks {
204 __const_mask = 0x1,
205 __volatile_mask = 0x2,
206 __restrict_mask = 0x4,
207 __incomplete_mask = 0x8,
Richard Smithf1636202016-12-02 02:06:53 +0000208 __incomplete_class_mask = 0x10,
209 __transaction_safe_mask = 0x20,
210 // This implements the following proposal from cxx-abi-dev (not yet part of
211 // the ABI document):
212 //
213 // http://sourcerytools.com/pipermail/cxx-abi-dev/2016-October/002986.html
214 //
215 // This is necessary for support of http://wg21.link/p0012, which permits
216 // throwing noexcept function and member function pointers and catching
217 // them as non-noexcept pointers.
218 __noexcept_mask = 0x40,
219
220 // Flags that cannot be removed by a standard conversion.
221 __no_remove_flags_mask = __const_mask | __volatile_mask | __restrict_mask,
222 // Flags that cannot be added by a standard conversion.
223 __no_add_flags_mask = __transaction_safe_mask | __noexcept_mask
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000224 };
Howard Hinnant152beb72012-01-09 17:10:00 +0000225
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000226 _LIBCXXABI_HIDDEN virtual ~__pbase_type_info();
227 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
228 void *&) const;
Howard Hinnant152beb72012-01-09 17:10:00 +0000229};
230
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000231class _LIBCXXABI_TYPE_VIS __pointer_type_info : public __pbase_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +0000232public:
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000233 _LIBCXXABI_HIDDEN virtual ~__pointer_type_info();
234 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
235 void *&) const;
236 _LIBCXXABI_HIDDEN bool can_catch_nested(const __shim_type_info *) const;
Howard Hinnant152beb72012-01-09 17:10:00 +0000237};
238
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000239class _LIBCXXABI_TYPE_VIS __pointer_to_member_type_info
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000240 : public __pbase_type_info {
Howard Hinnant152beb72012-01-09 17:10:00 +0000241public:
Saleem Abdulrasool77a304b2015-12-04 02:14:41 +0000242 const __class_type_info *__context;
Howard Hinnant152beb72012-01-09 17:10:00 +0000243
Saleem Abdulrasoolb4ec5792015-12-04 02:14:58 +0000244 _LIBCXXABI_HIDDEN virtual ~__pointer_to_member_type_info();
245 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
246 void *&) const;
247 _LIBCXXABI_HIDDEN bool can_catch_nested(const __shim_type_info *) const;
Howard Hinnant152beb72012-01-09 17:10:00 +0000248};
249
Howard Hinnant152beb72012-01-09 17:10:00 +0000250} // __cxxabiv1
251
252#endif // __PRIVATE_TYPEINFO_H_