Metalang99
1.13.3
Full-blown preprocessor metaprogramming
assert.h
Go to the documentation of this file.
1
13
#ifndef ML99_ASSERT_H
14
#define ML99_ASSERT_H
15
16
#include <metalang99/priv/compiler_specific.h>
17
18
#include <
metalang99/bool.h
>
19
#include <
metalang99/lang.h
>
20
27
#define ML99_assert(expr) ML99_call(ML99_assert, expr)
28
32
#define ML99_assertEq(lhs, rhs) ML99_call(ML99_assertEq, lhs, rhs)
33
45
#define ML99_ASSERT(expr) ML99_ASSERT_EQ(expr, ML99_true())
46
58
#define ML99_ASSERT_EQ(lhs, rhs) ML99_ASSERT_UNEVAL((ML99_EVAL(lhs)) == (ML99_EVAL(rhs)))
59
72
#define ML99_ASSERT_UNEVAL(expr) ML99_PRIV_ASSERT_UNEVAL_INNER(expr)
73
89
#define ML99_ASSERT_EMPTY(expr) ML99_ASSERT_EMPTY_UNEVAL(ML99_EVAL(expr))
90
106
#define ML99_ASSERT_EMPTY_UNEVAL(expr) \
107
ML99_ASSERT_UNEVAL(ML99_PRIV_CAT(ML99_PRIV_ASSERT_EMPTY_, expr))
108
109
#ifndef DOXYGEN_IGNORE
110
111
#define ML99_assert_IMPL(expr) v(ML99_ASSERT_UNEVAL(expr))
112
#define ML99_assertEq_IMPL(lhs, rhs) v(ML99_ASSERT_UNEVAL((lhs) == (rhs)))
113
114
#ifdef ML99_PRIV_C11_STATIC_ASSERT_AVAILABLE
115
#define ML99_PRIV_ASSERT_UNEVAL_INNER(expr) _Static_assert((expr), "Metalang99 assertion failed"
)
116
#else
117
// How to imitate static assertions in C99: <https://stackoverflow.com/a/3385694/13166656>.
118
#define ML99_PRIV_ASSERT_UNEVAL_INNER(expr) \
119
static const char ML99_PRIV_CAT( \
120
ml99_assert_, \
121
__LINE__)[(expr) ? 1 : -1] ML99_PRIV_COMPILER_ATTR_UNUSED = {0}
122
#endif
123
124
#define ML99_PRIV_ASSERT_EMPTY_ 1
125
126
// Arity specifiers {
127
128
#define ML99_assert_ARITY 1
129
#define ML99_assertEq_ARITY 2
130
// } (Arity specifiers)
131
132
#endif
// DOXYGEN_IGNORE
133
134
#endif
// ML99_ASSERT_H
bool.h
Boolean algebra.
lang.h
The core metalanguage.
include
metalang99
assert.h
Generated by
1.9.4