__debug revision 262801
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 14262801Sdim#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 15262801Sdim#pragma GCC system_header 16262801Sdim#endif 17262801Sdim 18227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 1 19227825Stheraven 20227825Stheraven# include <cstdlib> 21227825Stheraven# include <cstdio> 22227825Stheraven# include <cstddef> 23249998Sdim# ifndef _LIBCPP_ASSERT 24249998Sdim# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort())) 25249998Sdim# endif 26227825Stheraven 27227825Stheraven#endif 28227825Stheraven 29227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2 30227825Stheraven 31227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 32227825Stheraven 33249998Sdimstruct _LIBCPP_TYPE_VIS __c_node; 34227825Stheraven 35249998Sdimstruct _LIBCPP_TYPE_VIS __i_node 36227825Stheraven{ 37227825Stheraven void* __i_; 38227825Stheraven __i_node* __next_; 39227825Stheraven __c_node* __c_; 40227825Stheraven 41262801Sdim#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 42227825Stheraven __i_node(const __i_node&) = delete; 43227825Stheraven __i_node& operator=(const __i_node&) = delete; 44262801Sdim#else 45262801Sdimprivate: 46262801Sdim __i_node(const __i_node&); 47262801Sdim __i_node& operator=(const __i_node&); 48262801Sdimpublic: 49262801Sdim#endif 50227825Stheraven _LIBCPP_INLINE_VISIBILITY 51227825Stheraven __i_node(void* __i, __i_node* __next, __c_node* __c) 52227825Stheraven : __i_(__i), __next_(__next), __c_(__c) {} 53227825Stheraven ~__i_node(); 54227825Stheraven}; 55227825Stheraven 56249998Sdimstruct _LIBCPP_TYPE_VIS __c_node 57227825Stheraven{ 58227825Stheraven void* __c_; 59227825Stheraven __c_node* __next_; 60227825Stheraven __i_node** beg_; 61227825Stheraven __i_node** end_; 62227825Stheraven __i_node** cap_; 63227825Stheraven 64262801Sdim#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 65227825Stheraven __c_node(const __c_node&) = delete; 66227825Stheraven __c_node& operator=(const __c_node&) = delete; 67262801Sdim#else 68262801Sdimprivate: 69262801Sdim __c_node(const __c_node&); 70262801Sdim __c_node& operator=(const __c_node&); 71262801Sdimpublic: 72262801Sdim#endif 73227825Stheraven _LIBCPP_INLINE_VISIBILITY 74227825Stheraven __c_node(void* __c, __c_node* __next) 75227825Stheraven : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} 76227825Stheraven virtual ~__c_node(); 77227825Stheraven 78227825Stheraven virtual bool __dereferenceable(const void*) const = 0; 79227825Stheraven virtual bool __decrementable(const void*) const = 0; 80227825Stheraven virtual bool __addable(const void*, ptrdiff_t) const = 0; 81227825Stheraven virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; 82227825Stheraven 83227825Stheraven void __add(__i_node* __i); 84227825Stheraven _LIBCPP_HIDDEN void __remove(__i_node* __i); 85227825Stheraven}; 86227825Stheraven 87227825Stheraventemplate <class _Cont> 88227825Stheravenstruct _C_node 89227825Stheraven : public __c_node 90227825Stheraven{ 91227825Stheraven _C_node(void* __c, __c_node* __n) 92227825Stheraven : __c_node(__c, __n) {} 93227825Stheraven 94227825Stheraven virtual bool __dereferenceable(const void*) const; 95227825Stheraven virtual bool __decrementable(const void*) const; 96227825Stheraven virtual bool __addable(const void*, ptrdiff_t) const; 97227825Stheraven virtual bool __subscriptable(const void*, ptrdiff_t) const; 98227825Stheraven}; 99227825Stheraven 100227825Stheraventemplate <class _Cont> 101227825Stheravenbool 102227825Stheraven_C_node<_Cont>::__dereferenceable(const void* __i) 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->__dereferenceable(__j); 108227825Stheraven} 109227825Stheraven 110227825Stheraventemplate <class _Cont> 111227825Stheravenbool 112227825Stheraven_C_node<_Cont>::__decrementable(const void* __i) 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->__decrementable(__j); 118227825Stheraven} 119227825Stheraven 120227825Stheraventemplate <class _Cont> 121227825Stheravenbool 122227825Stheraven_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const 123227825Stheraven{ 124227825Stheraven typedef typename _Cont::const_iterator iterator; 125227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 126232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 127232950Stheraven return _Cp->__addable(__j, __n); 128227825Stheraven} 129227825Stheraven 130227825Stheraventemplate <class _Cont> 131227825Stheravenbool 132227825Stheraven_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const 133227825Stheraven{ 134227825Stheraven typedef typename _Cont::const_iterator iterator; 135227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 136232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 137232950Stheraven return _Cp->__subscriptable(__j, __n); 138227825Stheraven} 139227825Stheraven 140249998Sdimclass _LIBCPP_TYPE_VIS __libcpp_db 141227825Stheraven{ 142227825Stheraven __c_node** __cbeg_; 143227825Stheraven __c_node** __cend_; 144227825Stheraven size_t __csz_; 145227825Stheraven __i_node** __ibeg_; 146227825Stheraven __i_node** __iend_; 147227825Stheraven size_t __isz_; 148227825Stheraven 149227825Stheraven __libcpp_db(); 150227825Stheravenpublic: 151262801Sdim#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 152227825Stheraven __libcpp_db(const __libcpp_db&) = delete; 153227825Stheraven __libcpp_db& operator=(const __libcpp_db&) = delete; 154262801Sdim#else 155262801Sdimprivate: 156262801Sdim __libcpp_db(const __libcpp_db&); 157262801Sdim __libcpp_db& operator=(const __libcpp_db&); 158262801Sdimpublic: 159262801Sdim#endif 160227825Stheraven ~__libcpp_db(); 161227825Stheraven 162227825Stheraven class __db_c_iterator; 163227825Stheraven class __db_c_const_iterator; 164227825Stheraven class __db_i_iterator; 165227825Stheraven class __db_i_const_iterator; 166227825Stheraven 167227825Stheraven __db_c_const_iterator __c_end() const; 168227825Stheraven __db_i_const_iterator __i_end() const; 169227825Stheraven 170227825Stheraven template <class _Cont> 171227825Stheraven _LIBCPP_INLINE_VISIBILITY 172227825Stheraven void __insert_c(_Cont* __c) 173227825Stheraven { 174227825Stheraven __c_node* __n = __insert_c(static_cast<void*>(__c)); 175227825Stheraven ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_); 176227825Stheraven } 177227825Stheraven 178227825Stheraven void __insert_i(void* __i); 179227825Stheraven __c_node* __insert_c(void* __c); 180227825Stheraven void __erase_c(void* __c); 181227825Stheraven 182227825Stheraven void __insert_ic(void* __i, const void* __c); 183227825Stheraven void __iterator_copy(void* __i, const void* __i0); 184227825Stheraven void __erase_i(void* __i); 185227825Stheraven 186227825Stheraven void* __find_c_from_i(void* __i) const; 187227825Stheraven void __invalidate_all(void* __c); 188227825Stheraven __c_node* __find_c_and_lock(void* __c) const; 189227825Stheraven __c_node* __find_c(void* __c) const; 190227825Stheraven void unlock() const; 191227825Stheraven 192227825Stheraven void swap(void* __c1, void* __c2); 193227825Stheraven 194227825Stheraven 195227825Stheraven bool __dereferenceable(const void* __i) const; 196227825Stheraven bool __decrementable(const void* __i) const; 197227825Stheraven bool __addable(const void* __i, ptrdiff_t __n) const; 198227825Stheraven bool __subscriptable(const void* __i, ptrdiff_t __n) const; 199262801Sdim bool __less_than_comparable(const void* __i, const void* __j) const; 200227825Stheravenprivate: 201227825Stheraven _LIBCPP_HIDDEN 202227825Stheraven __i_node* __insert_iterator(void* __i); 203227825Stheraven _LIBCPP_HIDDEN 204227825Stheraven __i_node* __find_iterator(const void* __i) const; 205227825Stheraven 206249998Sdim friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db(); 207227825Stheraven}; 208227825Stheraven 209249998Sdim_LIBCPP_FUNC_VIS __libcpp_db* __get_db(); 210249998Sdim_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db(); 211227825Stheraven 212227825Stheraven 213227825Stheraven_LIBCPP_END_NAMESPACE_STD 214227825Stheraven 215227825Stheraven#endif 216227825Stheraven 217227825Stheraven#endif // _LIBCPP_DEBUG_H 218227825Stheraven 219