Home | History | Annotate | Download | only in include
      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 
     11 #ifndef _LIBCPP_DEBUG_H
     12 #define _LIBCPP_DEBUG_H
     13 
     14 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
     15 #pragma GCC system_header
     16 #endif
     17 
     18 #if _LIBCPP_DEBUG_LEVEL >= 1
     19 
     20 #   include <cstdlib>
     21 #   include <cstdio>
     22 #   include <cstddef>
     23 #   ifndef _LIBCPP_ASSERT
     24 #      define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
     25 #   endif
     26 
     27 #endif
     28 
     29 #if _LIBCPP_DEBUG_LEVEL >= 2
     30 
     31 _LIBCPP_BEGIN_NAMESPACE_STD
     32 
     33 struct _LIBCPP_TYPE_VIS __c_node;
     34 
     35 struct _LIBCPP_TYPE_VIS __i_node
     36 {
     37     void* __i_;
     38     __i_node* __next_;
     39     __c_node* __c_;
     40 
     41 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
     42     __i_node(const __i_node&) = delete;
     43     __i_node& operator=(const __i_node&) = delete;
     44 #else
     45 private:
     46     __i_node(const __i_node&);
     47     __i_node& operator=(const __i_node&);
     48 public:
     49 #endif
     50     _LIBCPP_INLINE_VISIBILITY
     51     __i_node(void* __i, __i_node* __next, __c_node* __c)
     52         : __i_(__i), __next_(__next), __c_(__c) {}
     53     ~__i_node();
     54 };
     55 
     56 struct _LIBCPP_TYPE_VIS __c_node
     57 {
     58     void* __c_;
     59     __c_node* __next_;
     60     __i_node** beg_;
     61     __i_node** end_;
     62     __i_node** cap_;
     63 
     64 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
     65     __c_node(const __c_node&) = delete;
     66     __c_node& operator=(const __c_node&) = delete;
     67 #else
     68 private:
     69     __c_node(const __c_node&);
     70     __c_node& operator=(const __c_node&);
     71 public:
     72 #endif
     73     _LIBCPP_INLINE_VISIBILITY
     74     __c_node(void* __c, __c_node* __next)
     75         : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
     76     virtual ~__c_node();
     77 
     78     virtual bool __dereferenceable(const void*) const = 0;
     79     virtual bool __decrementable(const void*) const = 0;
     80     virtual bool __addable(const void*, ptrdiff_t) const = 0;
     81     virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
     82 
     83     void __add(__i_node* __i);
     84     _LIBCPP_HIDDEN void __remove(__i_node* __i);
     85 };
     86 
     87 template <class _Cont>
     88 struct _C_node
     89     : public __c_node
     90 {
     91     _C_node(void* __c, __c_node* __n)
     92         : __c_node(__c, __n) {}
     93 
     94     virtual bool __dereferenceable(const void*) const;
     95     virtual bool __decrementable(const void*) const;
     96     virtual bool __addable(const void*, ptrdiff_t) const;
     97     virtual bool __subscriptable(const void*, ptrdiff_t) const;
     98 };
     99 
    100 template <class _Cont>
    101 bool
    102 _C_node<_Cont>::__dereferenceable(const void* __i) const
    103 {
    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->__dereferenceable(__j);
    108 }
    109 
    110 template <class _Cont>
    111 bool
    112 _C_node<_Cont>::__decrementable(const void* __i) const
    113 {
    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->__decrementable(__j);
    118 }
    119 
    120 template <class _Cont>
    121 bool
    122 _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
    123 {
    124     typedef typename _Cont::const_iterator iterator;
    125     const iterator* __j = static_cast<const iterator*>(__i);
    126     _Cont* _Cp = static_cast<_Cont*>(__c_);
    127     return _Cp->__addable(__j, __n);
    128 }
    129 
    130 template <class _Cont>
    131 bool
    132 _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
    133 {
    134     typedef typename _Cont::const_iterator iterator;
    135     const iterator* __j = static_cast<const iterator*>(__i);
    136     _Cont* _Cp = static_cast<_Cont*>(__c_);
    137     return _Cp->__subscriptable(__j, __n);
    138 }
    139 
    140 class _LIBCPP_TYPE_VIS __libcpp_db
    141 {
    142     __c_node** __cbeg_;
    143     __c_node** __cend_;
    144     size_t   __csz_;
    145     __i_node** __ibeg_;
    146     __i_node** __iend_;
    147     size_t   __isz_;
    148 
    149     __libcpp_db();
    150 public:
    151 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
    152     __libcpp_db(const __libcpp_db&) = delete;
    153     __libcpp_db& operator=(const __libcpp_db&) = delete;
    154 #else
    155 private:
    156     __libcpp_db(const __libcpp_db&);
    157     __libcpp_db& operator=(const __libcpp_db&);
    158 public:
    159 #endif
    160     ~__libcpp_db();
    161 
    162     class __db_c_iterator;
    163     class __db_c_const_iterator;
    164     class __db_i_iterator;
    165     class __db_i_const_iterator;
    166 
    167     __db_c_const_iterator __c_end() const;
    168     __db_i_const_iterator __i_end() const;
    169 
    170     template <class _Cont>
    171     _LIBCPP_INLINE_VISIBILITY
    172     void __insert_c(_Cont* __c)
    173     {
    174         __c_node* __n = __insert_c(static_cast<void*>(__c));
    175         ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
    176     }
    177 
    178     void __insert_i(void* __i);
    179     __c_node* __insert_c(void* __c);
    180     void __erase_c(void* __c);
    181 
    182     void __insert_ic(void* __i, const void* __c);
    183     void __iterator_copy(void* __i, const void* __i0);
    184     void __erase_i(void* __i);
    185 
    186     void* __find_c_from_i(void* __i) const;
    187     void __invalidate_all(void* __c);
    188     __c_node* __find_c_and_lock(void* __c) const;
    189     __c_node* __find_c(void* __c) const;
    190     void unlock() const;
    191 
    192     void swap(void* __c1, void* __c2);
    193 
    194 
    195     bool __dereferenceable(const void* __i) const;
    196     bool __decrementable(const void* __i) const;
    197     bool __addable(const void* __i, ptrdiff_t __n) const;
    198     bool __subscriptable(const void* __i, ptrdiff_t __n) const;
    199     bool __less_than_comparable(const void* __i, const void* __j) const;
    200 private:
    201     _LIBCPP_HIDDEN
    202     __i_node* __insert_iterator(void* __i);
    203     _LIBCPP_HIDDEN
    204     __i_node* __find_iterator(const void* __i) const;
    205 
    206     friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
    207 };
    208 
    209 _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
    210 _LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
    211 
    212 
    213 _LIBCPP_END_NAMESPACE_STD
    214 
    215 #endif
    216 
    217 #endif  // _LIBCPP_DEBUG_H
    218 
    219