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 14 #if _LIBCPP_DEBUG_LEVEL >= 1 15 16 # include <cstdlib> 17 # include <cstdio> 18 # include <cstddef> 19 # define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort())) 20 21 #endif 22 23 #if _LIBCPP_DEBUG_LEVEL >= 2 24 25 _LIBCPP_BEGIN_NAMESPACE_STD 26 27 struct _LIBCPP_VISIBLE __c_node; 28 29 struct _LIBCPP_VISIBLE __i_node 30 { 31 void* __i_; 32 __i_node* __next_; 33 __c_node* __c_; 34 35 __i_node(const __i_node&) = delete; 36 __i_node& operator=(const __i_node&) = delete; 37 _LIBCPP_INLINE_VISIBILITY 38 __i_node(void* __i, __i_node* __next, __c_node* __c) 39 : __i_(__i), __next_(__next), __c_(__c) {} 40 ~__i_node(); 41 }; 42 43 struct _LIBCPP_VISIBLE __c_node 44 { 45 void* __c_; 46 __c_node* __next_; 47 __i_node** beg_; 48 __i_node** end_; 49 __i_node** cap_; 50 51 __c_node(const __c_node&) = delete; 52 __c_node& operator=(const __c_node&) = delete; 53 _LIBCPP_INLINE_VISIBILITY 54 __c_node(void* __c, __c_node* __next) 55 : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} 56 virtual ~__c_node(); 57 58 virtual bool __dereferenceable(const void*) const = 0; 59 virtual bool __decrementable(const void*) const = 0; 60 virtual bool __addable(const void*, ptrdiff_t) const = 0; 61 virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; 62 63 void __add(__i_node* __i); 64 _LIBCPP_HIDDEN void __remove(__i_node* __i); 65 }; 66 67 template <class _Cont> 68 struct _C_node 69 : public __c_node 70 { 71 _C_node(void* __c, __c_node* __n) 72 : __c_node(__c, __n) {} 73 74 virtual bool __dereferenceable(const void*) const; 75 virtual bool __decrementable(const void*) const; 76 virtual bool __addable(const void*, ptrdiff_t) const; 77 virtual bool __subscriptable(const void*, ptrdiff_t) const; 78 }; 79 80 template <class _Cont> 81 bool 82 _C_node<_Cont>::__dereferenceable(const void* __i) const 83 { 84 typedef typename _Cont::const_iterator iterator; 85 const iterator* __j = static_cast<const iterator*>(__i); 86 _Cont* _Cp = static_cast<_Cont*>(__c_); 87 return _Cp->__dereferenceable(__j); 88 } 89 90 template <class _Cont> 91 bool 92 _C_node<_Cont>::__decrementable(const void* __i) const 93 { 94 typedef typename _Cont::const_iterator iterator; 95 const iterator* __j = static_cast<const iterator*>(__i); 96 _Cont* _Cp = static_cast<_Cont*>(__c_); 97 return _Cp->__decrementable(__j); 98 } 99 100 template <class _Cont> 101 bool 102 _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const 103 { 104 typedef typename _Cont::const_iterator iterator; 105 const iterator* __j = static_cast<const iterator*>(__i); 106 _Cont* _Cp = static_cast<_Cont*>(__c_); 107 return _Cp->__addable(__j, __n); 108 } 109 110 template <class _Cont> 111 bool 112 _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const 113 { 114 typedef typename _Cont::const_iterator iterator; 115 const iterator* __j = static_cast<const iterator*>(__i); 116 _Cont* _Cp = static_cast<_Cont*>(__c_); 117 return _Cp->__subscriptable(__j, __n); 118 } 119 120 class _LIBCPP_VISIBLE __libcpp_db 121 { 122 __c_node** __cbeg_; 123 __c_node** __cend_; 124 size_t __csz_; 125 __i_node** __ibeg_; 126 __i_node** __iend_; 127 size_t __isz_; 128 129 __libcpp_db(); 130 public: 131 __libcpp_db(const __libcpp_db&) = delete; 132 __libcpp_db& operator=(const __libcpp_db&) = delete; 133 ~__libcpp_db(); 134 135 class __db_c_iterator; 136 class __db_c_const_iterator; 137 class __db_i_iterator; 138 class __db_i_const_iterator; 139 140 __db_c_const_iterator __c_end() const; 141 __db_i_const_iterator __i_end() const; 142 143 template <class _Cont> 144 _LIBCPP_INLINE_VISIBILITY 145 void __insert_c(_Cont* __c) 146 { 147 __c_node* __n = __insert_c(static_cast<void*>(__c)); 148 ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_); 149 } 150 151 void __insert_i(void* __i); 152 __c_node* __insert_c(void* __c); 153 void __erase_c(void* __c); 154 155 void __insert_ic(void* __i, const void* __c); 156 void __iterator_copy(void* __i, const void* __i0); 157 void __erase_i(void* __i); 158 159 void* __find_c_from_i(void* __i) const; 160 void __invalidate_all(void* __c); 161 __c_node* __find_c_and_lock(void* __c) const; 162 __c_node* __find_c(void* __c) const; 163 void unlock() const; 164 165 void swap(void* __c1, void* __c2); 166 167 168 bool __dereferenceable(const void* __i) const; 169 bool __decrementable(const void* __i) const; 170 bool __addable(const void* __i, ptrdiff_t __n) const; 171 bool __subscriptable(const void* __i, ptrdiff_t __n) const; 172 bool __comparable(const void* __i, const void* __j) const; 173 private: 174 _LIBCPP_HIDDEN 175 __i_node* __insert_iterator(void* __i); 176 _LIBCPP_HIDDEN 177 __i_node* __find_iterator(const void* __i) const; 178 179 friend _LIBCPP_VISIBLE __libcpp_db* __get_db(); 180 }; 181 182 _LIBCPP_VISIBLE __libcpp_db* __get_db(); 183 _LIBCPP_VISIBLE const __libcpp_db* __get_const_db(); 184 185 186 _LIBCPP_END_NAMESPACE_STD 187 188 #endif 189 190 #endif // _LIBCPP_DEBUG_H 191 192