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