1 /*
2     This file is part of GNU APL, a free implementation of the
3     ISO/IEC Standard 13751, "Programming Language APL, Extended"
4 
5     Copyright (C) 2008-2015  Dr. Jürgen Sauermann
6 
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef __ASSERT_HH_DEFINED__
22 #define __ASSERT_HH_DEFINED__
23 
24 #include "Common.hh"
25 
26 extern void do_Assert(const char * cond, const char * fun,
27                       const char * file, int line)
28 #ifdef __GNUC__
29     __attribute__ ((noreturn))
30 #endif
31 ;
32 
33 #ifndef ASSERT_LEVEL_WANTED
34 
35 #error "ASSERT_LEVEL_WANTED not defined"
36 
37 #elif ASSERT_LEVEL_WANTED == 0
38 
39 #define Assert1(x)   if ((x)) {}
40 #define Assert(x)    if ((x)) {}
41 
42 #elif ASSERT_LEVEL_WANTED == 1
43 
44 #define Assert1(x)  if ((x)) {}
45 #define Assert(x)  if (!(x))   do_Assert(#x, __FUNCTION__, __FILE__, __LINE__)
46 
47 #elif ASSERT_LEVEL_WANTED == 2
48 
49 #define Assert1(x) if (!(x))   do_Assert(#x, __FUNCTION__, __FILE__, __LINE__)
50 #define Assert(x)  if (!(x))   do_Assert(#x, __FUNCTION__, __FILE__, __LINE__)
51 
52 #else
53 
54 #error "Bad ASSERT_LEVEL_WANTED"
55 
56 #endif
57 
58 #define NeverReach(X) do_Assert(X, __FUNCTION__, __FILE__, __LINE__)
59 
60 /// trivial assertion
61 
62 /// normal assertion
63 
64 /// assertion being fatal if wrong
65 #define Assert_fatal(x) if (!(x)) {\
66    cerr << endl << endl << "FATAL error at " << __FILE__ << ":" << __LINE__ \
67         << endl;   exit(2); }
68 
69 #endif // __ASSERT_HH_DEFINED__
70 
71