diff --git a/crates/oq3_semantics/src/syntax_to_semantics.rs b/crates/oq3_semantics/src/syntax_to_semantics.rs index ca91531..55f2b6e 100644 --- a/crates/oq3_semantics/src/syntax_to_semantics.rs +++ b/crates/oq3_semantics/src/syntax_to_semantics.rs @@ -24,7 +24,11 @@ use oq3_syntax::ast as synast; // Syntactic AST use crate::with_scope; -use crate::utils::type_name_of; // for debugging +// dprintln, ddbg are defined in utils.rs +use crate::utils::type_name_of; +#[allow(unused_imports)] +#[cfg(debug_assertions)] +use crate::{ddbg, dprintln}; // for debugging // traits use synast::{HasArgList, HasModuleItem, HasName, HasTextName}; diff --git a/crates/oq3_semantics/src/utils.rs b/crates/oq3_semantics/src/utils.rs index 8623b52..5bff970 100644 --- a/crates/oq3_semantics/src/utils.rs +++ b/crates/oq3_semantics/src/utils.rs @@ -31,3 +31,40 @@ macro_rules! dbg_stdout { ($(::std::dbg_stdout!($val)),+,) }; } + +/// This is the same as `dbg!`, except that it is only defined in a debug build. +/// Attempting use in a release build will result in an error +/// `error: cannot determine resolution for the macro ddbg` +#[cfg(debug_assertions)] +#[macro_export] +macro_rules! ddbg { + () => { + println!("[{}:{}:{}]", file!(), line!(), column!()) + }; + ($val:expr $(,)?) => { + match $val { + tmp => { + eprintln!("[{}:{}:{}] {} = {:#?}", + file!(), line!(), column!(), stringify!($val), &tmp); + tmp + } + } + }; + ($($val:expr),+ $(,)?) => { + ($(ddbg!($val)),+,) + }; +} + +/// This is the same as `println!`, except that it is only defined in a debug build. +/// Attempting use in a release build will result in an error +/// `error: cannot determine resolution for the macro dprintln!` +#[cfg(debug_assertions)] +#[macro_export] +macro_rules! dprintln { + () => { + print!("\n") + }; + ($($arg:tt)*) => {{ + println!($($arg)*); + }}; +}