Introduce alternate forms of logging

These new macros are all based on format! instead of fmt! and purely exist for
bootstrapping purposes. After the next snapshot, all uses of logging will be
migrated to these macros, and then after the next snapshot after that we can
drop the `2` suffix on everything
This commit is contained in:
Alex Crichton 2013-08-24 12:46:55 -07:00
parent eb836dd61e
commit a3e39b9454
2 changed files with 31 additions and 24 deletions

View file

@ -758,32 +758,32 @@ pub fn std_macros() -> @str {
)
)
// conditionally define debug!, but keep it type checking even
// in non-debug builds.
macro_rules! __debug (
macro_rules! debug (
($arg:expr) => (
__log(4u32, fmt!( \"%?\", $arg ))
if cfg!(debug) { __log(4u32, fmt!( \"%?\", $arg )) }
);
($( $arg:expr ),+) => (
__log(4u32, fmt!( $($arg),+ ))
if cfg!(debug) { __log(4u32, fmt!( $($arg),+ )) }
)
)
#[cfg(debug)]
#[macro_escape]
mod debug_macro {
macro_rules! debug (($($arg:expr),*) => {
__debug!($($arg),*)
})
}
macro_rules! error2 (
($($arg:tt)*) => ( __log(1u32, format!($($arg)*)))
)
#[cfg(not(debug))]
#[macro_escape]
mod debug_macro {
macro_rules! debug (($($arg:expr),*) => {
if false { __debug!($($arg),*) }
})
}
macro_rules! warn2 (
($($arg:tt)*) => ( __log(2u32, format!($($arg)*)))
)
macro_rules! info2 (
($($arg:tt)*) => ( __log(3u32, format!($($arg)*)))
)
macro_rules! debug2 (
($($arg:tt)*) => (
if cfg!(debug) { __log(4u32, format!($($arg)*)) }
)
)
macro_rules! fail(
() => (
@ -797,6 +797,15 @@ pub fn std_macros() -> @str {
)
)
macro_rules! fail2(
() => (
fail!(\"explicit failure\")
);
($($arg:tt)+) => (
::std::sys::FailWithCause::fail_with(format!($($arg)+), file!(), line!())
)
)
macro_rules! assert(
($cond:expr) => {
if !$cond {
@ -964,15 +973,13 @@ pub fn std_macros() -> @str {
// allocation but should rather delegate to an invocation of
// write! instead of format!
macro_rules! print (
() => ();
($arg:expr) => ( ::std::io::print(format!(\"{}\", $arg)));
($fmt:expr, $($arg:tt)+) => ( ::std::io::print(format!($fmt, $($arg)+)))
($($arg:tt)+) => ( ::std::io::print(format!($($arg)+)))
)
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
// allocation but should rather delegate to an io::Writer
macro_rules! println (
($($arg:tt)*) => ({ print!($($arg)*); ::std::io::println(\"\"); })
($($arg:tt)+) => ({ print!($($arg)+); ::std::io::println(\"\"); })
)
// NOTE: use this after a snapshot lands to abstract the details