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, and exceptions.
13 #ifndef __CVC4__ASSERT_H
14 #define __CVC4__ASSERT_H
17 #include "util/exception.h"
18 #include "cvc4_config.h"
23 class CVC4_PUBLIC AssertionException
: public Exception
{
25 AssertionException() : Exception() {}
26 AssertionException(std::string msg
) : Exception(msg
) {}
27 AssertionException(const char* msg
) : Exception(msg
) {}
28 };/* class AssertionException */
30 class CVC4_PUBLIC UnreachableCodeException
: public AssertionException
{
32 UnreachableCodeException() : AssertionException() {}
33 UnreachableCodeException(std::string msg
) : AssertionException(msg
) {}
34 UnreachableCodeException(const char* msg
) : AssertionException(msg
) {}
35 };/* class UnreachableCodeException */
37 class CVC4_PUBLIC UnhandledCaseException
: public UnreachableCodeException
{
39 UnhandledCaseException() : UnreachableCodeException() {}
40 UnhandledCaseException(std::string msg
) : UnreachableCodeException(msg
) {}
41 UnhandledCaseException(const char* msg
) : UnreachableCodeException(msg
) {}
42 };/* class UnhandledCaseException */
44 #ifdef CVC4_ASSERTIONS
45 # define Assert(cond, msg...) __CVC4_ASSERTGLUE("Assertion failure at " __FILE__ ":", __LINE__, ": " #cond, __builtin_expect((cond), 1), ## msg)
46 #else /* ! CVC4_ASSERTIONS */
47 # define Assert(cond, msg...) /*EXPECT_TRUE( cond )*/
48 #endif /* CVC4_ASSERTIONS */
50 #define AlwaysAssert(cond, msg...) __CVC4_ASSERTGLUE("Assertion failure at " __FILE__ ":", __LINE__, ": " #cond, __builtin_expect((cond), 1), ## msg)
51 #define Unreachable(msg...) __CVC4_UNREACHABLEGLUE("Hit a section of unreachable code at " __FILE__ ":", __LINE__, ## msg)
52 #define Unhandled(msg...) __CVC4_UNHANDLEDGLUE("Hit an unhandled case at " __FILE__ ":", __LINE__, ## msg)
54 #define __CVC4_ASSERTGLUE(str1, line, str2, cond, msg...) AssertImpl(str1 #line str2, cond, ## msg)
55 #define __CVC4_UNREACHABLEGLUE(str, line, msg...) UnreachableImpl(str #line, ## msg)
56 #define __CVC4_UNHANDLEDGLUE(str, line, msg...) UnhandledImpl(str #line, ## msg)
58 inline void AssertImpl(const char* info
, bool cond
, std::string msg
) {
59 if(EXPECT_FALSE( ! cond
))
60 throw AssertionException(std::string(info
) + "\n" + msg
);
63 inline void AssertImpl(const char* info
, bool cond
, const char* msg
) {
64 if(EXPECT_FALSE( ! cond
))
65 throw AssertionException(std::string(info
) + "\n" + msg
);
68 inline void AssertImpl(const char* info
, bool cond
) {
69 if(EXPECT_FALSE( ! cond
))
70 throw AssertionException(info
);
74 inline void UnreachableImpl(const char* info
, std::string msg
) __attribute__ ((noreturn
));
75 inline void UnreachableImpl(const char* info
, const char* msg
) __attribute__ ((noreturn
));
76 inline void UnreachableImpl(const char* info
) __attribute__ ((noreturn
));
79 inline void UnreachableImpl(const char* info
, std::string msg
) {
80 throw UnreachableCodeException(std::string(info
) + "\n" + msg
);
83 inline void UnreachableImpl(const char* info
, const char* msg
) {
84 throw UnreachableCodeException(std::string(info
) + "\n" + msg
);
87 inline void UnreachableImpl(const char* info
) {
88 throw UnreachableCodeException(info
);
92 inline void UnhandledImpl(const char* info
, std::string msg
) __attribute__ ((noreturn
));
93 inline void UnhandledImpl(const char* info
, const char* msg
) __attribute__ ((noreturn
));
94 inline void UnhandledImpl(const char* info
) __attribute__ ((noreturn
));
97 inline void UnhandledImpl(const char* info
, std::string msg
) {
98 throw UnhandledCaseException(std::string(info
) + "\n" + msg
);
101 inline void UnhandledImpl(const char* info
, const char* msg
) {
102 throw UnhandledCaseException(std::string(info
) + "\n" + msg
);
105 inline void UnhandledImpl(const char* info
) {
106 throw UnhandledCaseException(info
);
109 }/* CVC4 namespace */
111 #endif /* __CVC4__ASSERT_H */