From: David Wells Date: Sun, 8 Apr 2018 21:32:02 +0000 (-0400) Subject: Tidy up the Assert macros. X-Git-Tag: v9.0.0-rc1~174^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=727bcbb98dcbf980fb815cbf6e88e65aff05bfc2;p=dealii.git Tidy up the Assert macros. This commit makes the backslashes align neatly in doxygen output for the various standard assertions. --- diff --git a/doc/doxygen/scripts/filter b/doc/doxygen/scripts/filter index 6ecf2a2891..884f43cdf5 100755 --- a/doc/doxygen/scripts/filter +++ b/doc/doxygen/scripts/filter @@ -35,12 +35,35 @@ while (<>) # We don't let doxygen put everything into a namespace # dealii. consequently, doxygen can't link references that contain an # explicit dealii:: qualification. remove it and replace it by the - # global scope + # global scope. + # + # Try to detect whether or not ::dealii:: is part of a macro (e.g., Assert) + # continuation line (line ending in '\'): if it is then replace it with + # spaces. This keeps the '\'s aligned, e.g., the following snippet (which is + # part of the definition of Assert) + # + # ::dealii::internals::abort(__LINE__, \ # part of macro + # __PRETTY_FUNCTION__) + # + # will be converted to + # + # ::internals::abort(__LINE__, \ # part of macro + # __PRETTY_FUNCTION__) + # + # so the '\' is kept in the same column. # # Now, as of doxygen 1.5, this still produces the wrong result, but # that's not our fault. This is reported here: # http://bugzilla.gnome.org/show_bug.cgi?id=365053 - s/(::)?dealii::/::/g; + if (m/^ *(::)?dealii::.*\\$/) + { + s/::dealii::(.*)\\$/::\1 \\/g; + s/dealii::(.*)\\$/\1 \\/g; + } + else + { + s/(::)?dealii::/::/g; + } # Replace all occurrences of something like step-xx by # @ref step_xx "step-xx" diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index f87fd53248..631f5c74b0 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -348,26 +348,24 @@ namespace deal_II_exceptions */ #ifdef DEBUG # ifdef DEAL_II_HAVE_BUILTIN_EXPECT -# define Assert(cond, exc) \ - { \ - if (__builtin_expect(!(cond), false)) \ - ::dealii::deal_II_exceptions::internals:: \ - issue_error_noreturn( \ - ::dealii::deal_II_exceptions::internals::abort_on_exception, \ - __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ - } +# define Assert(cond, exc) \ +{ \ + if (__builtin_expect(!(cond), false)) \ + ::dealii::deal_II_exceptions::internals:: issue_error_noreturn( \ + ::dealii::deal_II_exceptions::internals::abort_on_exception, \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ +} # else -# define Assert(cond, exc) \ - { \ - if (!(cond)) \ - ::dealii::deal_II_exceptions::internals:: \ - issue_error_noreturn( \ - ::dealii::deal_II_exceptions::internals::abort_on_exception, \ - __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ - } +# define Assert(cond, exc) \ +{ \ + if (!(cond)) \ + ::dealii::deal_II_exceptions::internals:: issue_error_noreturn( \ + ::dealii::deal_II_exceptions::internals::abort_on_exception, \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ +} # endif #else -#define Assert(cond, exc) \ +#define Assert(cond, exc) \ {} #endif @@ -390,31 +388,27 @@ namespace deal_II_exceptions */ #ifdef DEBUG # ifdef DEAL_II_HAVE_BUILTIN_EXPECT -# define AssertNothrow(cond, exc) \ - { \ - if (__builtin_expect(!(cond), false)) \ - ::dealii::deal_II_exceptions::internals:: \ - issue_error_nothrow( \ - ::dealii::deal_II_exceptions::internals::abort_nothrow_on_exception, \ - __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ - } +# define AssertNothrow(cond, exc) \ +{ \ + if (__builtin_expect(!(cond), false)) \ + ::dealii::deal_II_exceptions::internals::issue_error_nothrow( \ + ::dealii::deal_II_exceptions::internals::abort_nothrow_on_exception, \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ +} # else -# define AssertNothrow(cond, exc) \ - { \ - if (!(cond)) \ - ::dealii::deal_II_exceptions::internals:: \ - issue_error_nothrow( \ - ::dealii::deal_II_exceptions::internals::abort_nothrow_on_exception, \ - __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ - } +# define AssertNothrow(cond, exc) \ +{ \ + if (!(cond)) \ + ::dealii::deal_II_exceptions::internals::issue_error_nothrow( \ + ::dealii::deal_II_exceptions::internals::abort_nothrow_on_exception, \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ +} # endif #else -#define AssertNothrow(cond, exc) \ +#define AssertNothrow(cond, exc) \ {} #endif - - /** * A macro that serves as the main routine in the exception mechanism for dynamic * error checking. It asserts that a certain condition is fulfilled, otherwise @@ -431,23 +425,21 @@ namespace deal_II_exceptions * @author Wolfgang Bangerth, 1997, 1998, Matthias Maier, 2013 */ #ifdef DEAL_II_HAVE_BUILTIN_EXPECT -#define AssertThrow(cond, exc) \ - { \ - if (__builtin_expect(!(cond), false)) \ - ::dealii::deal_II_exceptions::internals:: \ - issue_error_noreturn( \ - ::dealii::deal_II_exceptions::internals::throw_on_exception, \ - __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ - } +#define AssertThrow(cond, exc) \ +{ \ + if (__builtin_expect(!(cond), false)) \ + ::dealii::deal_II_exceptions::internals:: issue_error_noreturn( \ + ::dealii::deal_II_exceptions::internals::throw_on_exception, \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ +} #else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ -#define AssertThrow(cond, exc) \ - { \ - if (!(cond)) \ - ::dealii::deal_II_exceptions::internals:: \ - issue_error_noreturn( \ - ::dealii::deal_II_exceptions::internals::throw_on_exception, \ - __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ - } +#define AssertThrow(cond, exc) \ +{ \ + if (!(cond)) \ + ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \ + ::dealii::deal_II_exceptions::internals::throw_on_exception, \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \ +} #endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ @@ -1214,7 +1206,6 @@ namespace StandardExceptions #endif // DEAL_II_WITH_MPI } /*namespace StandardExceptions*/ - /** * Special assertion for dimension mismatch. * @@ -1225,8 +1216,8 @@ namespace StandardExceptions * @ingroup Exceptions * @author Guido Kanschat 2007 */ -#define AssertDimension(dim1,dim2) Assert((dim1) == (dim2), \ - dealii::ExcDimensionMismatch((dim1),(dim2))) +#define AssertDimension(dim1,dim2) \ +Assert((dim1) == (dim2), dealii::ExcDimensionMismatch((dim1),(dim2))) /** @@ -1236,8 +1227,9 @@ namespace StandardExceptions * @ingroup Exceptions * @author Guido Kanschat 2010 */ -#define AssertVectorVectorDimension(vec,dim1,dim2) AssertDimension((vec).size(), (dim1)) \ - for (unsigned int i=0;i::type)>::type>((index),0,(range))) +#define AssertIndexRange(index,range) \ +Assert((index) < (range), \ +dealii::ExcIndexRangeType::type)>::type>((index),0,(range))) /** * An assertion that checks whether a number is finite or not. We explicitly @@ -1276,8 +1267,9 @@ namespace internal * @ingroup Exceptions * @author Wolfgang Bangerth, 2015 */ -#define AssertIsFinite(number) Assert(dealii::numbers::is_finite(number), \ - dealii::ExcNumberNotFinite(std::complex(number))) +#define AssertIsFinite(number) \ +Assert(dealii::numbers::is_finite(number), \ +dealii::ExcNumberNotFinite(std::complex(number))) #ifdef DEAL_II_WITH_MPI /** @@ -1290,8 +1282,8 @@ namespace internal * @ingroup Exceptions * @author David Wells, 2016 */ -#define AssertThrowMPI(error_code) AssertThrow(error_code == MPI_SUCCESS, \ - dealii::ExcMPI(error_code)) +#define AssertThrowMPI(error_code) \ +AssertThrow(error_code == MPI_SUCCESS, dealii::ExcMPI(error_code)) #else #define AssertThrowMPI(error_code) {} #endif // DEAL_II_WITH_MPI