1 /********************* -*- C++ -*- */
3 ** This file is part of the CVC4 prototype.
4 ** Copyright (c) 2009 The Analysis of Computer Systems Group (ACSys)
5 ** Courant Institute of Mathematical Sciences
7 ** See the file COPYING in the top-level source directory for licensing
10 ** Assertion utility classes, functions, exceptions, and macros.
13 #ifndef __CVC4__ASSERT_H
14 #define __CVC4__ASSERT_H
19 #include "util/exception.h"
20 #include "cvc4_config.h"
25 class CVC4_PUBLIC AssertionException
: public Exception
{
27 void construct(const char* header
, const char* extra
,
28 const char* function
, const char* file
,
29 unsigned line
, const char* fmt
, ...) {
32 construct(header
, extra
, function
, file
, line
, fmt
, args
);
35 void construct(const char* header
, const char* extra
,
36 const char* function
, const char* file
,
37 unsigned line
, const char* fmt
, va_list args
);
38 void construct(const char* header
, const char* extra
,
39 const char* function
, const char* file
,
42 AssertionException() : Exception() {}
45 AssertionException(const char* extra
, const char* function
,
46 const char* file
, unsigned line
,
47 const char* fmt
, ...) :
51 construct("Assertion failure", extra
, function
, file
, line
, fmt
, args
);
55 AssertionException(const char* extra
, const char* function
,
56 const char* file
, unsigned line
) :
58 construct("Assertion failure", extra
, function
, file
, line
);
60 };/* class AssertionException */
62 class CVC4_PUBLIC UnreachableCodeException
: public AssertionException
{
64 UnreachableCodeException() : AssertionException() {}
67 UnreachableCodeException(const char* function
, const char* file
,
68 unsigned line
, const char* fmt
, ...) :
69 AssertionException() {
72 construct("Unreachable code reached",
73 NULL
, function
, file
, line
, fmt
, args
);
77 UnreachableCodeException(const char* function
, const char* file
,
79 AssertionException() {
80 construct("Unreachable code reached", NULL
, function
, file
, line
);
82 };/* class UnreachableCodeException */
84 class CVC4_PUBLIC UnhandledCaseException
: public UnreachableCodeException
{
86 UnhandledCaseException() : UnreachableCodeException() {}
89 UnhandledCaseException(const char* function
, const char* file
,
90 unsigned line
, const char* fmt
, ...) :
91 UnreachableCodeException() {
94 construct("Unhandled case encountered",
95 NULL
, function
, file
, line
, fmt
, args
);
99 UnhandledCaseException(const char* function
, const char* file
,
100 unsigned line
, int theCase
) :
101 UnreachableCodeException() {
102 construct("Unhandled case encountered",
103 NULL
, function
, file
, line
, "The case was: %d", theCase
);
106 UnhandledCaseException(const char* function
, const char* file
,
108 UnreachableCodeException() {
109 construct("Unhandled case encountered", NULL
, function
, file
, line
);
111 };/* class UnhandledCaseException */
113 class CVC4_PUBLIC IllegalArgumentException
: public AssertionException
{
115 IllegalArgumentException() : AssertionException() {}
118 IllegalArgumentException(const char* argDesc
, const char* function
,
119 const char* file
, unsigned line
,
120 const char* fmt
, ...) :
121 AssertionException() {
124 construct("Illegal argument detected",
125 argDesc
, function
, file
, line
, fmt
, args
);
129 IllegalArgumentException(const char* argDesc
, const char* function
,
130 const char* file
, unsigned line
) :
131 AssertionException() {
132 construct("Illegal argument detected",
133 argDesc
, function
, file
, line
);
135 };/* class IllegalArgumentException */
137 #define AlwaysAssert(cond, msg...) \
139 if(EXPECT_FALSE( ! (cond) )) { \
140 throw AssertionException(#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg); \
143 #define Unreachable(msg...) \
144 throw UnreachableCodeException(__PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg)
145 #define Unhandled(msg...) \
146 throw UnhandledCaseException(__PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg)
147 #define IllegalArgument(arg, msg...) \
148 throw IllegalArgumentException(#arg, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg)
150 #ifdef CVC4_ASSERTIONS
151 # define Assert(cond, msg...) AlwaysAssert(cond, ## msg)
152 #else /* ! CVC4_ASSERTIONS */
153 # define Assert(cond, msg...) /*EXPECT_TRUE( cond )*/
154 #endif /* CVC4_ASSERTIONS */
156 }/* CVC4 namespace */
158 #endif /* __CVC4__ASSERT_H */