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