1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: assert.h,v 1.5 1997-06-19 12:13:49 schmidt Exp $ */ |
---|
3 | |
---|
4 | /* This is for compatibility with standard assert.h */ |
---|
5 | #if defined (NDEBUG) && ! defined (NOASSERT) |
---|
6 | #define NOASSERT |
---|
7 | #endif |
---|
8 | |
---|
9 | /* It should be possible to include this file multiple times for different */ |
---|
10 | /* settings of NOASSERT */ |
---|
11 | |
---|
12 | #undef __ASSERT |
---|
13 | #undef __ASSERT1 |
---|
14 | #undef STICKYASSERT |
---|
15 | #undef STICKYASSERT1 |
---|
16 | #undef ASSERT |
---|
17 | #undef ASSERT1 |
---|
18 | |
---|
19 | #undef __WARN |
---|
20 | #undef STICKYWARN |
---|
21 | #undef WARN |
---|
22 | |
---|
23 | #undef PVIRT_VOID |
---|
24 | #undef PVIRT_INTCF |
---|
25 | #undef PVIRT_BOOL |
---|
26 | #undef PVIRT_INT |
---|
27 | #undef PVIRT_CHARCC |
---|
28 | |
---|
29 | #include <stdio.h> |
---|
30 | #include <stdlib.h> |
---|
31 | |
---|
32 | #define __ASSERT(expression, message, file, line) \ |
---|
33 | (fprintf( stderr, "error: " message "\n%s:%u: failed assertion `%s'\n", \ |
---|
34 | file, line, expression ), abort(), 0 ) |
---|
35 | #define __ASSERT1(expression, message, parameter1, file, line) \ |
---|
36 | (fprintf( stderr, "error: " message "\n%s:%u: failed assertion `%s'\n", \ |
---|
37 | parameter1, file, line, expression ), abort(), 0 ) |
---|
38 | #define STICKYASSERT(expression, message) \ |
---|
39 | ((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__))) |
---|
40 | #define STICKYASSERT1(expression, message, parameter1) \ |
---|
41 | ((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__))) |
---|
42 | |
---|
43 | #define __WARN(expression, message, file, line) \ |
---|
44 | (fprintf( stderr, "warning: " message "\n%s:%u: failed assertion `%s'\n", \ |
---|
45 | file, line, expression ), 0 ) |
---|
46 | #define STICKYWARN(expression, message) \ |
---|
47 | ((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__))) |
---|
48 | |
---|
49 | #ifndef NOASSERT |
---|
50 | #define ASSERT(expression, message) \ |
---|
51 | ((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__))) |
---|
52 | #define ASSERT1(expression, message, parameter1) \ |
---|
53 | ((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__))) |
---|
54 | |
---|
55 | #define WARN(expression, message) \ |
---|
56 | ((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__))) |
---|
57 | |
---|
58 | #define PVIRT_VOID(msg) \ |
---|
59 | { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); } |
---|
60 | #define PVIRT_INTCF(msg) \ |
---|
61 | { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; } |
---|
62 | #define PVIRT_BOOL(msg) \ |
---|
63 | { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return false; } |
---|
64 | #define PVIRT_INT(msg) \ |
---|
65 | { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; } |
---|
66 | #define PVIRT_CHARCC(msg) \ |
---|
67 | { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; } |
---|
68 | #else /* NOASSERT */ |
---|
69 | #define ASSERT(expression, message) |
---|
70 | #define ASSERT1(expression, message, parameter1) |
---|
71 | |
---|
72 | #define WARN(expression, message) |
---|
73 | |
---|
74 | #define PVIRT_VOID(msg) = 0 |
---|
75 | #define PVIRT_INTCF(msg) = 0 |
---|
76 | #define PVIRT_BOOL(msg) = 0 |
---|
77 | #define PVIRT_INT(msg) = 0 |
---|
78 | #define PVIRT_CHARCC(msg) = 0 |
---|
79 | #endif /* NOASSERT */ |
---|