__debug revision 232950
1227825Stheraven// -*- C++ -*- 2227825Stheraven//===--------------------------- __debug ----------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_DEBUG_H 12227825Stheraven#define _LIBCPP_DEBUG_H 13227825Stheraven 14227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 1 15227825Stheraven 16227825Stheraven# include <cstdlib> 17227825Stheraven# include <cstdio> 18227825Stheraven# include <cstddef> 19227825Stheraven# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort())) 20227825Stheraven 21227825Stheraven#endif 22227825Stheraven 23227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2 24227825Stheraven 25227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 26227825Stheraven 27227825Stheravenstruct _LIBCPP_VISIBLE __c_node; 28227825Stheraven 29227825Stheravenstruct _LIBCPP_VISIBLE __i_node 30227825Stheraven{ 31227825Stheraven void* __i_; 32227825Stheraven __i_node* __next_; 33227825Stheraven __c_node* __c_; 34227825Stheraven 35227825Stheraven __i_node(const __i_node&) = delete; 36227825Stheraven __i_node& operator=(const __i_node&) = delete; 37227825Stheraven _LIBCPP_INLINE_VISIBILITY 38227825Stheraven __i_node(void* __i, __i_node* __next, __c_node* __c) 39227825Stheraven : __i_(__i), __next_(__next), __c_(__c) {} 40227825Stheraven ~__i_node(); 41227825Stheraven}; 42227825Stheraven 43227825Stheravenstruct _LIBCPP_VISIBLE __c_node 44227825Stheraven{ 45227825Stheraven void* __c_; 46227825Stheraven __c_node* __next_; 47227825Stheraven __i_node** beg_; 48227825Stheraven __i_node** end_; 49227825Stheraven __i_node** cap_; 50227825Stheraven 51227825Stheraven __c_node(const __c_node&) = delete; 52227825Stheraven __c_node& operator=(const __c_node&) = delete; 53227825Stheraven _LIBCPP_INLINE_VISIBILITY 54227825Stheraven __c_node(void* __c, __c_node* __next) 55227825Stheraven : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} 56227825Stheraven virtual ~__c_node(); 57227825Stheraven 58227825Stheraven virtual bool __dereferenceable(const void*) const = 0; 59227825Stheraven virtual bool __decrementable(const void*) const = 0; 60227825Stheraven virtual bool __addable(const void*, ptrdiff_t) const = 0; 61227825Stheraven virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; 62227825Stheraven 63227825Stheraven void __add(__i_node* __i); 64227825Stheraven _LIBCPP_HIDDEN void __remove(__i_node* __i); 65227825Stheraven}; 66227825Stheraven 67227825Stheraventemplate <class _Cont> 68227825Stheravenstruct _C_node 69227825Stheraven : public __c_node 70227825Stheraven{ 71227825Stheraven _C_node(void* __c, __c_node* __n) 72227825Stheraven : __c_node(__c, __n) {} 73227825Stheraven 74227825Stheraven virtual bool __dereferenceable(const void*) const; 75227825Stheraven virtual bool __decrementable(const void*) const; 76227825Stheraven virtual bool __addable(const void*, ptrdiff_t) const; 77227825Stheraven virtual bool __subscriptable(const void*, ptrdiff_t) const; 78227825Stheraven}; 79227825Stheraven 80227825Stheraventemplate <class _Cont> 81227825Stheravenbool 82227825Stheraven_C_node<_Cont>::__dereferenceable(const void* __i) const 83227825Stheraven{ 84227825Stheraven typedef typename _Cont::const_iterator iterator; 85227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 86232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 87232950Stheraven return _Cp->__dereferenceable(__j); 88227825Stheraven} 89227825Stheraven 90227825Stheraventemplate <class _Cont> 91227825Stheravenbool 92227825Stheraven_C_node<_Cont>::__decrementable(const void* __i) const 93227825Stheraven{ 94227825Stheraven typedef typename _Cont::const_iterator iterator; 95227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 96232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 97232950Stheraven return _Cp->__decrementable(__j); 98227825Stheraven} 99227825Stheraven 100227825Stheraventemplate <class _Cont> 101227825Stheravenbool 102227825Stheraven_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const 103227825Stheraven{ 104227825Stheraven typedef typename _Cont::const_iterator iterator; 105227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 106232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 107232950Stheraven return _Cp->__addable(__j, __n); 108227825Stheraven} 109227825Stheraven 110227825Stheraventemplate <class _Cont> 111227825Stheravenbool 112227825Stheraven_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const 113227825Stheraven{ 114227825Stheraven typedef typename _Cont::const_iterator iterator; 115227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 116232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 117232950Stheraven return _Cp->__subscriptable(__j, __n); 118227825Stheraven} 119227825Stheraven 120227825Stheravenclass _LIBCPP_VISIBLE __libcpp_db 121227825Stheraven{ 122227825Stheraven __c_node** __cbeg_; 123227825Stheraven __c_node** __cend_; 124227825Stheraven size_t __csz_; 125227825Stheraven __i_node** __ibeg_; 126227825Stheraven __i_node** __iend_; 127227825Stheraven size_t __isz_; 128227825Stheraven 129227825Stheraven __libcpp_db(); 130227825Stheravenpublic: 131227825Stheraven __libcpp_db(const __libcpp_db&) = delete; 132227825Stheraven __libcpp_db& operator=(const __libcpp_db&) = delete; 133227825Stheraven ~__libcpp_db(); 134227825Stheraven 135227825Stheraven class __db_c_iterator; 136227825Stheraven class __db_c_const_iterator; 137227825Stheraven class __db_i_iterator; 138227825Stheraven class __db_i_const_iterator; 139227825Stheraven 140227825Stheraven __db_c_const_iterator __c_end() const; 141227825Stheraven __db_i_const_iterator __i_end() const; 142227825Stheraven 143227825Stheraven template <class _Cont> 144227825Stheraven _LIBCPP_INLINE_VISIBILITY 145227825Stheraven void __insert_c(_Cont* __c) 146227825Stheraven { 147227825Stheraven __c_node* __n = __insert_c(static_cast<void*>(__c)); 148227825Stheraven ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_); 149227825Stheraven } 150227825Stheraven 151227825Stheraven void __insert_i(void* __i); 152227825Stheraven __c_node* __insert_c(void* __c); 153227825Stheraven void __erase_c(void* __c); 154227825Stheraven 155227825Stheraven void __insert_ic(void* __i, const void* __c); 156227825Stheraven void __iterator_copy(void* __i, const void* __i0); 157227825Stheraven void __erase_i(void* __i); 158227825Stheraven 159227825Stheraven void* __find_c_from_i(void* __i) const; 160227825Stheraven void __invalidate_all(void* __c); 161227825Stheraven __c_node* __find_c_and_lock(void* __c) const; 162227825Stheraven __c_node* __find_c(void* __c) const; 163227825Stheraven void unlock() const; 164227825Stheraven 165227825Stheraven void swap(void* __c1, void* __c2); 166227825Stheraven 167227825Stheraven 168227825Stheraven bool __dereferenceable(const void* __i) const; 169227825Stheraven bool __decrementable(const void* __i) const; 170227825Stheraven bool __addable(const void* __i, ptrdiff_t __n) const; 171227825Stheraven bool __subscriptable(const void* __i, ptrdiff_t __n) const; 172227825Stheraven bool __comparable(const void* __i, const void* __j) const; 173227825Stheravenprivate: 174227825Stheraven _LIBCPP_HIDDEN 175227825Stheraven __i_node* __insert_iterator(void* __i); 176227825Stheraven _LIBCPP_HIDDEN 177227825Stheraven __i_node* __find_iterator(const void* __i) const; 178227825Stheraven 179227825Stheraven friend _LIBCPP_VISIBLE __libcpp_db* __get_db(); 180227825Stheraven}; 181227825Stheraven 182227825Stheraven_LIBCPP_VISIBLE __libcpp_db* __get_db(); 183227825Stheraven_LIBCPP_VISIBLE const __libcpp_db* __get_const_db(); 184227825Stheraven 185227825Stheraven 186227825Stheraven_LIBCPP_END_NAMESPACE_STD 187227825Stheraven 188227825Stheraven#endif 189227825Stheraven 190227825Stheraven#endif // _LIBCPP_DEBUG_H 191227825Stheraven 192