BAN: Implement better ASSERT macros
Implement macros for all basic binary ops. These macros print failed values when the fail.
This commit is contained in:
parent
6ef153b6ca
commit
3c311efb81
|
@ -1,11 +1,33 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <BAN/Traits.h>
|
||||||
|
|
||||||
#if defined(__is_kernel)
|
#if defined(__is_kernel)
|
||||||
#include <kernel/Panic.h>
|
#include <kernel/Panic.h>
|
||||||
#define ASSERT(cond) do { if (!(cond)) Kernel::panic("ASSERT("#cond") failed"); } while (false)
|
|
||||||
|
#define ASSERT(cond) \
|
||||||
|
do { \
|
||||||
|
if (!(cond)) \
|
||||||
|
Kernel::panic("ASSERT(" #cond ") failed"); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#define __ASSERT_BIN_OP(lhs, rhs, name, op) \
|
||||||
|
do { \
|
||||||
|
auto&& _lhs = lhs; \
|
||||||
|
auto&& _rhs = rhs; \
|
||||||
|
if (!(_lhs op _rhs)) \
|
||||||
|
Kernel::panic(name "(" #lhs ", " #rhs ") ({} " #op " {}) failed", _lhs, _rhs); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#define ASSERT_LT(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_LT", <)
|
||||||
|
#define ASSERT_LE(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_LE", <=)
|
||||||
|
#define ASSERT_GT(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_GT", >)
|
||||||
|
#define ASSERT_GE(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_GE", >=)
|
||||||
|
#define ASSERT_EQ(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_EQ", ==)
|
||||||
|
#define ASSERT_NE(lhs, rhs) __ASSERT_BIN_OP(lhs, rhs, "ASSERT_NE", !=)
|
||||||
#define ASSERT_NOT_REACHED() Kernel::panic("ASSERT_NOT_REACHED() failed")
|
#define ASSERT_NOT_REACHED() Kernel::panic("ASSERT_NOT_REACHED() failed")
|
||||||
#else
|
#else
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#define ASSERT(cond) assert((cond) && "ASSERT("#cond") failed")
|
#define ASSERT(cond) assert((cond) && "ASSERT("#cond") failed")
|
||||||
#define ASSERT_NOT_REACHED() do { assert(false && "ASSERT_NOT_REACHED() failed"); __builtin_unreachable(); } while (false)
|
#define ASSERT_NOT_REACHED() do { assert(false && "ASSERT_NOT_REACHED() failed"); __builtin_unreachable(); } while (false)
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue