core/irrt: refactor debug.hpp

This commit is contained in:
lyken 2024-08-26 15:29:25 +08:00
parent 8d441576f2
commit 4e6ff06215
No known key found for this signature in database
GPG Key ID: 3BD5FC6AC8325DD8
1 changed files with 13 additions and 9 deletions

View File

@ -10,14 +10,18 @@
#define raise_debug_assert(SizeT, msg, param1, param2, param3) \ #define raise_debug_assert(SizeT, msg, param1, param2, param3) \
raise_exception(SizeT, EXN_ASSERTION_ERROR, "IRRT debug assert failed: " msg, param1, param2, param3); raise_exception(SizeT, EXN_ASSERTION_ERROR, "IRRT debug assert failed: " msg, param1, param2, param3);
#define debug_assert_eq(SizeT, lhs, rhs) \ #define debug_assert_eq(SizeT, lhs, rhs) if constexpr (IRRT_DEBUG_ASSERT_BOOL)
if (IRRT_DEBUG_ASSERT_BOOL && (lhs) != (rhs)) \ {
{ \ if ((lhs) != (rhs))
raise_debug_assert(SizeT, "LHS = {0}. RHS = {1}", lhs, rhs, NO_PARAM); \ {
raise_debug_assert(SizeT, "LHS = {0}. RHS = {1}", lhs, rhs, NO_PARAM);
} }
}
#define debug_assert(SizeT, expr) \ #define debug_assert(SizeT, expr) if constexpr (IRRT_DEBUG_ASSERT_BOOL)
if (IRRT_DEBUG_ASSERT_BOOL && !(expr)) \ {
{ \ if (!(expr))
raise_debug_assert(SizeT, "Got false.", NO_PARAM, NO_PARAM, NO_PARAM); \ {
raise_debug_assert(SizeT, "Got false.", NO_PARAM, NO_PARAM, NO_PARAM);
} }
}