[221] | 1 | /***************************************************************************
|
---|
| 2 | * blitz/bzdebug.h Debugging macros
|
---|
| 3 | *
|
---|
| 4 | * $Id: bzdebug.h,v 1.1.1.1 1999-04-09 17:58:58 ansari Exp $
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
|
---|
| 7 | *
|
---|
| 8 | * This program is free software; you can redistribute it and/or
|
---|
| 9 | * modify it under the terms of the GNU General Public License
|
---|
| 10 | * as published by the Free Software Foundation; either version 2
|
---|
| 11 | * of the License, or (at your option) any later version.
|
---|
| 12 | *
|
---|
| 13 | * This program is distributed in the hope that it will be useful,
|
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | * GNU General Public License for more details.
|
---|
| 17 | *
|
---|
| 18 | * Suggestions: blitz-suggest@cybervision.com
|
---|
| 19 | * Bugs: blitz-bugs@cybervision.com
|
---|
| 20 | *
|
---|
| 21 | * For more information, please see the Blitz++ Home Page:
|
---|
| 22 | * http://seurat.uwaterloo.ca/blitz/
|
---|
| 23 | *
|
---|
| 24 | ***************************************************************************
|
---|
| 25 | * $Log: not supported by cvs2svn $
|
---|
| 26 | * Revision 1.7 1998/03/14 00:04:47 tveldhui
|
---|
| 27 | * 0.2-alpha-05
|
---|
| 28 | *
|
---|
| 29 | * Revision 1.6 1998/02/26 18:09:36 tveldhui
|
---|
| 30 | * Added testsuite support for precondition fail checking
|
---|
| 31 | *
|
---|
| 32 | * Revision 1.5 1997/07/16 14:51:20 tveldhui
|
---|
| 33 | * Update: Alpha release 0.2 (Arrays)
|
---|
| 34 | *
|
---|
| 35 | * Revision 1.4 1997/01/24 14:42:00 tveldhui
|
---|
| 36 | * Periodic RCS update
|
---|
| 37 | *
|
---|
| 38 | * Revision 1.3 1997/01/13 22:19:58 tveldhui
|
---|
| 39 | * Periodic RCS update
|
---|
| 40 | *
|
---|
| 41 | * Revision 1.2 1996/11/11 17:29:13 tveldhui
|
---|
| 42 | * Periodic RCS update
|
---|
| 43 | *
|
---|
| 44 | * Revision 1.1 1996/04/14 12:36:45 todd
|
---|
| 45 | * Initial revision
|
---|
| 46 | *
|
---|
| 47 | *
|
---|
| 48 | */
|
---|
| 49 |
|
---|
| 50 | #ifndef BZ_DEBUG_H
|
---|
| 51 | #define BZ_DEBUG_H
|
---|
| 52 |
|
---|
| 53 | #include <stdlib.h>
|
---|
| 54 | #include <assert.h>
|
---|
| 55 |
|
---|
| 56 | #ifdef BZ_RTTI
|
---|
| 57 | #include <typeinfo>
|
---|
| 58 | #endif
|
---|
| 59 |
|
---|
| 60 | BZ_NAMESPACE(blitz)
|
---|
| 61 |
|
---|
| 62 | /*
|
---|
| 63 | * These globals are used by the Blitz++ testsuite. The _bz_global
|
---|
| 64 | * modifier ensures that they will reside in libblitz.a, but appear
|
---|
| 65 | * "extern" elsewhere.
|
---|
| 66 | */
|
---|
| 67 |
|
---|
| 68 | _bz_global _bz_bool assertFailMode BZ_GLOBAL_INIT(_bz_false);
|
---|
| 69 | _bz_global int assertFailCount BZ_GLOBAL_INIT(0);
|
---|
| 70 | _bz_global int assertSuccessCount BZ_GLOBAL_INIT(0);
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | #ifdef BZ_TESTSUITE
|
---|
| 74 | /*
|
---|
| 75 | * In testsuite mode, these routines allow a test suite to check
|
---|
| 76 | * that precondition checking is being done properly. A typical
|
---|
| 77 | * use looks like this:
|
---|
| 78 | *
|
---|
| 79 | * beginCheckAssert();
|
---|
| 80 | * // Some operation which should cause an assert to fail
|
---|
| 81 | * endCheckAssert();
|
---|
| 82 | *
|
---|
| 83 | * The routine beginCheckAssert() sets a flag which results in
|
---|
| 84 | * failed asserts being silently tallied. If no asserts have
|
---|
| 85 | * failed by the time endCheckAssert() is invoked, the program
|
---|
| 86 | * halts and issues an error code.
|
---|
| 87 | *
|
---|
| 88 | * In normal operation (i.e. when beginCheckAssert() has not
|
---|
| 89 | * been called), failed preconditions will cause the program
|
---|
| 90 | * to halt and issue an error code. -- TV 980226
|
---|
| 91 | */
|
---|
| 92 |
|
---|
| 93 | inline void checkAssert(_bz_bool condition, const char* where=0,
|
---|
| 94 | int line=0)
|
---|
| 95 | {
|
---|
| 96 | if (assertFailMode == _bz_true)
|
---|
| 97 | {
|
---|
| 98 | if (condition == _bz_true)
|
---|
| 99 | ++assertSuccessCount;
|
---|
| 100 | else
|
---|
| 101 | ++assertFailCount;
|
---|
| 102 | }
|
---|
| 103 | else {
|
---|
| 104 | if (!condition)
|
---|
| 105 | {
|
---|
| 106 | cerr << "Unexpected assert failure!" << endl;
|
---|
| 107 | if (where)
|
---|
| 108 | cerr << where << ":" << line << endl;
|
---|
| 109 | cerr.flush();
|
---|
| 110 | assert(0);
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | inline void beginCheckAssert()
|
---|
| 116 | {
|
---|
| 117 | assertFailMode = _bz_true;
|
---|
| 118 | assertSuccessCount = 0;
|
---|
| 119 | assertFailCount = 0;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | inline void endCheckAssert()
|
---|
| 123 | {
|
---|
| 124 | assert(assertFailMode == _bz_true);
|
---|
| 125 | assertFailMode = _bz_false;
|
---|
| 126 | if (assertFailCount == 0)
|
---|
| 127 | {
|
---|
| 128 | cerr << "Assert check failed!" << endl;
|
---|
| 129 | assert(0);
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | #define BZASSERT(X) checkAssert(X, __FILE__, __LINE__)
|
---|
| 134 | #define BZPRECONDITION(X) checkAssert(X, __FILE__, __LINE__)
|
---|
| 135 | #define BZPOSTCONDITION(X) checkAssert(X, __FILE__, __LINE__)
|
---|
| 136 | #define BZSTATECHECK(X,Y) checkAssert(X == Y, __FILE__, __LINE__)
|
---|
| 137 | #define BZPRECHECK(X,Y) \
|
---|
| 138 | { \
|
---|
| 139 | if ((assertFailMode == _bz_false) && (!(X))) \
|
---|
| 140 | cerr << Y << endl; \
|
---|
| 141 | checkAssert(X, __FILE__, __LINE__); \
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | #define BZ_DEBUG_MESSAGE(X) \
|
---|
| 145 | { if (assertFailMode == _bz_false) { cout << __FILE__ << ":" << __LINE__ << " " << X << endl; } }
|
---|
| 146 |
|
---|
| 147 | #define BZ_PRE_FAIL checkAssert(0)
|
---|
| 148 | #else
|
---|
| 149 | #ifdef BZ_DEBUG
|
---|
| 150 | #define BZASSERT(X) assert(X)
|
---|
| 151 | #define BZPRECONDITION(X) assert(X)
|
---|
| 152 | #define BZPOSTCONDITION(X) assert(X)
|
---|
| 153 | #define BZSTATECHECK(X,Y) assert(X == Y)
|
---|
| 154 | #define BZPRECHECK(X,Y) \
|
---|
| 155 | { if (!(X)) \
|
---|
| 156 | { cerr << "[Blitz++] Precondition failure: Module " << __FILE__ \
|
---|
| 157 | << " line " << __LINE__ << endl \
|
---|
| 158 | << Y << endl; \
|
---|
| 159 | cerr.flush(); \
|
---|
| 160 | assert(0); \
|
---|
| 161 | } \
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | #define BZ_PRE_FAIL assert(0)
|
---|
| 165 |
|
---|
| 166 | #define BZ_DEBUG_MESSAGE(X) \
|
---|
| 167 | { cout << __FILE__ << ":" << __LINE__ << " " << X << endl; }
|
---|
| 168 |
|
---|
| 169 | void _bz_debug_marker();
|
---|
| 170 | #define BZ_ASM_DEBUG_MARKER _bz_debug_marker();
|
---|
| 171 | #else // !BZ_DEBUG
|
---|
| 172 | #define BZASSERT(X)
|
---|
| 173 | #define BZPRECONDITION(X)
|
---|
| 174 | #define BZPOSTCONDITION(X)
|
---|
| 175 | #define BZSTATECHECK(X,Y)
|
---|
| 176 | #define BZPRECHECK(X,Y)
|
---|
| 177 | #define BZ_PRE_FAIL
|
---|
| 178 | #define BZ_DEBUG_MESSAGE(X)
|
---|
| 179 | #endif // !BZ_DEBUG
|
---|
| 180 | #endif // !BZ_TESTSUITE
|
---|
| 181 |
|
---|
| 182 | // This routine doesn't exist anywhere; it's used to mark a
|
---|
| 183 | // position of interest in assembler (.s) files
|
---|
| 184 | void _bz_debug_marker();
|
---|
| 185 |
|
---|
| 186 | #define BZ_NOT_IMPLEMENTED() { cerr << "[Blitz++] Not implemented: module " \
|
---|
| 187 | << __FILE__ << " line " << __LINE__ << endl; \
|
---|
| 188 | exit(1); }
|
---|
| 189 |
|
---|
| 190 | #ifdef BZ_RTTI
|
---|
| 191 | #define BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(X) typeid(X).name()
|
---|
| 192 | #else
|
---|
| 193 |
|
---|
| 194 | template<class T>
|
---|
| 195 | class _bz_stringLiteralForNumericType {
|
---|
| 196 | public:
|
---|
| 197 | static const char* string()
|
---|
| 198 | { return "unknown"; }
|
---|
| 199 | };
|
---|
| 200 |
|
---|
| 201 | #define BZ_DECL_SLFNT(X,Y) \
|
---|
| 202 | template<> \
|
---|
| 203 | class _bz_stringLiteralForNumericType< X > { \
|
---|
| 204 | public: \
|
---|
| 205 | static const char* string() \
|
---|
| 206 | { return Y; } \
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | #ifdef BZ_BOOL
|
---|
| 210 | BZ_DECL_SLFNT(bool, "bool");
|
---|
| 211 | #endif
|
---|
| 212 |
|
---|
| 213 | BZ_DECL_SLFNT(char, "char");
|
---|
| 214 | BZ_DECL_SLFNT(unsigned char, "unsigned char");
|
---|
| 215 | BZ_DECL_SLFNT(short int, "short int");
|
---|
| 216 | BZ_DECL_SLFNT(short unsigned int, "short unsigned int");
|
---|
| 217 | BZ_DECL_SLFNT(int, "int");
|
---|
| 218 | BZ_DECL_SLFNT(unsigned int, "unsigned int");
|
---|
| 219 | BZ_DECL_SLFNT(long, "long");
|
---|
| 220 | BZ_DECL_SLFNT(unsigned long, "unsigned long");
|
---|
| 221 | BZ_DECL_SLFNT(float, "float");
|
---|
| 222 | BZ_DECL_SLFNT(double, "double");
|
---|
| 223 | BZ_DECL_SLFNT(long double, "long double");
|
---|
| 224 |
|
---|
| 225 | #ifdef BZ_HAVE_COMPLEX
|
---|
| 226 | BZ_DECL_SLFNT(complex<float>, "complex<float>");
|
---|
| 227 | BZ_DECL_SLFNT(complex<double>, "complex<double>");
|
---|
| 228 | BZ_DECL_SLFNT(complex<long double>, "complex<long double>");
|
---|
| 229 | #endif
|
---|
| 230 |
|
---|
| 231 | #define BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(X) \
|
---|
| 232 | _bz_stringLiteralForNumericType<X>::string()
|
---|
| 233 |
|
---|
| 234 | #endif // !BZ_RTTI
|
---|
| 235 |
|
---|
| 236 | BZ_NAMESPACE_END
|
---|
| 237 |
|
---|
| 238 | #endif // BZ_DEBUG_H
|
---|