]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.1.0/include/debug/macros.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.1.0 / include / debug / macros.h
1 // Debugging support implementation -*- C++ -*-
2
3 // Copyright (C) 2003, 2005
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 #ifndef _GLIBCXX_DEBUG_MACROS_H
32 #define _GLIBCXX_DEBUG_MACROS_H 1
33
34 /**
35  * Macros used by the implementation to verify certain
36  * properties. These macros may only be used directly by the debug
37  * wrappers. Note that these are macros (instead of the more obviously
38  * "correct" choice of making them functions) because we need line and
39  * file information at the call site, to minimize the distance between
40  * the user error and where the error is reported.
41  *
42  */
43 #define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage)                 \
44   do {                                                                  \
45     if (! (_Condition))                                                 \
46       ::__gnu_debug::_Error_formatter::_M_at(__FILE__, __LINE__)        \
47           ._ErrorMessage._M_error();                                    \
48   } while (false)
49
50 // Verify that [_First, _Last) forms a valid iterator range.
51 #define __glibcxx_check_valid_range(_First,_Last)                       \
52 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__valid_range(_First, _Last),      \
53                       _M_message(::__gnu_debug::__msg_valid_range)      \
54                       ._M_iterator(_First, #_First)                     \
55                       ._M_iterator(_Last, #_Last))
56
57 /** Verify that we can insert into *this with the iterator _Position.
58  *  Insertion into a container at a specific position requires that
59  *  the iterator be nonsingular (i.e., either dereferenceable or
60  *  past-the-end) and that it reference the sequence we are inserting
61  *  into. Note that this macro is only valid when the container is a
62  *  _Safe_sequence and the iterator is a _Safe_iterator.
63 */
64 #define __glibcxx_check_insert(_Position)                               \
65 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),                         \
66                       _M_message(::__gnu_debug::__msg_insert_singular) \
67                       ._M_sequence(*this, "this")                       \
68                       ._M_iterator(_Position, #_Position));             \
69 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                   \
70                       _M_message(::__gnu_debug::__msg_insert_different) \
71                       ._M_sequence(*this, "this")                       \
72                       ._M_iterator(_Position, #_Position))
73
74 /** Verify that we can insert the values in the iterator range
75  *  [_First, _Last) into *this with the iterator _Position.  Insertion
76  *  into a container at a specific position requires that the iterator
77  *  be nonsingular (i.e., either dereferenceable or past-the-end),
78  *  that it reference the sequence we are inserting into, and that the
79  *  iterator range [_First, Last) is a valid (possibly empty)
80  *  range. Note that this macro is only valid when the container is a
81  *  _Safe_sequence and the iterator is a _Safe_iterator.
82  *
83  *  @tbd We would like to be able to check for noninterference of
84  *  _Position and the range [_First, _Last), but that can't (in
85  *  general) be done.
86 */
87 #define __glibcxx_check_insert_range(_Position,_First,_Last)            \
88 __glibcxx_check_valid_range(_First,_Last);                              \
89 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),                         \
90                       _M_message(::__gnu_debug::__msg_insert_singular) \
91                       ._M_sequence(*this, "this")                       \
92                       ._M_iterator(_Position, #_Position));             \
93 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                   \
94                       _M_message(::__gnu_debug::__msg_insert_different) \
95                       ._M_sequence(*this, "this")                       \
96                       ._M_iterator(_Position, #_Position))
97
98 /** Verify that we can erase the element referenced by the iterator
99  * _Position. We can erase the element if the _Position iterator is
100  * dereferenceable and references this sequence.
101 */
102 #define __glibcxx_check_erase(_Position)                                \
103 _GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(),                   \
104                       _M_message(::__gnu_debug::__msg_erase_bad)        \
105                       ._M_sequence(*this, "this")                       \
106                       ._M_iterator(_Position, #_Position));             \
107 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                   \
108                       _M_message(::__gnu_debug::__msg_erase_different) \
109                       ._M_sequence(*this, "this")                       \
110                       ._M_iterator(_Position, #_Position))
111
112 /** Verify that we can erase the elements in the iterator range
113  *  [_First, _Last). We can erase the elements if [_First, _Last) is a
114  *  valid iterator range within this sequence.
115 */
116 #define __glibcxx_check_erase_range(_First,_Last)                       \
117 __glibcxx_check_valid_range(_First,_Last);                              \
118 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),                      \
119                       _M_message(::__gnu_debug::__msg_erase_different) \
120                       ._M_sequence(*this, "this")                       \
121                       ._M_iterator(_First, #_First)                     \
122                       ._M_iterator(_Last, #_Last))
123
124 // Verify that the subscript _N is less than the container's size.
125 #define __glibcxx_check_subscript(_N)                                   \
126 _GLIBCXX_DEBUG_VERIFY(_N < this->size(),                                \
127                       _M_message(::__gnu_debug::__msg_subscript_oob) \
128                       ._M_sequence(*this, "this")                       \
129                       ._M_integer(_N, #_N)                              \
130                       ._M_integer(this->size(), "size"))
131
132 // Verify that the container is nonempty
133 #define __glibcxx_check_nonempty()                                      \
134 _GLIBCXX_DEBUG_VERIFY(! this->empty(),                                  \
135                       _M_message(::__gnu_debug::__msg_empty)    \
136                       ._M_sequence(*this, "this"))
137
138 // Verify that the < operator for elements in the sequence is a
139 // StrictWeakOrdering by checking that it is irreflexive.
140 #define __glibcxx_check_strict_weak_ordering(_First,_Last)      \
141 _GLIBCXX_DEBUG_ASSERT(_First == _Last || !(*_First < *_First))
142
143 // Verify that the predicate is StrictWeakOrdering by checking that it
144 // is irreflexive.
145 #define __glibcxx_check_strict_weak_ordering_pred(_First,_Last,_Pred)   \
146 _GLIBCXX_DEBUG_ASSERT(_First == _Last || !_Pred(*_First, *_First))
147
148
149 // Verify that the iterator range [_First, _Last) is sorted
150 #define __glibcxx_check_sorted(_First,_Last)                            \
151 __glibcxx_check_valid_range(_First,_Last);                              \
152 __glibcxx_check_strict_weak_ordering(_First,_Last);                     \
153 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__check_sorted(_First, _Last),     \
154                       _M_message(::__gnu_debug::__msg_unsorted) \
155                       ._M_iterator(_First, #_First)                     \
156                       ._M_iterator(_Last, #_Last))
157
158 /** Verify that the iterator range [_First, _Last) is sorted by the
159     predicate _Pred. */
160 #define __glibcxx_check_sorted_pred(_First,_Last,_Pred)                 \
161 __glibcxx_check_valid_range(_First,_Last);                              \
162 __glibcxx_check_strict_weak_ordering_pred(_First,_Last,_Pred);          \
163 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__check_sorted(_First, _Last, _Pred), \
164                       _M_message(::__gnu_debug::__msg_unsorted_pred) \
165                       ._M_iterator(_First, #_First)                     \
166                       ._M_iterator(_Last, #_Last)                       \
167                       ._M_string(#_Pred))
168
169 /** Verify that the iterator range [_First, _Last) is partitioned
170     w.r.t. the value _Value. */
171 #define __glibcxx_check_partitioned(_First,_Last,_Value)                \
172 __glibcxx_check_valid_range(_First,_Last);                              \
173 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__check_partitioned(_First, _Last, \
174                                                          _Value),       \
175                       _M_message(::__gnu_debug::__msg_unpartitioned) \
176                       ._M_iterator(_First, #_First)                     \
177                       ._M_iterator(_Last, #_Last)                       \
178                       ._M_string(#_Value))
179
180 /** Verify that the iterator range [_First, _Last) is partitioned
181     w.r.t. the value _Value and predicate _Pred. */
182 #define __glibcxx_check_partitioned_pred(_First,_Last,_Value,_Pred)     \
183 __glibcxx_check_valid_range(_First,_Last);                              \
184 _GLIBCXX_DEBUG_VERIFY(::__gnu_debug::__check_partitioned(_First, _Last, \
185                                                          _Value, _Pred), \
186                       _M_message(::__gnu_debug::__msg_unpartitioned_pred) \
187                       ._M_iterator(_First, #_First)                     \
188                       ._M_iterator(_Last, #_Last)                       \
189                       ._M_string(#_Pred)                                \
190                       ._M_string(#_Value))
191
192 // Verify that the iterator range [_First, _Last) is a heap
193 #define __glibcxx_check_heap(_First,_Last)                              \
194 __glibcxx_check_valid_range(_First,_Last);                              \
195 _GLIBCXX_DEBUG_VERIFY(::std::__is_heap(_First, _Last),          \
196                       _M_message(::__gnu_debug::__msg_not_heap) \
197                       ._M_iterator(_First, #_First)                     \
198                       ._M_iterator(_Last, #_Last))
199
200 /** Verify that the iterator range [_First, _Last) is a heap
201     w.r.t. the predicate _Pred. */
202 #define __glibcxx_check_heap_pred(_First,_Last,_Pred)                   \
203 __glibcxx_check_valid_range(_First,_Last);                              \
204 _GLIBCXX_DEBUG_VERIFY(::std::__is_heap(_First, _Last, _Pred),           \
205                       _M_message(::__gnu_debug::__msg_not_heap_pred) \
206                       ._M_iterator(_First, #_First)                     \
207                       ._M_iterator(_Last, #_Last)                       \
208                       ._M_string(#_Pred))
209
210 #ifdef _GLIBCXX_DEBUG_PEDANTIC
211 #  define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0)
212 #  define __glibcxx_check_string_len(_String,_Len) \
213        _GLIBCXX_DEBUG_ASSERT(_String != 0 || _Len == 0)
214 #else
215 #  define __glibcxx_check_string(_String)
216 #  define __glibcxx_check_string_len(_String,_Len)
217 #endif
218
219 #endif