]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/debug/macros.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / debug / macros.h
1 // Debugging support implementation -*- C++ -*-
2
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
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 /** @file debug/macros.h
32  *  This file is a GNU debug extension to the Standard C++ Library.
33  */
34
35 #ifndef _GLIBCXX_DEBUG_MACROS_H
36 #define _GLIBCXX_DEBUG_MACROS_H 1
37
38 /**
39  * Macros used by the implementation to verify certain
40  * properties. These macros may only be used directly by the debug
41  * wrappers. Note that these are macros (instead of the more obviously
42  * "correct" choice of making them functions) because we need line and
43  * file information at the call site, to minimize the distance between
44  * the user error and where the error is reported.
45  *
46  */
47 #define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage)                 \
48   do                                                                    \
49   {                                                                     \
50     if (! (_Condition))                                                 \
51       __gnu_debug::_Error_formatter::_M_at(__FILE__, __LINE__)          \
52           ._ErrorMessage._M_error();                                    \
53   } while (false)
54
55 // Verify that [_First, _Last) forms a valid iterator range.
56 #define __glibcxx_check_valid_range(_First,_Last)                       \
57 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last),        \
58                       _M_message(__gnu_debug::__msg_valid_range)        \
59                       ._M_iterator(_First, #_First)                     \
60                       ._M_iterator(_Last, #_Last))
61
62 /** Verify that we can insert into *this with the iterator _Position.
63  *  Insertion into a container at a specific position requires that
64  *  the iterator be nonsingular (i.e., either dereferenceable or
65  *  past-the-end) and that it reference the sequence we are inserting
66  *  into. Note that this macro is only valid when the container is a
67  *  _Safe_sequence and the iterator is a _Safe_iterator.
68 */
69 #define __glibcxx_check_insert(_Position)                               \
70 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),                         \
71                       _M_message(__gnu_debug::__msg_insert_singular) \
72                       ._M_sequence(*this, "this")                       \
73                       ._M_iterator(_Position, #_Position));             \
74 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                   \
75                       _M_message(__gnu_debug::__msg_insert_different) \
76                       ._M_sequence(*this, "this")                       \
77                       ._M_iterator(_Position, #_Position))
78
79 /** Verify that we can insert the values in the iterator range
80  *  [_First, _Last) into *this with the iterator _Position.  Insertion
81  *  into a container at a specific position requires that the iterator
82  *  be nonsingular (i.e., either dereferenceable or past-the-end),
83  *  that it reference the sequence we are inserting into, and that the
84  *  iterator range [_First, Last) is a valid (possibly empty)
85  *  range. Note that this macro is only valid when the container is a
86  *  _Safe_sequence and the iterator is a _Safe_iterator.
87  *
88  *  @tbd We would like to be able to check for noninterference of
89  *  _Position and the range [_First, _Last), but that can't (in
90  *  general) be done.
91 */
92 #define __glibcxx_check_insert_range(_Position,_First,_Last)            \
93 __glibcxx_check_valid_range(_First,_Last);                              \
94 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),                         \
95                       _M_message(__gnu_debug::__msg_insert_singular)    \
96                       ._M_sequence(*this, "this")                       \
97                       ._M_iterator(_Position, #_Position));             \
98 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                   \
99                       _M_message(__gnu_debug::__msg_insert_different)   \
100                       ._M_sequence(*this, "this")                       \
101                       ._M_iterator(_Position, #_Position))
102
103 /** Verify that we can erase the element referenced by the iterator
104  * _Position. We can erase the element if the _Position iterator is
105  * dereferenceable and references this sequence.
106 */
107 #define __glibcxx_check_erase(_Position)                                \
108 _GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(),                   \
109                       _M_message(__gnu_debug::__msg_erase_bad)          \
110                       ._M_sequence(*this, "this")                       \
111                       ._M_iterator(_Position, #_Position));             \
112 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                   \
113                       _M_message(__gnu_debug::__msg_erase_different)    \
114                       ._M_sequence(*this, "this")                       \
115                       ._M_iterator(_Position, #_Position))
116
117 /** Verify that we can erase the elements in the iterator range
118  *  [_First, _Last). We can erase the elements if [_First, _Last) is a
119  *  valid iterator range within this sequence.
120 */
121 #define __glibcxx_check_erase_range(_First,_Last)                       \
122 __glibcxx_check_valid_range(_First,_Last);                              \
123 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),                      \
124                       _M_message(__gnu_debug::__msg_erase_different)    \
125                       ._M_sequence(*this, "this")                       \
126                       ._M_iterator(_First, #_First)                     \
127                       ._M_iterator(_Last, #_Last))
128
129 // Verify that the subscript _N is less than the container's size.
130 #define __glibcxx_check_subscript(_N)                                   \
131 _GLIBCXX_DEBUG_VERIFY(_N < this->size(),                                \
132                       _M_message(__gnu_debug::__msg_subscript_oob)      \
133                       ._M_sequence(*this, "this")                       \
134                       ._M_integer(_N, #_N)                              \
135                       ._M_integer(this->size(), "size"))
136
137 // Verify that the container is nonempty
138 #define __glibcxx_check_nonempty()                                      \
139 _GLIBCXX_DEBUG_VERIFY(! this->empty(),                                  \
140                       _M_message(__gnu_debug::__msg_empty)              \
141                       ._M_sequence(*this, "this"))
142
143 // Verify that the iterator range [_First, _Last) is sorted
144 #define __glibcxx_check_sorted(_First,_Last)                            \
145 __glibcxx_check_valid_range(_First,_Last);                              \
146 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last),       \
147                       _M_message(__gnu_debug::__msg_unsorted)           \
148                       ._M_iterator(_First, #_First)                     \
149                       ._M_iterator(_Last, #_Last))
150
151 /** Verify that the iterator range [_First, _Last) is sorted by the
152     predicate _Pred. */
153 #define __glibcxx_check_sorted_pred(_First,_Last,_Pred)                 \
154 __glibcxx_check_valid_range(_First,_Last);                              \
155 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last, _Pred), \
156                       _M_message(__gnu_debug::__msg_unsorted_pred)      \
157                       ._M_iterator(_First, #_First)                     \
158                       ._M_iterator(_Last, #_Last)                       \
159                       ._M_string(#_Pred))
160
161 // Special variant for std::merge, std::includes, std::set_*
162 #define __glibcxx_check_sorted_set(_First1,_Last1,_First2)              \
163 __glibcxx_check_valid_range(_First1,_Last1);                            \
164 _GLIBCXX_DEBUG_VERIFY(                                                  \
165   __gnu_debug::__check_sorted_set(_First1, _Last1, _First2),            \
166   _M_message(__gnu_debug::__msg_unsorted)                               \
167   ._M_iterator(_First1, #_First1)                                       \
168   ._M_iterator(_Last1, #_Last1))
169
170 // Likewise with a _Pred.
171 #define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred)   \
172 __glibcxx_check_valid_range(_First1,_Last1);                            \
173 _GLIBCXX_DEBUG_VERIFY(                                                  \
174   __gnu_debug::__check_sorted_set(_First1, _Last1, _First2, _Pred),     \
175   _M_message(__gnu_debug::__msg_unsorted_pred)                          \
176   ._M_iterator(_First1, #_First1)                                       \
177   ._M_iterator(_Last1, #_Last1)                                         \
178   ._M_string(#_Pred))
179
180 /** Verify that the iterator range [_First, _Last) is partitioned
181     w.r.t. the value _Value. */
182 #define __glibcxx_check_partitioned_lower(_First,_Last,_Value)          \
183 __glibcxx_check_valid_range(_First,_Last);                              \
184 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
185                                                             _Value),    \
186                       _M_message(__gnu_debug::__msg_unpartitioned)      \
187                       ._M_iterator(_First, #_First)                     \
188                       ._M_iterator(_Last, #_Last)                       \
189                       ._M_string(#_Value))
190
191 #define __glibcxx_check_partitioned_upper(_First,_Last,_Value)          \
192 __glibcxx_check_valid_range(_First,_Last);                              \
193 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
194                                                             _Value),    \
195                       _M_message(__gnu_debug::__msg_unpartitioned)      \
196                       ._M_iterator(_First, #_First)                     \
197                       ._M_iterator(_Last, #_Last)                       \
198                       ._M_string(#_Value))
199
200 /** Verify that the iterator range [_First, _Last) is partitioned
201     w.r.t. the value _Value and predicate _Pred. */
202 #define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
203 __glibcxx_check_valid_range(_First,_Last);                              \
204 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
205                                                          _Value, _Pred), \
206                       _M_message(__gnu_debug::__msg_unpartitioned_pred) \
207                       ._M_iterator(_First, #_First)                     \
208                       ._M_iterator(_Last, #_Last)                       \
209                       ._M_string(#_Pred)                                \
210                       ._M_string(#_Value))
211
212 /** Verify that the iterator range [_First, _Last) is partitioned
213     w.r.t. the value _Value and predicate _Pred. */
214 #define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
215 __glibcxx_check_valid_range(_First,_Last);                              \
216 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
217                                                          _Value, _Pred), \
218                       _M_message(__gnu_debug::__msg_unpartitioned_pred) \
219                       ._M_iterator(_First, #_First)                     \
220                       ._M_iterator(_Last, #_Last)                       \
221                       ._M_string(#_Pred)                                \
222                       ._M_string(#_Value))
223
224 // Verify that the iterator range [_First, _Last) is a heap
225 #define __glibcxx_check_heap(_First,_Last)                              \
226 __glibcxx_check_valid_range(_First,_Last);                              \
227 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last),                    \
228                       _M_message(__gnu_debug::__msg_not_heap)           \
229                       ._M_iterator(_First, #_First)                     \
230                       ._M_iterator(_Last, #_Last))
231
232 /** Verify that the iterator range [_First, _Last) is a heap
233     w.r.t. the predicate _Pred. */
234 #define __glibcxx_check_heap_pred(_First,_Last,_Pred)                   \
235 __glibcxx_check_valid_range(_First,_Last);                              \
236 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last, _Pred),             \
237                       _M_message(__gnu_debug::__msg_not_heap_pred)      \
238                       ._M_iterator(_First, #_First)                     \
239                       ._M_iterator(_Last, #_Last)                       \
240                       ._M_string(#_Pred))
241
242 #ifdef _GLIBCXX_DEBUG_PEDANTIC
243 #  define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0)
244 #  define __glibcxx_check_string_len(_String,_Len) \
245        _GLIBCXX_DEBUG_ASSERT(_String != 0 || _Len == 0)
246 #else
247 #  define __glibcxx_check_string(_String)
248 #  define __glibcxx_check_string_len(_String,_Len)
249 #endif
250
251 #endif