__debug revision 278724
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 14278724Sdim#include <__config> 15278724Sdim 16262801Sdim#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17262801Sdim#pragma GCC system_header 18262801Sdim#endif 19262801Sdim 20227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 1 21227825Stheraven# include <cstdlib> 22227825Stheraven# include <cstdio> 23227825Stheraven# include <cstddef> 24249998Sdim# ifndef _LIBCPP_ASSERT 25249998Sdim# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort())) 26249998Sdim# endif 27278724Sdim#endif 28227825Stheraven 29278724Sdim#ifndef _LIBCPP_ASSERT 30278724Sdim# define _LIBCPP_ASSERT(x, m) ((void)0) 31227825Stheraven#endif 32227825Stheraven 33227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2 34227825Stheraven 35227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 36227825Stheraven 37249998Sdimstruct _LIBCPP_TYPE_VIS __c_node; 38227825Stheraven 39249998Sdimstruct _LIBCPP_TYPE_VIS __i_node 40227825Stheraven{ 41227825Stheraven void* __i_; 42227825Stheraven __i_node* __next_; 43227825Stheraven __c_node* __c_; 44227825Stheraven 45262801Sdim#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 46227825Stheraven __i_node(const __i_node&) = delete; 47227825Stheraven __i_node& operator=(const __i_node&) = delete; 48262801Sdim#else 49262801Sdimprivate: 50262801Sdim __i_node(const __i_node&); 51262801Sdim __i_node& operator=(const __i_node&); 52262801Sdimpublic: 53262801Sdim#endif 54227825Stheraven _LIBCPP_INLINE_VISIBILITY 55227825Stheraven __i_node(void* __i, __i_node* __next, __c_node* __c) 56227825Stheraven : __i_(__i), __next_(__next), __c_(__c) {} 57227825Stheraven ~__i_node(); 58227825Stheraven}; 59227825Stheraven 60249998Sdimstruct _LIBCPP_TYPE_VIS __c_node 61227825Stheraven{ 62227825Stheraven void* __c_; 63227825Stheraven __c_node* __next_; 64227825Stheraven __i_node** beg_; 65227825Stheraven __i_node** end_; 66227825Stheraven __i_node** cap_; 67227825Stheraven 68262801Sdim#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 69227825Stheraven __c_node(const __c_node&) = delete; 70227825Stheraven __c_node& operator=(const __c_node&) = delete; 71262801Sdim#else 72262801Sdimprivate: 73262801Sdim __c_node(const __c_node&); 74262801Sdim __c_node& operator=(const __c_node&); 75262801Sdimpublic: 76262801Sdim#endif 77227825Stheraven _LIBCPP_INLINE_VISIBILITY 78227825Stheraven __c_node(void* __c, __c_node* __next) 79227825Stheraven : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} 80227825Stheraven virtual ~__c_node(); 81227825Stheraven 82227825Stheraven virtual bool __dereferenceable(const void*) const = 0; 83227825Stheraven virtual bool __decrementable(const void*) const = 0; 84227825Stheraven virtual bool __addable(const void*, ptrdiff_t) const = 0; 85227825Stheraven virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; 86227825Stheraven 87227825Stheraven void __add(__i_node* __i); 88227825Stheraven _LIBCPP_HIDDEN void __remove(__i_node* __i); 89227825Stheraven}; 90227825Stheraven 91227825Stheraventemplate <class _Cont> 92227825Stheravenstruct _C_node 93227825Stheraven : public __c_node 94227825Stheraven{ 95227825Stheraven _C_node(void* __c, __c_node* __n) 96227825Stheraven : __c_node(__c, __n) {} 97227825Stheraven 98227825Stheraven virtual bool __dereferenceable(const void*) const; 99227825Stheraven virtual bool __decrementable(const void*) const; 100227825Stheraven virtual bool __addable(const void*, ptrdiff_t) const; 101227825Stheraven virtual bool __subscriptable(const void*, ptrdiff_t) const; 102227825Stheraven}; 103227825Stheraven 104227825Stheraventemplate <class _Cont> 105227825Stheravenbool 106227825Stheraven_C_node<_Cont>::__dereferenceable(const void* __i) const 107227825Stheraven{ 108227825Stheraven typedef typename _Cont::const_iterator iterator; 109227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 110232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 111232950Stheraven return _Cp->__dereferenceable(__j); 112227825Stheraven} 113227825Stheraven 114227825Stheraventemplate <class _Cont> 115227825Stheravenbool 116227825Stheraven_C_node<_Cont>::__decrementable(const void* __i) const 117227825Stheraven{ 118227825Stheraven typedef typename _Cont::const_iterator iterator; 119227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 120232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 121232950Stheraven return _Cp->__decrementable(__j); 122227825Stheraven} 123227825Stheraven 124227825Stheraventemplate <class _Cont> 125227825Stheravenbool 126227825Stheraven_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const 127227825Stheraven{ 128227825Stheraven typedef typename _Cont::const_iterator iterator; 129227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 130232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 131232950Stheraven return _Cp->__addable(__j, __n); 132227825Stheraven} 133227825Stheraven 134227825Stheraventemplate <class _Cont> 135227825Stheravenbool 136227825Stheraven_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const 137227825Stheraven{ 138227825Stheraven typedef typename _Cont::const_iterator iterator; 139227825Stheraven const iterator* __j = static_cast<const iterator*>(__i); 140232950Stheraven _Cont* _Cp = static_cast<_Cont*>(__c_); 141232950Stheraven return _Cp->__subscriptable(__j, __n); 142227825Stheraven} 143227825Stheraven 144249998Sdimclass _LIBCPP_TYPE_VIS __libcpp_db 145227825Stheraven{ 146227825Stheraven __c_node** __cbeg_; 147227825Stheraven __c_node** __cend_; 148227825Stheraven size_t __csz_; 149227825Stheraven __i_node** __ibeg_; 150227825Stheraven __i_node** __iend_; 151227825Stheraven size_t __isz_; 152227825Stheraven 153227825Stheraven __libcpp_db(); 154227825Stheravenpublic: 155262801Sdim#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 156227825Stheraven __libcpp_db(const __libcpp_db&) = delete; 157227825Stheraven __libcpp_db& operator=(const __libcpp_db&) = delete; 158262801Sdim#else 159262801Sdimprivate: 160262801Sdim __libcpp_db(const __libcpp_db&); 161262801Sdim __libcpp_db& operator=(const __libcpp_db&); 162262801Sdimpublic: 163262801Sdim#endif 164227825Stheraven ~__libcpp_db(); 165227825Stheraven 166227825Stheraven class __db_c_iterator; 167227825Stheraven class __db_c_const_iterator; 168227825Stheraven class __db_i_iterator; 169227825Stheraven class __db_i_const_iterator; 170227825Stheraven 171227825Stheraven __db_c_const_iterator __c_end() const; 172227825Stheraven __db_i_const_iterator __i_end() const; 173227825Stheraven 174227825Stheraven template <class _Cont> 175227825Stheraven _LIBCPP_INLINE_VISIBILITY 176227825Stheraven void __insert_c(_Cont* __c) 177227825Stheraven { 178227825Stheraven __c_node* __n = __insert_c(static_cast<void*>(__c)); 179227825Stheraven ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_); 180227825Stheraven } 181227825Stheraven 182227825Stheraven void __insert_i(void* __i); 183227825Stheraven __c_node* __insert_c(void* __c); 184227825Stheraven void __erase_c(void* __c); 185227825Stheraven 186227825Stheraven void __insert_ic(void* __i, const void* __c); 187227825Stheraven void __iterator_copy(void* __i, const void* __i0); 188227825Stheraven void __erase_i(void* __i); 189227825Stheraven 190227825Stheraven void* __find_c_from_i(void* __i) const; 191227825Stheraven void __invalidate_all(void* __c); 192227825Stheraven __c_node* __find_c_and_lock(void* __c) const; 193227825Stheraven __c_node* __find_c(void* __c) const; 194227825Stheraven void unlock() const; 195227825Stheraven 196227825Stheraven void swap(void* __c1, void* __c2); 197227825Stheraven 198227825Stheraven 199227825Stheraven bool __dereferenceable(const void* __i) const; 200227825Stheraven bool __decrementable(const void* __i) const; 201227825Stheraven bool __addable(const void* __i, ptrdiff_t __n) const; 202227825Stheraven bool __subscriptable(const void* __i, ptrdiff_t __n) const; 203262801Sdim bool __less_than_comparable(const void* __i, const void* __j) const; 204227825Stheravenprivate: 205227825Stheraven _LIBCPP_HIDDEN 206227825Stheraven __i_node* __insert_iterator(void* __i); 207227825Stheraven _LIBCPP_HIDDEN 208227825Stheraven __i_node* __find_iterator(const void* __i) const; 209227825Stheraven 210249998Sdim friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db(); 211227825Stheraven}; 212227825Stheraven 213249998Sdim_LIBCPP_FUNC_VIS __libcpp_db* __get_db(); 214249998Sdim_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db(); 215227825Stheraven 216227825Stheraven 217227825Stheraven_LIBCPP_END_NAMESPACE_STD 218227825Stheraven 219227825Stheraven#endif 220227825Stheraven 221227825Stheraven#endif // _LIBCPP_DEBUG_H 222227825Stheraven 223