Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- __debug ----------------------------------===// |
| 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_DEBUG_H |
| 12 | #define _LIBCPP_DEBUG_H |
| 13 | |
Eric Fiselier | b953610 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 14 | #include <__config> |
| 15 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 16 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 17 | #pragma GCC system_header |
| 18 | #endif |
| 19 | |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 20 | #if _LIBCPP_DEBUG_LEVEL >= 1 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 21 | # include <cstdlib> |
| 22 | # include <cstdio> |
| 23 | # include <cstddef> |
Howard Hinnant | f5f4684 | 2013-03-25 19:29:35 +0000 | [diff] [blame] | 24 | # ifndef _LIBCPP_ASSERT |
Ed Schouten | e5a356a | 2015-03-10 07:57:43 +0000 | [diff] [blame] | 25 | # define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::fprintf(stderr, "%s\n", m), _VSTD::abort())) |
Howard Hinnant | f5f4684 | 2013-03-25 19:29:35 +0000 | [diff] [blame] | 26 | # endif |
Eric Fiselier | b953610 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 27 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 28 | |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame^] | 29 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 30 | #ifndef _LIBCPP_DEBUG_ASSERT |
| 31 | #define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m) |
| 32 | #endif |
| 33 | #define _LIBCPP_DEBUG_MODE(...) __VA_ARGS__ |
| 34 | #endif |
| 35 | |
Eric Fiselier | b953610 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 36 | #ifndef _LIBCPP_ASSERT |
| 37 | # define _LIBCPP_ASSERT(x, m) ((void)0) |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 38 | #endif |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame^] | 39 | #ifndef _LIBCPP_DEBUG_ASSERT |
| 40 | # define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) |
| 41 | #endif |
| 42 | #ifndef _LIBCPP_DEBUG_MODE |
| 43 | #define _LIBCPP_DEBUG_MODE(...) ((void)0) |
| 44 | #endif |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 45 | |
| 46 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 47 | |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 48 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 49 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 50 | struct _LIBCPP_TYPE_VIS __c_node; |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 51 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 52 | struct _LIBCPP_TYPE_VIS __i_node |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 53 | { |
| 54 | void* __i_; |
| 55 | __i_node* __next_; |
| 56 | __c_node* __c_; |
| 57 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 58 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 59 | __i_node(const __i_node&) = delete; |
| 60 | __i_node& operator=(const __i_node&) = delete; |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 61 | #else |
| 62 | private: |
| 63 | __i_node(const __i_node&); |
| 64 | __i_node& operator=(const __i_node&); |
| 65 | public: |
| 66 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 67 | _LIBCPP_INLINE_VISIBILITY |
| 68 | __i_node(void* __i, __i_node* __next, __c_node* __c) |
| 69 | : __i_(__i), __next_(__next), __c_(__c) {} |
| 70 | ~__i_node(); |
| 71 | }; |
| 72 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 73 | struct _LIBCPP_TYPE_VIS __c_node |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 74 | { |
| 75 | void* __c_; |
| 76 | __c_node* __next_; |
| 77 | __i_node** beg_; |
| 78 | __i_node** end_; |
| 79 | __i_node** cap_; |
| 80 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 81 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 82 | __c_node(const __c_node&) = delete; |
| 83 | __c_node& operator=(const __c_node&) = delete; |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 84 | #else |
| 85 | private: |
| 86 | __c_node(const __c_node&); |
| 87 | __c_node& operator=(const __c_node&); |
| 88 | public: |
| 89 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 90 | _LIBCPP_INLINE_VISIBILITY |
| 91 | __c_node(void* __c, __c_node* __next) |
| 92 | : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} |
| 93 | virtual ~__c_node(); |
| 94 | |
| 95 | virtual bool __dereferenceable(const void*) const = 0; |
| 96 | virtual bool __decrementable(const void*) const = 0; |
| 97 | virtual bool __addable(const void*, ptrdiff_t) const = 0; |
| 98 | virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; |
| 99 | |
Howard Hinnant | 1c3ec6d | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 100 | void __add(__i_node* __i); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 101 | _LIBCPP_HIDDEN void __remove(__i_node* __i); |
| 102 | }; |
| 103 | |
| 104 | template <class _Cont> |
| 105 | struct _C_node |
| 106 | : public __c_node |
| 107 | { |
| 108 | _C_node(void* __c, __c_node* __n) |
| 109 | : __c_node(__c, __n) {} |
| 110 | |
| 111 | virtual bool __dereferenceable(const void*) const; |
| 112 | virtual bool __decrementable(const void*) const; |
| 113 | virtual bool __addable(const void*, ptrdiff_t) const; |
| 114 | virtual bool __subscriptable(const void*, ptrdiff_t) const; |
| 115 | }; |
| 116 | |
| 117 | template <class _Cont> |
| 118 | bool |
| 119 | _C_node<_Cont>::__dereferenceable(const void* __i) const |
| 120 | { |
| 121 | typedef typename _Cont::const_iterator iterator; |
| 122 | const iterator* __j = static_cast<const iterator*>(__i); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 123 | _Cont* _Cp = static_cast<_Cont*>(__c_); |
| 124 | return _Cp->__dereferenceable(__j); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | template <class _Cont> |
| 128 | bool |
| 129 | _C_node<_Cont>::__decrementable(const void* __i) const |
| 130 | { |
| 131 | typedef typename _Cont::const_iterator iterator; |
| 132 | const iterator* __j = static_cast<const iterator*>(__i); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 133 | _Cont* _Cp = static_cast<_Cont*>(__c_); |
| 134 | return _Cp->__decrementable(__j); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | template <class _Cont> |
| 138 | bool |
| 139 | _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const |
| 140 | { |
| 141 | typedef typename _Cont::const_iterator iterator; |
| 142 | const iterator* __j = static_cast<const iterator*>(__i); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 143 | _Cont* _Cp = static_cast<_Cont*>(__c_); |
| 144 | return _Cp->__addable(__j, __n); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | template <class _Cont> |
| 148 | bool |
| 149 | _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const |
| 150 | { |
| 151 | typedef typename _Cont::const_iterator iterator; |
| 152 | const iterator* __j = static_cast<const iterator*>(__i); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 153 | _Cont* _Cp = static_cast<_Cont*>(__c_); |
| 154 | return _Cp->__subscriptable(__j, __n); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 157 | class _LIBCPP_TYPE_VIS __libcpp_db |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 158 | { |
| 159 | __c_node** __cbeg_; |
| 160 | __c_node** __cend_; |
| 161 | size_t __csz_; |
| 162 | __i_node** __ibeg_; |
| 163 | __i_node** __iend_; |
| 164 | size_t __isz_; |
| 165 | |
| 166 | __libcpp_db(); |
| 167 | public: |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 168 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 169 | __libcpp_db(const __libcpp_db&) = delete; |
| 170 | __libcpp_db& operator=(const __libcpp_db&) = delete; |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 171 | #else |
| 172 | private: |
| 173 | __libcpp_db(const __libcpp_db&); |
| 174 | __libcpp_db& operator=(const __libcpp_db&); |
| 175 | public: |
| 176 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 177 | ~__libcpp_db(); |
| 178 | |
| 179 | class __db_c_iterator; |
| 180 | class __db_c_const_iterator; |
| 181 | class __db_i_iterator; |
| 182 | class __db_i_const_iterator; |
| 183 | |
| 184 | __db_c_const_iterator __c_end() const; |
| 185 | __db_i_const_iterator __i_end() const; |
| 186 | |
| 187 | template <class _Cont> |
| 188 | _LIBCPP_INLINE_VISIBILITY |
| 189 | void __insert_c(_Cont* __c) |
| 190 | { |
| 191 | __c_node* __n = __insert_c(static_cast<void*>(__c)); |
| 192 | ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_); |
| 193 | } |
| 194 | |
Howard Hinnant | 7608b4a | 2011-09-16 19:52:23 +0000 | [diff] [blame] | 195 | void __insert_i(void* __i); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 196 | __c_node* __insert_c(void* __c); |
| 197 | void __erase_c(void* __c); |
| 198 | |
| 199 | void __insert_ic(void* __i, const void* __c); |
| 200 | void __iterator_copy(void* __i, const void* __i0); |
| 201 | void __erase_i(void* __i); |
| 202 | |
| 203 | void* __find_c_from_i(void* __i) const; |
| 204 | void __invalidate_all(void* __c); |
| 205 | __c_node* __find_c_and_lock(void* __c) const; |
Howard Hinnant | 1c3ec6d | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 206 | __c_node* __find_c(void* __c) const; |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 207 | void unlock() const; |
| 208 | |
| 209 | void swap(void* __c1, void* __c2); |
| 210 | |
| 211 | |
| 212 | bool __dereferenceable(const void* __i) const; |
| 213 | bool __decrementable(const void* __i) const; |
| 214 | bool __addable(const void* __i, ptrdiff_t __n) const; |
| 215 | bool __subscriptable(const void* __i, ptrdiff_t __n) const; |
Howard Hinnant | 8b00e6c | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 216 | bool __less_than_comparable(const void* __i, const void* __j) const; |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 217 | private: |
| 218 | _LIBCPP_HIDDEN |
| 219 | __i_node* __insert_iterator(void* __i); |
| 220 | _LIBCPP_HIDDEN |
| 221 | __i_node* __find_iterator(const void* __i) const; |
| 222 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 223 | friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db(); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 224 | }; |
| 225 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 226 | _LIBCPP_FUNC_VIS __libcpp_db* __get_db(); |
| 227 | _LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db(); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 228 | |
| 229 | |
| 230 | _LIBCPP_END_NAMESPACE_STD |
| 231 | |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 232 | #endif |
| 233 | |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 234 | #endif // _LIBCPP_DEBUG_H |
| 235 | |