#[macro_export]
macro_rules! fa_diagnostic {
(
$kind:ident,
code = $code:expr,
message = $msg:expr
$(, note = $note:expr)?
$(, help = $help:expr)?
) => {{
#[cfg(any(debug_assertions, feature = "diagnostics"))]
{
let diag = $crate::diagnostics::Diagnostic {
kind: $crate::diagnostics::DiagnosticKind::$kind,
code: $code,
message: $msg,
note: None $(.or(Some($note)))?,
help: None $(.or(Some($help)))?,
};
$crate::diagnostics::emit::emit(&diag);
}
}};
}
#[macro_export]
macro_rules! fa_diagnostic_ctx {
(
$kind:ident,
code = $code:expr,
message = $msg:expr
$(, note = $note:expr)?
$(, help = $help:expr)?
) => {{
#[cfg(any(debug_assertions, feature = "diagnostics"))]
{
let diag = $crate::diagnostics::Diagnostic {
kind: $crate::diagnostics::DiagnosticKind::$kind,
code: $code,
message: $msg,
note: None $(.or(Some($note)))?,
help: None $(.or(Some($help)))?,
};
let ctx = $crate::diagnostics::context::DiagContext::capture();
$crate::diagnostics::emit::emit_with_context(&diag, &ctx.format());
}
}};
}
#[macro_export]
macro_rules! fa_emit {
($code:ident) => {{
#[cfg(any(debug_assertions, feature = "diagnostics"))]
{
$crate::diagnostics::emit::emit(&$crate::diagnostics::$code);
}
}};
}
#[macro_export]
macro_rules! fa_emit_ctx {
($code:ident) => {{
#[cfg(any(debug_assertions, feature = "diagnostics"))]
{
let ctx = $crate::diagnostics::context::DiagContext::capture();
$crate::diagnostics::emit::emit_with_context(
&$crate::diagnostics::$code,
&ctx.format(),
);
}
}};
}
#[macro_export]
macro_rules! fa_compile_error {
(
code = $code:expr,
message = $msg:expr
$(, help = $help:expr)?
) => {
compile_error!(concat!(
"[framealloc][", $code, "] ", $msg
$(, "\n help: ", $help)?
));
};
}
#[macro_export]
macro_rules! fa_compile_warning {
(
code = $code:expr,
message = $msg:expr
) => {
#[deprecated(note = concat!("[framealloc][", $code, "] ", $msg))]
const _FRAMEALLOC_WARNING: () = ();
let _ = _FRAMEALLOC_WARNING;
};
}
#[macro_export]
macro_rules! fa_assert {
($cond:expr, $code:ident) => {{
#[cfg(any(debug_assertions, feature = "diagnostics"))]
{
if !$cond {
$crate::fa_emit!($code);
}
}
}};
($cond:expr, $code:ident, ctx) => {{
#[cfg(any(debug_assertions, feature = "diagnostics"))]
{
if !$cond {
$crate::fa_emit_ctx!($code);
}
}
}};
}
#[macro_export]
macro_rules! fa_debug {
($($arg:tt)*) => {{
#[cfg(debug_assertions)]
{
$crate::fa_diagnostic!($($arg)*);
}
}};
}
pub use crate::{fa_assert, fa_compile_error, fa_compile_warning, fa_debug, fa_diagnostic, fa_diagnostic_ctx, fa_emit, fa_emit_ctx};