macros.h

Go to the documentation of this file.
00001 // Debugging support implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 /** @file debug/macros.h
00032  *  This file is a GNU debug extension to the Standard C++ Library.
00033  */
00034 
00035 #ifndef _GLIBCXX_DEBUG_MACROS_H
00036 #define _GLIBCXX_DEBUG_MACROS_H 1
00037 
00038 /**
00039  * Macros used by the implementation to verify certain
00040  * properties. These macros may only be used directly by the debug
00041  * wrappers. Note that these are macros (instead of the more obviously
00042  * "correct" choice of making them functions) because we need line and
00043  * file information at the call site, to minimize the distance between
00044  * the user error and where the error is reported.
00045  *
00046  */
00047 #define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage)             \
00048   do                                    \
00049   {                                 \
00050     if (! (_Condition))                         \
00051       __gnu_debug::_Error_formatter::_M_at(__FILE__, __LINE__)          \
00052       ._ErrorMessage._M_error();                    \
00053   } while (false)
00054 
00055 // Verify that [_First, _Last) forms a valid iterator range.
00056 #define __glibcxx_check_valid_range(_First,_Last)           \
00057 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last),    \
00058               _M_message(__gnu_debug::__msg_valid_range)    \
00059               ._M_iterator(_First, #_First)         \
00060               ._M_iterator(_Last, #_Last))
00061 
00062 /** Verify that we can insert into *this with the iterator _Position.
00063  *  Insertion into a container at a specific position requires that
00064  *  the iterator be nonsingular (i.e., either dereferenceable or
00065  *  past-the-end) and that it reference the sequence we are inserting
00066  *  into. Note that this macro is only valid when the container is a
00067  *  _Safe_sequence and the iterator is a _Safe_iterator.
00068 */
00069 #define __glibcxx_check_insert(_Position)               \
00070 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),             \
00071               _M_message(__gnu_debug::__msg_insert_singular) \
00072               ._M_sequence(*this, "this")           \
00073               ._M_iterator(_Position, #_Position));     \
00074 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),           \
00075               _M_message(__gnu_debug::__msg_insert_different) \
00076               ._M_sequence(*this, "this")           \
00077               ._M_iterator(_Position, #_Position))
00078 
00079 /** Verify that we can insert the values in the iterator range
00080  *  [_First, _Last) into *this with the iterator _Position.  Insertion
00081  *  into a container at a specific position requires that the iterator
00082  *  be nonsingular (i.e., either dereferenceable or past-the-end),
00083  *  that it reference the sequence we are inserting into, and that the
00084  *  iterator range [_First, Last) is a valid (possibly empty)
00085  *  range. Note that this macro is only valid when the container is a
00086  *  _Safe_sequence and the iterator is a _Safe_iterator.
00087  *
00088  *  @tbd We would like to be able to check for noninterference of
00089  *  _Position and the range [_First, _Last), but that can't (in
00090  *  general) be done.
00091 */
00092 #define __glibcxx_check_insert_range(_Position,_First,_Last)        \
00093 __glibcxx_check_valid_range(_First,_Last);              \
00094 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),             \
00095               _M_message(__gnu_debug::__msg_insert_singular)    \
00096                       ._M_sequence(*this, "this")           \
00097               ._M_iterator(_Position, #_Position));     \
00098 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),           \
00099               _M_message(__gnu_debug::__msg_insert_different)   \
00100               ._M_sequence(*this, "this")           \
00101               ._M_iterator(_Position, #_Position))
00102 
00103 /** Verify that we can erase the element referenced by the iterator
00104  * _Position. We can erase the element if the _Position iterator is
00105  * dereferenceable and references this sequence.
00106 */
00107 #define __glibcxx_check_erase(_Position)                \
00108 _GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(),           \
00109               _M_message(__gnu_debug::__msg_erase_bad)          \
00110                       ._M_sequence(*this, "this")           \
00111               ._M_iterator(_Position, #_Position));     \
00112 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),           \
00113               _M_message(__gnu_debug::__msg_erase_different)    \
00114               ._M_sequence(*this, "this")           \
00115               ._M_iterator(_Position, #_Position))
00116 
00117 /** Verify that we can erase the elements in the iterator range
00118  *  [_First, _Last). We can erase the elements if [_First, _Last) is a
00119  *  valid iterator range within this sequence.
00120 */
00121 #define __glibcxx_check_erase_range(_First,_Last)           \
00122 __glibcxx_check_valid_range(_First,_Last);              \
00123 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),          \
00124               _M_message(__gnu_debug::__msg_erase_different)    \
00125                       ._M_sequence(*this, "this")           \
00126               ._M_iterator(_First, #_First)         \
00127               ._M_iterator(_Last, #_Last))
00128 
00129 // Verify that the subscript _N is less than the container's size.
00130 #define __glibcxx_check_subscript(_N)                   \
00131 _GLIBCXX_DEBUG_VERIFY(_N < this->size(),                \
00132               _M_message(__gnu_debug::__msg_subscript_oob)      \
00133                       ._M_sequence(*this, "this")           \
00134               ._M_integer(_N, #_N)              \
00135               ._M_integer(this->size(), "size"))
00136 
00137 // Verify that the container is nonempty
00138 #define __glibcxx_check_nonempty()                  \
00139 _GLIBCXX_DEBUG_VERIFY(! this->empty(),                  \
00140               _M_message(__gnu_debug::__msg_empty)          \
00141                       ._M_sequence(*this, "this"))
00142 
00143 // Verify that the iterator range [_First, _Last) is sorted
00144 #define __glibcxx_check_sorted(_First,_Last)                \
00145 __glibcxx_check_valid_range(_First,_Last);              \
00146 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last),   \
00147               _M_message(__gnu_debug::__msg_unsorted)           \
00148                       ._M_iterator(_First, #_First)         \
00149               ._M_iterator(_Last, #_Last))
00150 
00151 /** Verify that the iterator range [_First, _Last) is sorted by the
00152     predicate _Pred. */
00153 #define __glibcxx_check_sorted_pred(_First,_Last,_Pred)         \
00154 __glibcxx_check_valid_range(_First,_Last);              \
00155 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last, _Pred), \
00156               _M_message(__gnu_debug::__msg_unsorted_pred)      \
00157                       ._M_iterator(_First, #_First)         \
00158               ._M_iterator(_Last, #_Last)           \
00159               ._M_string(#_Pred))
00160 
00161 // Special variant for std::merge, std::includes, std::set_*
00162 #define __glibcxx_check_sorted_set(_First1,_Last1,_First2)      \
00163 __glibcxx_check_valid_range(_First1,_Last1);                \
00164 _GLIBCXX_DEBUG_VERIFY(                                                  \
00165   __gnu_debug::__check_sorted_set(_First1, _Last1, _First2),        \
00166   _M_message(__gnu_debug::__msg_unsorted)               \
00167   ._M_iterator(_First1, #_First1)                   \
00168   ._M_iterator(_Last1, #_Last1))
00169 
00170 // Likewise with a _Pred.
00171 #define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred)   \
00172 __glibcxx_check_valid_range(_First1,_Last1);                    \
00173 _GLIBCXX_DEBUG_VERIFY(                          \
00174   __gnu_debug::__check_sorted_set(_First1, _Last1, _First2, _Pred), \
00175   _M_message(__gnu_debug::__msg_unsorted_pred)              \
00176   ._M_iterator(_First1, #_First1)                   \
00177   ._M_iterator(_Last1, #_Last1)                     \
00178   ._M_string(#_Pred))
00179 
00180 /** Verify that the iterator range [_First, _Last) is partitioned
00181     w.r.t. the value _Value. */
00182 #define __glibcxx_check_partitioned_lower(_First,_Last,_Value)      \
00183 __glibcxx_check_valid_range(_First,_Last);              \
00184 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
00185                                 _Value),    \
00186               _M_message(__gnu_debug::__msg_unpartitioned)      \
00187               ._M_iterator(_First, #_First)         \
00188               ._M_iterator(_Last, #_Last)           \
00189               ._M_string(#_Value))
00190 
00191 #define __glibcxx_check_partitioned_upper(_First,_Last,_Value)      \
00192 __glibcxx_check_valid_range(_First,_Last);              \
00193 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
00194                                 _Value),    \
00195               _M_message(__gnu_debug::__msg_unpartitioned)      \
00196               ._M_iterator(_First, #_First)         \
00197               ._M_iterator(_Last, #_Last)           \
00198               ._M_string(#_Value))
00199 
00200 /** Verify that the iterator range [_First, _Last) is partitioned
00201     w.r.t. the value _Value and predicate _Pred. */
00202 #define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
00203 __glibcxx_check_valid_range(_First,_Last);              \
00204 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
00205                              _Value, _Pred), \
00206               _M_message(__gnu_debug::__msg_unpartitioned_pred) \
00207               ._M_iterator(_First, #_First)         \
00208               ._M_iterator(_Last, #_Last)           \
00209               ._M_string(#_Pred)                \
00210                       ._M_string(#_Value))
00211 
00212 /** Verify that the iterator range [_First, _Last) is partitioned
00213     w.r.t. the value _Value and predicate _Pred. */
00214 #define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
00215 __glibcxx_check_valid_range(_First,_Last);              \
00216 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
00217                              _Value, _Pred), \
00218               _M_message(__gnu_debug::__msg_unpartitioned_pred) \
00219               ._M_iterator(_First, #_First)         \
00220               ._M_iterator(_Last, #_Last)           \
00221               ._M_string(#_Pred)                \
00222                       ._M_string(#_Value))
00223 
00224 // Verify that the iterator range [_First, _Last) is a heap
00225 #define __glibcxx_check_heap(_First,_Last)              \
00226 __glibcxx_check_valid_range(_First,_Last);              \
00227 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last),                \
00228               _M_message(__gnu_debug::__msg_not_heap)           \
00229               ._M_iterator(_First, #_First)         \
00230               ._M_iterator(_Last, #_Last))
00231 
00232 /** Verify that the iterator range [_First, _Last) is a heap
00233     w.r.t. the predicate _Pred. */
00234 #define __glibcxx_check_heap_pred(_First,_Last,_Pred)           \
00235 __glibcxx_check_valid_range(_First,_Last);              \
00236 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last, _Pred),     \
00237               _M_message(__gnu_debug::__msg_not_heap_pred)      \
00238                       ._M_iterator(_First, #_First)         \
00239               ._M_iterator(_Last, #_Last)           \
00240               ._M_string(#_Pred))
00241 
00242 #ifdef _GLIBCXX_DEBUG_PEDANTIC
00243 #  define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0)
00244 #  define __glibcxx_check_string_len(_String,_Len) \
00245        _GLIBCXX_DEBUG_ASSERT(_String != 0 || _Len == 0)
00246 #else
00247 #  define __glibcxx_check_string(_String)
00248 #  define __glibcxx_check_string_len(_String,_Len)
00249 #endif
00250 
00251 #endif

Generated on Sat Oct 25 05:09:04 2008 for libstdc++ by  doxygen 1.5.6