2 //===--------------------------- __debug ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_DEBUG_H
12 #define _LIBCPP_DEBUG_H
14 #if _LIBCPP_DEBUG_LEVEL >= 1
19 # define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
23 #if _LIBCPP_DEBUG_LEVEL >= 2
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 struct _LIBCPP_VISIBLE __c_node;
29 struct _LIBCPP_VISIBLE __i_node
35 __i_node(const __i_node&) = delete;
36 __i_node& operator=(const __i_node&) = delete;
37 _LIBCPP_INLINE_VISIBILITY
38 __i_node(void* __i, __i_node* __next, __c_node* __c)
39 : __i_(__i), __next_(__next), __c_(__c) {}
43 struct _LIBCPP_VISIBLE __c_node
51 __c_node(const __c_node&) = delete;
52 __c_node& operator=(const __c_node&) = delete;
53 _LIBCPP_INLINE_VISIBILITY
54 __c_node(void* __c, __c_node* __next)
55 : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
58 virtual bool __dereferenceable(const void*) const = 0;
59 virtual bool __decrementable(const void*) const = 0;
60 virtual bool __addable(const void*, ptrdiff_t) const = 0;
61 virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
63 void __add(__i_node* __i);
64 _LIBCPP_HIDDEN void __remove(__i_node* __i);
67 template <class _Cont>
71 _C_node(void* __c, __c_node* __n)
72 : __c_node(__c, __n) {}
74 virtual bool __dereferenceable(const void*) const;
75 virtual bool __decrementable(const void*) const;
76 virtual bool __addable(const void*, ptrdiff_t) const;
77 virtual bool __subscriptable(const void*, ptrdiff_t) const;
80 template <class _Cont>
82 _C_node<_Cont>::__dereferenceable(const void* __i) const
84 typedef typename _Cont::const_iterator iterator;
85 const iterator* __j = static_cast<const iterator*>(__i);
86 _Cont* _Cp = static_cast<_Cont*>(__c_);
87 return _Cp->__dereferenceable(__j);
90 template <class _Cont>
92 _C_node<_Cont>::__decrementable(const void* __i) const
94 typedef typename _Cont::const_iterator iterator;
95 const iterator* __j = static_cast<const iterator*>(__i);
96 _Cont* _Cp = static_cast<_Cont*>(__c_);
97 return _Cp->__decrementable(__j);
100 template <class _Cont>
102 _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
104 typedef typename _Cont::const_iterator iterator;
105 const iterator* __j = static_cast<const iterator*>(__i);
106 _Cont* _Cp = static_cast<_Cont*>(__c_);
107 return _Cp->__addable(__j, __n);
110 template <class _Cont>
112 _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
114 typedef typename _Cont::const_iterator iterator;
115 const iterator* __j = static_cast<const iterator*>(__i);
116 _Cont* _Cp = static_cast<_Cont*>(__c_);
117 return _Cp->__subscriptable(__j, __n);
120 class _LIBCPP_VISIBLE __libcpp_db
131 __libcpp_db(const __libcpp_db&) = delete;
132 __libcpp_db& operator=(const __libcpp_db&) = delete;
135 class __db_c_iterator;
136 class __db_c_const_iterator;
137 class __db_i_iterator;
138 class __db_i_const_iterator;
140 __db_c_const_iterator __c_end() const;
141 __db_i_const_iterator __i_end() const;
143 template <class _Cont>
144 _LIBCPP_INLINE_VISIBILITY
145 void __insert_c(_Cont* __c)
147 __c_node* __n = __insert_c(static_cast<void*>(__c));
148 ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
151 void __insert_i(void* __i);
152 __c_node* __insert_c(void* __c);
153 void __erase_c(void* __c);
155 void __insert_ic(void* __i, const void* __c);
156 void __iterator_copy(void* __i, const void* __i0);
157 void __erase_i(void* __i);
159 void* __find_c_from_i(void* __i) const;
160 void __invalidate_all(void* __c);
161 __c_node* __find_c_and_lock(void* __c) const;
162 __c_node* __find_c(void* __c) const;
165 void swap(void* __c1, void* __c2);
168 bool __dereferenceable(const void* __i) const;
169 bool __decrementable(const void* __i) const;
170 bool __addable(const void* __i, ptrdiff_t __n) const;
171 bool __subscriptable(const void* __i, ptrdiff_t __n) const;
172 bool __comparable(const void* __i, const void* __j) const;
175 __i_node* __insert_iterator(void* __i);
177 __i_node* __find_iterator(const void* __i) const;
179 friend _LIBCPP_VISIBLE __libcpp_db* __get_db();
182 _LIBCPP_VISIBLE __libcpp_db* __get_db();
183 _LIBCPP_VISIBLE const __libcpp_db* __get_const_db();
186 _LIBCPP_END_NAMESPACE_STD
190 #endif // _LIBCPP_DEBUG_H