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