14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===--------------------------- __debug ----------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_DEBUG_H 124684ddb6SLionel Sambuc#define _LIBCPP_DEBUG_H 134684ddb6SLionel Sambuc 14*0a6a1f1dSLionel Sambuc#include <__config> 15*0a6a1f1dSLionel Sambuc 164684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 174684ddb6SLionel Sambuc#pragma GCC system_header 184684ddb6SLionel Sambuc#endif 194684ddb6SLionel Sambuc 204684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 1 214684ddb6SLionel Sambuc# include <cstdlib> 224684ddb6SLionel Sambuc# include <cstdio> 234684ddb6SLionel Sambuc# include <cstddef> 244684ddb6SLionel Sambuc# ifndef _LIBCPP_ASSERT 25*0a6a1f1dSLionel Sambuc# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::fprintf(stderr, "%s\n", m), _VSTD::abort())) 26*0a6a1f1dSLionel Sambuc# endif 274684ddb6SLionel Sambuc#endif 284684ddb6SLionel Sambuc 29*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_ASSERT 30*0a6a1f1dSLionel Sambuc# define _LIBCPP_ASSERT(x, m) ((void)0) 314684ddb6SLionel Sambuc#endif 324684ddb6SLionel Sambuc 334684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 344684ddb6SLionel Sambuc 354684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 364684ddb6SLionel Sambuc 374684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS __c_node; 384684ddb6SLionel Sambuc 394684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS __i_node 404684ddb6SLionel Sambuc{ 414684ddb6SLionel Sambuc void* __i_; 424684ddb6SLionel Sambuc __i_node* __next_; 434684ddb6SLionel Sambuc __c_node* __c_; 444684ddb6SLionel Sambuc 454684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 464684ddb6SLionel Sambuc __i_node(const __i_node&) = delete; 474684ddb6SLionel Sambuc __i_node& operator=(const __i_node&) = delete; 484684ddb6SLionel Sambuc#else 494684ddb6SLionel Sambucprivate: 504684ddb6SLionel Sambuc __i_node(const __i_node&); 514684ddb6SLionel Sambuc __i_node& operator=(const __i_node&); 524684ddb6SLionel Sambucpublic: 534684ddb6SLionel Sambuc#endif 544684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 554684ddb6SLionel Sambuc __i_node(void* __i, __i_node* __next, __c_node* __c) 564684ddb6SLionel Sambuc : __i_(__i), __next_(__next), __c_(__c) {} 574684ddb6SLionel Sambuc ~__i_node(); 584684ddb6SLionel Sambuc}; 594684ddb6SLionel Sambuc 604684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS __c_node 614684ddb6SLionel Sambuc{ 624684ddb6SLionel Sambuc void* __c_; 634684ddb6SLionel Sambuc __c_node* __next_; 644684ddb6SLionel Sambuc __i_node** beg_; 654684ddb6SLionel Sambuc __i_node** end_; 664684ddb6SLionel Sambuc __i_node** cap_; 674684ddb6SLionel Sambuc 684684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 694684ddb6SLionel Sambuc __c_node(const __c_node&) = delete; 704684ddb6SLionel Sambuc __c_node& operator=(const __c_node&) = delete; 714684ddb6SLionel Sambuc#else 724684ddb6SLionel Sambucprivate: 734684ddb6SLionel Sambuc __c_node(const __c_node&); 744684ddb6SLionel Sambuc __c_node& operator=(const __c_node&); 754684ddb6SLionel Sambucpublic: 764684ddb6SLionel Sambuc#endif 774684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 784684ddb6SLionel Sambuc __c_node(void* __c, __c_node* __next) 794684ddb6SLionel Sambuc : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} 804684ddb6SLionel Sambuc virtual ~__c_node(); 814684ddb6SLionel Sambuc 824684ddb6SLionel Sambuc virtual bool __dereferenceable(const void*) const = 0; 834684ddb6SLionel Sambuc virtual bool __decrementable(const void*) const = 0; 844684ddb6SLionel Sambuc virtual bool __addable(const void*, ptrdiff_t) const = 0; 854684ddb6SLionel Sambuc virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; 864684ddb6SLionel Sambuc 874684ddb6SLionel Sambuc void __add(__i_node* __i); 884684ddb6SLionel Sambuc _LIBCPP_HIDDEN void __remove(__i_node* __i); 894684ddb6SLionel Sambuc}; 904684ddb6SLionel Sambuc 914684ddb6SLionel Sambuctemplate <class _Cont> 924684ddb6SLionel Sambucstruct _C_node 934684ddb6SLionel Sambuc : public __c_node 944684ddb6SLionel Sambuc{ 954684ddb6SLionel Sambuc _C_node(void* __c, __c_node* __n) 964684ddb6SLionel Sambuc : __c_node(__c, __n) {} 974684ddb6SLionel Sambuc 984684ddb6SLionel Sambuc virtual bool __dereferenceable(const void*) const; 994684ddb6SLionel Sambuc virtual bool __decrementable(const void*) const; 1004684ddb6SLionel Sambuc virtual bool __addable(const void*, ptrdiff_t) const; 1014684ddb6SLionel Sambuc virtual bool __subscriptable(const void*, ptrdiff_t) const; 1024684ddb6SLionel Sambuc}; 1034684ddb6SLionel Sambuc 1044684ddb6SLionel Sambuctemplate <class _Cont> 1054684ddb6SLionel Sambucbool 1064684ddb6SLionel Sambuc_C_node<_Cont>::__dereferenceable(const void* __i) const 1074684ddb6SLionel Sambuc{ 1084684ddb6SLionel Sambuc typedef typename _Cont::const_iterator iterator; 1094684ddb6SLionel Sambuc const iterator* __j = static_cast<const iterator*>(__i); 1104684ddb6SLionel Sambuc _Cont* _Cp = static_cast<_Cont*>(__c_); 1114684ddb6SLionel Sambuc return _Cp->__dereferenceable(__j); 1124684ddb6SLionel Sambuc} 1134684ddb6SLionel Sambuc 1144684ddb6SLionel Sambuctemplate <class _Cont> 1154684ddb6SLionel Sambucbool 1164684ddb6SLionel Sambuc_C_node<_Cont>::__decrementable(const void* __i) const 1174684ddb6SLionel Sambuc{ 1184684ddb6SLionel Sambuc typedef typename _Cont::const_iterator iterator; 1194684ddb6SLionel Sambuc const iterator* __j = static_cast<const iterator*>(__i); 1204684ddb6SLionel Sambuc _Cont* _Cp = static_cast<_Cont*>(__c_); 1214684ddb6SLionel Sambuc return _Cp->__decrementable(__j); 1224684ddb6SLionel Sambuc} 1234684ddb6SLionel Sambuc 1244684ddb6SLionel Sambuctemplate <class _Cont> 1254684ddb6SLionel Sambucbool 1264684ddb6SLionel Sambuc_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const 1274684ddb6SLionel Sambuc{ 1284684ddb6SLionel Sambuc typedef typename _Cont::const_iterator iterator; 1294684ddb6SLionel Sambuc const iterator* __j = static_cast<const iterator*>(__i); 1304684ddb6SLionel Sambuc _Cont* _Cp = static_cast<_Cont*>(__c_); 1314684ddb6SLionel Sambuc return _Cp->__addable(__j, __n); 1324684ddb6SLionel Sambuc} 1334684ddb6SLionel Sambuc 1344684ddb6SLionel Sambuctemplate <class _Cont> 1354684ddb6SLionel Sambucbool 1364684ddb6SLionel Sambuc_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const 1374684ddb6SLionel Sambuc{ 1384684ddb6SLionel Sambuc typedef typename _Cont::const_iterator iterator; 1394684ddb6SLionel Sambuc const iterator* __j = static_cast<const iterator*>(__i); 1404684ddb6SLionel Sambuc _Cont* _Cp = static_cast<_Cont*>(__c_); 1414684ddb6SLionel Sambuc return _Cp->__subscriptable(__j, __n); 1424684ddb6SLionel Sambuc} 1434684ddb6SLionel Sambuc 1444684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS __libcpp_db 1454684ddb6SLionel Sambuc{ 1464684ddb6SLionel Sambuc __c_node** __cbeg_; 1474684ddb6SLionel Sambuc __c_node** __cend_; 1484684ddb6SLionel Sambuc size_t __csz_; 1494684ddb6SLionel Sambuc __i_node** __ibeg_; 1504684ddb6SLionel Sambuc __i_node** __iend_; 1514684ddb6SLionel Sambuc size_t __isz_; 1524684ddb6SLionel Sambuc 1534684ddb6SLionel Sambuc __libcpp_db(); 1544684ddb6SLionel Sambucpublic: 1554684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 1564684ddb6SLionel Sambuc __libcpp_db(const __libcpp_db&) = delete; 1574684ddb6SLionel Sambuc __libcpp_db& operator=(const __libcpp_db&) = delete; 1584684ddb6SLionel Sambuc#else 1594684ddb6SLionel Sambucprivate: 1604684ddb6SLionel Sambuc __libcpp_db(const __libcpp_db&); 1614684ddb6SLionel Sambuc __libcpp_db& operator=(const __libcpp_db&); 1624684ddb6SLionel Sambucpublic: 1634684ddb6SLionel Sambuc#endif 1644684ddb6SLionel Sambuc ~__libcpp_db(); 1654684ddb6SLionel Sambuc 1664684ddb6SLionel Sambuc class __db_c_iterator; 1674684ddb6SLionel Sambuc class __db_c_const_iterator; 1684684ddb6SLionel Sambuc class __db_i_iterator; 1694684ddb6SLionel Sambuc class __db_i_const_iterator; 1704684ddb6SLionel Sambuc 1714684ddb6SLionel Sambuc __db_c_const_iterator __c_end() const; 1724684ddb6SLionel Sambuc __db_i_const_iterator __i_end() const; 1734684ddb6SLionel Sambuc 1744684ddb6SLionel Sambuc template <class _Cont> 1754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1764684ddb6SLionel Sambuc void __insert_c(_Cont* __c) 1774684ddb6SLionel Sambuc { 1784684ddb6SLionel Sambuc __c_node* __n = __insert_c(static_cast<void*>(__c)); 1794684ddb6SLionel Sambuc ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_); 1804684ddb6SLionel Sambuc } 1814684ddb6SLionel Sambuc 1824684ddb6SLionel Sambuc void __insert_i(void* __i); 1834684ddb6SLionel Sambuc __c_node* __insert_c(void* __c); 1844684ddb6SLionel Sambuc void __erase_c(void* __c); 1854684ddb6SLionel Sambuc 1864684ddb6SLionel Sambuc void __insert_ic(void* __i, const void* __c); 1874684ddb6SLionel Sambuc void __iterator_copy(void* __i, const void* __i0); 1884684ddb6SLionel Sambuc void __erase_i(void* __i); 1894684ddb6SLionel Sambuc 1904684ddb6SLionel Sambuc void* __find_c_from_i(void* __i) const; 1914684ddb6SLionel Sambuc void __invalidate_all(void* __c); 1924684ddb6SLionel Sambuc __c_node* __find_c_and_lock(void* __c) const; 1934684ddb6SLionel Sambuc __c_node* __find_c(void* __c) const; 1944684ddb6SLionel Sambuc void unlock() const; 1954684ddb6SLionel Sambuc 1964684ddb6SLionel Sambuc void swap(void* __c1, void* __c2); 1974684ddb6SLionel Sambuc 1984684ddb6SLionel Sambuc 1994684ddb6SLionel Sambuc bool __dereferenceable(const void* __i) const; 2004684ddb6SLionel Sambuc bool __decrementable(const void* __i) const; 2014684ddb6SLionel Sambuc bool __addable(const void* __i, ptrdiff_t __n) const; 2024684ddb6SLionel Sambuc bool __subscriptable(const void* __i, ptrdiff_t __n) const; 2034684ddb6SLionel Sambuc bool __less_than_comparable(const void* __i, const void* __j) const; 2044684ddb6SLionel Sambucprivate: 2054684ddb6SLionel Sambuc _LIBCPP_HIDDEN 2064684ddb6SLionel Sambuc __i_node* __insert_iterator(void* __i); 2074684ddb6SLionel Sambuc _LIBCPP_HIDDEN 2084684ddb6SLionel Sambuc __i_node* __find_iterator(const void* __i) const; 2094684ddb6SLionel Sambuc 2104684ddb6SLionel Sambuc friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db(); 2114684ddb6SLionel Sambuc}; 2124684ddb6SLionel Sambuc 2134684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS __libcpp_db* __get_db(); 2144684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db(); 2154684ddb6SLionel Sambuc 2164684ddb6SLionel Sambuc 2174684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 2184684ddb6SLionel Sambuc 2194684ddb6SLionel Sambuc#endif 2204684ddb6SLionel Sambuc 2214684ddb6SLionel Sambuc#endif // _LIBCPP_DEBUG_H 2224684ddb6SLionel Sambuc 223