TaPAS  0.2
ccl-assert.h
Go to the documentation of this file.
1 /*
2  * ccl-assert.h -- Macros allowing to set assertions into the code
3  *
4  * This file is a part of the C Common Library (CCL) project.
5  *
6  * Copyright (C) 2010 CNRS UMR 5800 & Université Bordeaux I (see AUTHORS file).
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the AltaRica Public License that comes with this
10  * package.
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.
15  */
16 
25 #ifndef __CCL_ASSERT_H__
26 # define __CCL_ASSERT_H__
27 
28 # ifdef HAVE_CONFIG_H
29 # include <config.h>
30 # endif
31 
32 # include <ccl/ccl-common.h>
33 # include <ccl/ccl-exception.h>
34 
35 BEGIN_C_DECLS
36 
40 CCL_DECLARE_EXCEPTION (assertion, internal_error);
41 
46 CCL_DECLARE_EXCEPTION (unreachable_code_error, internal_error);
47 
51 # define ccl_assert(_cond_) \
52 CCL_CHECK_CONDITION ("assertion", _cond_, __FILE__, __LINE__)
53 
57 # define ccl_pre(_cond_) \
58 CCL_CHECK_CONDITION ("pre-condition", _cond_, __FILE__, __LINE__)
59 
63 # define ccl_post(_cond_) \
64 CCL_CHECK_CONDITION ("post-condition", _cond_, __FILE__, __LINE__)
65 
66 # if CCL_ENABLE_ASSERTIONS
67 
68 # define CCL_CHECK_CONDITION(_t, _c, _f, _l) \
69  ccl_check_condition (_c, _f, _l, "failed " _t " " #_c)
70 
71 # define ccl_unreachable() \
72  ccl_throw (unreachable_code_error, "unreachable code access")
73 
74 # else /* ! CCL_ENABLE_ASSERTIONS */
75 # define CCL_CHECK_CONDITION(_t,_c,_f,_l) CCL_NOP ()
76 
77 # define ccl_unreachable() CCL_NOP ()
78 
79 #endif /* ! CCL_ENABLE_ASSERTIONS */
80 
84 # define ccl_imply(_a, _b) ((!(_a)) || (_b))
85 
86 #define ccl_check_condition(cond_,file_, line_,msg_) \
87  ((cond_) ? 1 : (ccl_raise_assertion (file_,line_, msg_), 0))
88 
89 extern void
90 ccl_raise_assertion (const char *file, int line, const char *msg);
91 
92 END_C_DECLS
93 
94 #endif /* ! __CCL_ASSERT_H__ */
An exception mechanism.
Some useful and common macros.
#define CCL_DECLARE_EXCEPTION(exc, super)
Macro-function used to declare an exception exc.