__debug 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // -*- C++ -*-
  2. //===--------------------------- __debug ----------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_DEBUG_H
  11. #define _LIBCPP_DEBUG_H
  12. // Not supported.
  13. #include <__config>
  14. #if !defined(_LIBCPP_SGX_CONFIG)
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. #pragma GCC system_header
  17. #endif
  18. #if _LIBCPP_DEBUG_LEVEL >= 1
  19. # include <cstdlib>
  20. # include <cstdio>
  21. # include <cstddef>
  22. # ifndef _LIBCPP_ASSERT
  23. # define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::fprintf(stderr, "%s\n", m), _VSTD::abort()))
  24. # endif
  25. #endif
  26. #ifndef _LIBCPP_ASSERT
  27. # define _LIBCPP_ASSERT(x, m) ((void)0)
  28. #endif
  29. #if _LIBCPP_DEBUG_LEVEL >= 2
  30. _LIBCPP_BEGIN_NAMESPACE_STD
  31. struct _LIBCPP_TYPE_VIS __c_node;
  32. struct _LIBCPP_TYPE_VIS __i_node
  33. {
  34. void* __i_;
  35. __i_node* __next_;
  36. __c_node* __c_;
  37. #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
  38. __i_node(const __i_node&) = delete;
  39. __i_node& operator=(const __i_node&) = delete;
  40. #else
  41. private:
  42. __i_node(const __i_node&);
  43. __i_node& operator=(const __i_node&);
  44. public:
  45. #endif
  46. _LIBCPP_INLINE_VISIBILITY
  47. __i_node(void* __i, __i_node* __next, __c_node* __c)
  48. : __i_(__i), __next_(__next), __c_(__c) {}
  49. ~__i_node();
  50. };
  51. struct _LIBCPP_TYPE_VIS __c_node
  52. {
  53. void* __c_;
  54. __c_node* __next_;
  55. __i_node** beg_;
  56. __i_node** end_;
  57. __i_node** cap_;
  58. #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
  59. __c_node(const __c_node&) = delete;
  60. __c_node& operator=(const __c_node&) = delete;
  61. #else
  62. private:
  63. __c_node(const __c_node&);
  64. __c_node& operator=(const __c_node&);
  65. public:
  66. #endif
  67. _LIBCPP_INLINE_VISIBILITY
  68. __c_node(void* __c, __c_node* __next)
  69. : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
  70. virtual ~__c_node();
  71. virtual bool __dereferenceable(const void*) const = 0;
  72. virtual bool __decrementable(const void*) const = 0;
  73. virtual bool __addable(const void*, ptrdiff_t) const = 0;
  74. virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
  75. void __add(__i_node* __i);
  76. _LIBCPP_HIDDEN void __remove(__i_node* __i);
  77. };
  78. template <class _Cont>
  79. struct _C_node
  80. : public __c_node
  81. {
  82. _C_node(void* __c, __c_node* __n)
  83. : __c_node(__c, __n) {}
  84. virtual bool __dereferenceable(const void*) const;
  85. virtual bool __decrementable(const void*) const;
  86. virtual bool __addable(const void*, ptrdiff_t) const;
  87. virtual bool __subscriptable(const void*, ptrdiff_t) const;
  88. };
  89. template <class _Cont>
  90. bool
  91. _C_node<_Cont>::__dereferenceable(const void* __i) const
  92. {
  93. typedef typename _Cont::const_iterator iterator;
  94. const iterator* __j = static_cast<const iterator*>(__i);
  95. _Cont* _Cp = static_cast<_Cont*>(__c_);
  96. return _Cp->__dereferenceable(__j);
  97. }
  98. template <class _Cont>
  99. bool
  100. _C_node<_Cont>::__decrementable(const void* __i) const
  101. {
  102. typedef typename _Cont::const_iterator iterator;
  103. const iterator* __j = static_cast<const iterator*>(__i);
  104. _Cont* _Cp = static_cast<_Cont*>(__c_);
  105. return _Cp->__decrementable(__j);
  106. }
  107. template <class _Cont>
  108. bool
  109. _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
  110. {
  111. typedef typename _Cont::const_iterator iterator;
  112. const iterator* __j = static_cast<const iterator*>(__i);
  113. _Cont* _Cp = static_cast<_Cont*>(__c_);
  114. return _Cp->__addable(__j, __n);
  115. }
  116. template <class _Cont>
  117. bool
  118. _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
  119. {
  120. typedef typename _Cont::const_iterator iterator;
  121. const iterator* __j = static_cast<const iterator*>(__i);
  122. _Cont* _Cp = static_cast<_Cont*>(__c_);
  123. return _Cp->__subscriptable(__j, __n);
  124. }
  125. class _LIBCPP_TYPE_VIS __libcpp_db
  126. {
  127. __c_node** __cbeg_;
  128. __c_node** __cend_;
  129. size_t __csz_;
  130. __i_node** __ibeg_;
  131. __i_node** __iend_;
  132. size_t __isz_;
  133. __libcpp_db();
  134. public:
  135. #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
  136. __libcpp_db(const __libcpp_db&) = delete;
  137. __libcpp_db& operator=(const __libcpp_db&) = delete;
  138. #else
  139. private:
  140. __libcpp_db(const __libcpp_db&);
  141. __libcpp_db& operator=(const __libcpp_db&);
  142. public:
  143. #endif
  144. ~__libcpp_db();
  145. class __db_c_iterator;
  146. class __db_c_const_iterator;
  147. class __db_i_iterator;
  148. class __db_i_const_iterator;
  149. __db_c_const_iterator __c_end() const;
  150. __db_i_const_iterator __i_end() const;
  151. template <class _Cont>
  152. _LIBCPP_INLINE_VISIBILITY
  153. void __insert_c(_Cont* __c)
  154. {
  155. __c_node* __n = __insert_c(static_cast<void*>(__c));
  156. ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
  157. }
  158. void __insert_i(void* __i);
  159. __c_node* __insert_c(void* __c);
  160. void __erase_c(void* __c);
  161. void __insert_ic(void* __i, const void* __c);
  162. void __iterator_copy(void* __i, const void* __i0);
  163. void __erase_i(void* __i);
  164. void* __find_c_from_i(void* __i) const;
  165. void __invalidate_all(void* __c);
  166. __c_node* __find_c_and_lock(void* __c) const;
  167. __c_node* __find_c(void* __c) const;
  168. void unlock() const;
  169. void swap(void* __c1, void* __c2);
  170. bool __dereferenceable(const void* __i) const;
  171. bool __decrementable(const void* __i) const;
  172. bool __addable(const void* __i, ptrdiff_t __n) const;
  173. bool __subscriptable(const void* __i, ptrdiff_t __n) const;
  174. bool __less_than_comparable(const void* __i, const void* __j) const;
  175. private:
  176. _LIBCPP_HIDDEN
  177. __i_node* __insert_iterator(void* __i);
  178. _LIBCPP_HIDDEN
  179. __i_node* __find_iterator(const void* __i) const;
  180. friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
  181. };
  182. _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
  183. _LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
  184. _LIBCPP_END_NAMESPACE_STD
  185. #endif
  186. #endif // !defined(_LIBCPP_SGX_CONFIG)
  187. #endif // _LIBCPP_DEBUG_H