2022-11-15 18:36:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-12-06 18:40:35 +00:00
|
|
|
[[noreturn]] extern bool __check_failed(const char* file, const char* line, const char* func, const char* expr);
|
2022-11-15 18:36:50 +00:00
|
|
|
|
2022-12-03 16:18:16 +00:00
|
|
|
#ifndef STRINGIZE_VALUE_OF
|
2022-11-15 18:36:50 +00:00
|
|
|
#define STRINGIZE(x) #x
|
|
|
|
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
2022-12-03 16:18:16 +00:00
|
|
|
#endif
|
2022-11-15 18:36:50 +00:00
|
|
|
|
2022-12-04 11:19:17 +00:00
|
|
|
#define expect(expr, message) \
|
2022-12-05 12:35:33 +00:00
|
|
|
do { \
|
|
|
|
if (!(expr)) [[unlikely]] \
|
|
|
|
{ \
|
|
|
|
__check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, message); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define check(expr) \
|
|
|
|
do { \
|
|
|
|
if (!(expr)) [[unlikely]] \
|
|
|
|
{ \
|
|
|
|
__check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, #expr); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2022-12-18 11:40:28 +00:00
|
|
|
|
|
|
|
#define unreachable() \
|
|
|
|
__check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, "Reached unreachable code")
|