1*4d6fc14bSjoerg// -*- C++ -*- 2*4d6fc14bSjoerg//===--------------------------- __debug ----------------------------------===// 3*4d6fc14bSjoerg// 4*4d6fc14bSjoerg// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*4d6fc14bSjoerg// See https://llvm.org/LICENSE.txt for license information. 6*4d6fc14bSjoerg// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*4d6fc14bSjoerg// 8*4d6fc14bSjoerg//===----------------------------------------------------------------------===// 9*4d6fc14bSjoerg 10*4d6fc14bSjoerg#ifndef _LIBCPP_DEBUG_H 11*4d6fc14bSjoerg#define _LIBCPP_DEBUG_H 12*4d6fc14bSjoerg 13*4d6fc14bSjoerg#include <__config> 14*4d6fc14bSjoerg#include <iosfwd> 15*4d6fc14bSjoerg 16*4d6fc14bSjoerg#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17*4d6fc14bSjoerg#pragma GCC system_header 18*4d6fc14bSjoerg#endif 19*4d6fc14bSjoerg 20*4d6fc14bSjoerg#if defined(_LIBCPP_HAS_NO_NULLPTR) 21*4d6fc14bSjoerg# include <cstddef> 22*4d6fc14bSjoerg#endif 23*4d6fc14bSjoerg 24*4d6fc14bSjoerg#if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY) 25*4d6fc14bSjoerg# include <cstdlib> 26*4d6fc14bSjoerg# include <cstdio> 27*4d6fc14bSjoerg# include <cstddef> 28*4d6fc14bSjoerg#endif 29*4d6fc14bSjoerg 30*4d6fc14bSjoerg#if _LIBCPP_DEBUG_LEVEL == 0 31*4d6fc14bSjoerg# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) 32*4d6fc14bSjoerg# define _LIBCPP_ASSERT_IMPL(x, m) ((void)0) 33*4d6fc14bSjoerg#elif _LIBCPP_DEBUG_LEVEL == 1 34*4d6fc14bSjoerg# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) 35*4d6fc14bSjoerg# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) 36*4d6fc14bSjoerg#elif _LIBCPP_DEBUG_LEVEL == 2 37*4d6fc14bSjoerg# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m) 38*4d6fc14bSjoerg# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) 39*4d6fc14bSjoerg#else 40*4d6fc14bSjoerg# error _LIBCPP_DEBUG_LEVEL must be one of 0, 1, 2 41*4d6fc14bSjoerg#endif 42*4d6fc14bSjoerg 43*4d6fc14bSjoerg#if !defined(_LIBCPP_ASSERT) 44*4d6fc14bSjoerg# define _LIBCPP_ASSERT(x, m) _LIBCPP_ASSERT_IMPL(x, m) 45*4d6fc14bSjoerg#endif 46*4d6fc14bSjoerg 47*4d6fc14bSjoerg_LIBCPP_BEGIN_NAMESPACE_STD 48*4d6fc14bSjoerg 49*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info { 50*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 51*4d6fc14bSjoerg __libcpp_debug_info() 52*4d6fc14bSjoerg : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {} 53*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 54*4d6fc14bSjoerg __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m) 55*4d6fc14bSjoerg : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {} 56*4d6fc14bSjoerg 57*4d6fc14bSjoerg _LIBCPP_FUNC_VIS string what() const; 58*4d6fc14bSjoerg 59*4d6fc14bSjoerg const char* __file_; 60*4d6fc14bSjoerg int __line_; 61*4d6fc14bSjoerg const char* __pred_; 62*4d6fc14bSjoerg const char* __msg_; 63*4d6fc14bSjoerg}; 64*4d6fc14bSjoerg 65*4d6fc14bSjoerg/// __libcpp_debug_function_type - The type of the assertion failure handler. 66*4d6fc14bSjoergtypedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&); 67*4d6fc14bSjoerg 68*4d6fc14bSjoerg/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT 69*4d6fc14bSjoerg/// fails. 70*4d6fc14bSjoergextern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function; 71*4d6fc14bSjoerg 72*4d6fc14bSjoerg/// __libcpp_abort_debug_function - A debug handler that aborts when called. 73*4d6fc14bSjoerg_LIBCPP_NORETURN _LIBCPP_FUNC_VIS 74*4d6fc14bSjoergvoid __libcpp_abort_debug_function(__libcpp_debug_info const&); 75*4d6fc14bSjoerg 76*4d6fc14bSjoerg/// __libcpp_set_debug_function - Set the debug handler to the specified 77*4d6fc14bSjoerg/// function. 78*4d6fc14bSjoerg_LIBCPP_FUNC_VIS 79*4d6fc14bSjoergbool __libcpp_set_debug_function(__libcpp_debug_function_type __func); 80*4d6fc14bSjoerg 81*4d6fc14bSjoerg#if _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY) 82*4d6fc14bSjoerg 83*4d6fc14bSjoergstruct _LIBCPP_TYPE_VIS __c_node; 84*4d6fc14bSjoerg 85*4d6fc14bSjoergstruct _LIBCPP_TYPE_VIS __i_node 86*4d6fc14bSjoerg{ 87*4d6fc14bSjoerg void* __i_; 88*4d6fc14bSjoerg __i_node* __next_; 89*4d6fc14bSjoerg __c_node* __c_; 90*4d6fc14bSjoerg 91*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 92*4d6fc14bSjoerg __i_node(const __i_node&) = delete; 93*4d6fc14bSjoerg __i_node& operator=(const __i_node&) = delete; 94*4d6fc14bSjoerg#else 95*4d6fc14bSjoergprivate: 96*4d6fc14bSjoerg __i_node(const __i_node&); 97*4d6fc14bSjoerg __i_node& operator=(const __i_node&); 98*4d6fc14bSjoergpublic: 99*4d6fc14bSjoerg#endif 100*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 101*4d6fc14bSjoerg __i_node(void* __i, __i_node* __next, __c_node* __c) 102*4d6fc14bSjoerg : __i_(__i), __next_(__next), __c_(__c) {} 103*4d6fc14bSjoerg ~__i_node(); 104*4d6fc14bSjoerg}; 105*4d6fc14bSjoerg 106*4d6fc14bSjoergstruct _LIBCPP_TYPE_VIS __c_node 107*4d6fc14bSjoerg{ 108*4d6fc14bSjoerg void* __c_; 109*4d6fc14bSjoerg __c_node* __next_; 110*4d6fc14bSjoerg __i_node** beg_; 111*4d6fc14bSjoerg __i_node** end_; 112*4d6fc14bSjoerg __i_node** cap_; 113*4d6fc14bSjoerg 114*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 115*4d6fc14bSjoerg __c_node(const __c_node&) = delete; 116*4d6fc14bSjoerg __c_node& operator=(const __c_node&) = delete; 117*4d6fc14bSjoerg#else 118*4d6fc14bSjoergprivate: 119*4d6fc14bSjoerg __c_node(const __c_node&); 120*4d6fc14bSjoerg __c_node& operator=(const __c_node&); 121*4d6fc14bSjoergpublic: 122*4d6fc14bSjoerg#endif 123*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 124*4d6fc14bSjoerg __c_node(void* __c, __c_node* __next) 125*4d6fc14bSjoerg : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} 126*4d6fc14bSjoerg virtual ~__c_node(); 127*4d6fc14bSjoerg 128*4d6fc14bSjoerg virtual bool __dereferenceable(const void*) const = 0; 129*4d6fc14bSjoerg virtual bool __decrementable(const void*) const = 0; 130*4d6fc14bSjoerg virtual bool __addable(const void*, ptrdiff_t) const = 0; 131*4d6fc14bSjoerg virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; 132*4d6fc14bSjoerg 133*4d6fc14bSjoerg void __add(__i_node* __i); 134*4d6fc14bSjoerg _LIBCPP_HIDDEN void __remove(__i_node* __i); 135*4d6fc14bSjoerg}; 136*4d6fc14bSjoerg 137*4d6fc14bSjoergtemplate <class _Cont> 138*4d6fc14bSjoergstruct _C_node 139*4d6fc14bSjoerg : public __c_node 140*4d6fc14bSjoerg{ 141*4d6fc14bSjoerg _C_node(void* __c, __c_node* __n) 142*4d6fc14bSjoerg : __c_node(__c, __n) {} 143*4d6fc14bSjoerg 144*4d6fc14bSjoerg virtual bool __dereferenceable(const void*) const; 145*4d6fc14bSjoerg virtual bool __decrementable(const void*) const; 146*4d6fc14bSjoerg virtual bool __addable(const void*, ptrdiff_t) const; 147*4d6fc14bSjoerg virtual bool __subscriptable(const void*, ptrdiff_t) const; 148*4d6fc14bSjoerg}; 149*4d6fc14bSjoerg 150*4d6fc14bSjoergtemplate <class _Cont> 151*4d6fc14bSjoerginline bool 152*4d6fc14bSjoerg_C_node<_Cont>::__dereferenceable(const void* __i) const 153*4d6fc14bSjoerg{ 154*4d6fc14bSjoerg typedef typename _Cont::const_iterator iterator; 155*4d6fc14bSjoerg const iterator* __j = static_cast<const iterator*>(__i); 156*4d6fc14bSjoerg _Cont* _Cp = static_cast<_Cont*>(__c_); 157*4d6fc14bSjoerg return _Cp->__dereferenceable(__j); 158*4d6fc14bSjoerg} 159*4d6fc14bSjoerg 160*4d6fc14bSjoergtemplate <class _Cont> 161*4d6fc14bSjoerginline bool 162*4d6fc14bSjoerg_C_node<_Cont>::__decrementable(const void* __i) const 163*4d6fc14bSjoerg{ 164*4d6fc14bSjoerg typedef typename _Cont::const_iterator iterator; 165*4d6fc14bSjoerg const iterator* __j = static_cast<const iterator*>(__i); 166*4d6fc14bSjoerg _Cont* _Cp = static_cast<_Cont*>(__c_); 167*4d6fc14bSjoerg return _Cp->__decrementable(__j); 168*4d6fc14bSjoerg} 169*4d6fc14bSjoerg 170*4d6fc14bSjoergtemplate <class _Cont> 171*4d6fc14bSjoerginline bool 172*4d6fc14bSjoerg_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const 173*4d6fc14bSjoerg{ 174*4d6fc14bSjoerg typedef typename _Cont::const_iterator iterator; 175*4d6fc14bSjoerg const iterator* __j = static_cast<const iterator*>(__i); 176*4d6fc14bSjoerg _Cont* _Cp = static_cast<_Cont*>(__c_); 177*4d6fc14bSjoerg return _Cp->__addable(__j, __n); 178*4d6fc14bSjoerg} 179*4d6fc14bSjoerg 180*4d6fc14bSjoergtemplate <class _Cont> 181*4d6fc14bSjoerginline bool 182*4d6fc14bSjoerg_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const 183*4d6fc14bSjoerg{ 184*4d6fc14bSjoerg typedef typename _Cont::const_iterator iterator; 185*4d6fc14bSjoerg const iterator* __j = static_cast<const iterator*>(__i); 186*4d6fc14bSjoerg _Cont* _Cp = static_cast<_Cont*>(__c_); 187*4d6fc14bSjoerg return _Cp->__subscriptable(__j, __n); 188*4d6fc14bSjoerg} 189*4d6fc14bSjoerg 190*4d6fc14bSjoergclass _LIBCPP_TYPE_VIS __libcpp_db 191*4d6fc14bSjoerg{ 192*4d6fc14bSjoerg __c_node** __cbeg_; 193*4d6fc14bSjoerg __c_node** __cend_; 194*4d6fc14bSjoerg size_t __csz_; 195*4d6fc14bSjoerg __i_node** __ibeg_; 196*4d6fc14bSjoerg __i_node** __iend_; 197*4d6fc14bSjoerg size_t __isz_; 198*4d6fc14bSjoerg 199*4d6fc14bSjoerg __libcpp_db(); 200*4d6fc14bSjoergpublic: 201*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 202*4d6fc14bSjoerg __libcpp_db(const __libcpp_db&) = delete; 203*4d6fc14bSjoerg __libcpp_db& operator=(const __libcpp_db&) = delete; 204*4d6fc14bSjoerg#else 205*4d6fc14bSjoergprivate: 206*4d6fc14bSjoerg __libcpp_db(const __libcpp_db&); 207*4d6fc14bSjoerg __libcpp_db& operator=(const __libcpp_db&); 208*4d6fc14bSjoergpublic: 209*4d6fc14bSjoerg#endif 210*4d6fc14bSjoerg ~__libcpp_db(); 211*4d6fc14bSjoerg 212*4d6fc14bSjoerg class __db_c_iterator; 213*4d6fc14bSjoerg class __db_c_const_iterator; 214*4d6fc14bSjoerg class __db_i_iterator; 215*4d6fc14bSjoerg class __db_i_const_iterator; 216*4d6fc14bSjoerg 217*4d6fc14bSjoerg __db_c_const_iterator __c_end() const; 218*4d6fc14bSjoerg __db_i_const_iterator __i_end() const; 219*4d6fc14bSjoerg 220*4d6fc14bSjoerg typedef __c_node*(_InsertConstruct)(void*, void*, __c_node*); 221*4d6fc14bSjoerg 222*4d6fc14bSjoerg template <class _Cont> 223*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static __c_node* __create_C_node(void *__mem, void *__c, __c_node *__next) { 224*4d6fc14bSjoerg return ::new (__mem) _C_node<_Cont>(__c, __next); 225*4d6fc14bSjoerg } 226*4d6fc14bSjoerg 227*4d6fc14bSjoerg template <class _Cont> 228*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 229*4d6fc14bSjoerg void __insert_c(_Cont* __c) 230*4d6fc14bSjoerg { 231*4d6fc14bSjoerg __insert_c(static_cast<void*>(__c), &__create_C_node<_Cont>); 232*4d6fc14bSjoerg } 233*4d6fc14bSjoerg 234*4d6fc14bSjoerg void __insert_i(void* __i); 235*4d6fc14bSjoerg void __insert_c(void* __c, _InsertConstruct* __fn); 236*4d6fc14bSjoerg void __erase_c(void* __c); 237*4d6fc14bSjoerg 238*4d6fc14bSjoerg void __insert_ic(void* __i, const void* __c); 239*4d6fc14bSjoerg void __iterator_copy(void* __i, const void* __i0); 240*4d6fc14bSjoerg void __erase_i(void* __i); 241*4d6fc14bSjoerg 242*4d6fc14bSjoerg void* __find_c_from_i(void* __i) const; 243*4d6fc14bSjoerg void __invalidate_all(void* __c); 244*4d6fc14bSjoerg __c_node* __find_c_and_lock(void* __c) const; 245*4d6fc14bSjoerg __c_node* __find_c(void* __c) const; 246*4d6fc14bSjoerg void unlock() const; 247*4d6fc14bSjoerg 248*4d6fc14bSjoerg void swap(void* __c1, void* __c2); 249*4d6fc14bSjoerg 250*4d6fc14bSjoerg 251*4d6fc14bSjoerg bool __dereferenceable(const void* __i) const; 252*4d6fc14bSjoerg bool __decrementable(const void* __i) const; 253*4d6fc14bSjoerg bool __addable(const void* __i, ptrdiff_t __n) const; 254*4d6fc14bSjoerg bool __subscriptable(const void* __i, ptrdiff_t __n) const; 255*4d6fc14bSjoerg bool __less_than_comparable(const void* __i, const void* __j) const; 256*4d6fc14bSjoergprivate: 257*4d6fc14bSjoerg _LIBCPP_HIDDEN 258*4d6fc14bSjoerg __i_node* __insert_iterator(void* __i); 259*4d6fc14bSjoerg _LIBCPP_HIDDEN 260*4d6fc14bSjoerg __i_node* __find_iterator(const void* __i) const; 261*4d6fc14bSjoerg 262*4d6fc14bSjoerg friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db(); 263*4d6fc14bSjoerg}; 264*4d6fc14bSjoerg 265*4d6fc14bSjoerg_LIBCPP_FUNC_VIS __libcpp_db* __get_db(); 266*4d6fc14bSjoerg_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db(); 267*4d6fc14bSjoerg 268*4d6fc14bSjoerg 269*4d6fc14bSjoerg#endif // _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY) 270*4d6fc14bSjoerg 271*4d6fc14bSjoerg_LIBCPP_END_NAMESPACE_STD 272*4d6fc14bSjoerg 273*4d6fc14bSjoerg#endif // _LIBCPP_DEBUG_H 274