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