2022-11-15 18:36:50 +00:00
|
|
|
#pragma once
|
2023-01-22 10:43:48 +00:00
|
|
|
#include <luna/SourceLocation.h>
|
2022-11-15 18:36:50 +00:00
|
|
|
|
2023-01-22 10:43:48 +00:00
|
|
|
[[noreturn]] extern bool __check_failed(SourceLocation location, 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
|
|
|
|
2023-01-14 09:59:30 +00:00
|
|
|
// Like check(), but with a custom error message.
|
2022-12-04 11:19:17 +00:00
|
|
|
#define expect(expr, message) \
|
2022-12-05 12:35:33 +00:00
|
|
|
do { \
|
2023-01-22 10:43:48 +00:00
|
|
|
if (!(expr)) [[unlikely]] { __check_failed(SourceLocation::current(), message); } \
|
2022-12-05 12:35:33 +00:00
|
|
|
} while (0)
|
|
|
|
|
2023-01-22 11:00:52 +00:00
|
|
|
#define expect_at(expr, location, message) \
|
|
|
|
do { \
|
|
|
|
if (!(expr)) [[unlikely]] { __check_failed(location, message); } \
|
|
|
|
} while (0)
|
|
|
|
|
2023-02-25 16:41:28 +00:00
|
|
|
// Fail with an error message and location.
|
|
|
|
#define fail(message) __check_failed(SourceLocation::current(), message)
|
|
|
|
#define fail_at(location, message) __check_failed(location, message)
|
|
|
|
|
2023-01-14 09:59:30 +00:00
|
|
|
// Like assert(), but always enabled.
|
2022-12-05 12:35:33 +00:00
|
|
|
#define check(expr) \
|
|
|
|
do { \
|
2023-01-22 10:43:48 +00:00
|
|
|
if (!(expr)) [[unlikely]] { __check_failed(SourceLocation::current(), #expr); } \
|
2022-12-05 12:35:33 +00:00
|
|
|
} while (0)
|
2022-12-18 11:40:28 +00:00
|
|
|
|
2023-01-22 11:00:52 +00:00
|
|
|
#define check_at(expr, location) \
|
|
|
|
do { \
|
|
|
|
if (!(expr)) [[unlikely]] { __check_failed(location, #expr); } \
|
|
|
|
} while (0)
|
|
|
|
|
2023-01-22 10:43:48 +00:00
|
|
|
#define unreachable() __check_failed(SourceLocation::current(), "Reached unreachable code")
|
2022-12-18 16:15:42 +00:00
|
|
|
|
2023-01-22 10:43:48 +00:00
|
|
|
#define todo() __check_failed(SourceLocation::current(), "Reached a TODO!")
|