diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-08-27 23:12:05 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-09-05 01:48:20 -0700 |
| commit | 8a966183fe5129ea2a55a9898ac1bd0f16f3573d (patch) | |
| tree | 8e222f4e505499610a935accf49b73e5ee8e2a89 /src/libsyntax | |
| parent | 3c3ae1d0e26c9ae0906dc57daa14bb9e4627e3c8 (diff) | |
| download | rust-8a966183fe5129ea2a55a9898ac1bd0f16f3573d.tar.gz rust-8a966183fe5129ea2a55a9898ac1bd0f16f3573d.zip | |
Remove the __log function for __log_level
Also redefine all of the standard logging macros to use more rust code instead of custom LLVM translation code. This makes them a bit easier to understand, but also more flexibile for future types of logging. Additionally, this commit removes the LogType language item in preparation for changing how logging is performed.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 88 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/oldvisit.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 5 |
8 files changed, 50 insertions, 84 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c7ebc344a9c..ca5e31ee432 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -505,7 +505,9 @@ pub enum Expr_ { ExprBreak(Option<Ident>), ExprAgain(Option<Ident>), ExprRet(Option<@Expr>), - ExprLog(@Expr, @Expr), + + /// Gets the log level for the enclosing module + ExprLogLevel, ExprInlineAsm(inline_asm), diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 7e48fe4d419..00248425ee6 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -740,59 +740,41 @@ pub fn std_macros() -> @str { macro_rules! ignore (($($x:tt)*) => (())) - macro_rules! error ( - ($arg:expr) => ( - __log(1u32, fmt!( \"%?\", $arg )) - ); - ($( $arg:expr ),+) => ( - __log(1u32, fmt!( $($arg),+ )) - ) - ) - - macro_rules! warn ( - ($arg:expr) => ( - __log(2u32, fmt!( \"%?\", $arg )) - ); - ($( $arg:expr ),+) => ( - __log(2u32, fmt!( $($arg),+ )) - ) - ) - - macro_rules! info ( - ($arg:expr) => ( - __log(3u32, fmt!( \"%?\", $arg )) - ); - ($( $arg:expr ),+) => ( - __log(3u32, fmt!( $($arg),+ )) - ) - ) - - macro_rules! debug ( - ($arg:expr) => ( - if cfg!(debug) { __log(4u32, fmt!( \"%?\", $arg )) } - ); - ($( $arg:expr ),+) => ( - if cfg!(debug) { __log(4u32, fmt!( $($arg),+ )) } - ) - ) - - macro_rules! error2 ( - ($($arg:tt)*) => ( __log(1u32, format!($($arg)*))) - ) - - macro_rules! warn2 ( - ($($arg:tt)*) => ( __log(2u32, format!($($arg)*))) - ) - - macro_rules! info2 ( - ($($arg:tt)*) => ( __log(3u32, format!($($arg)*))) + macro_rules! log( + ($lvl:expr, $arg:expr) => ({ + let lvl = $lvl; + if lvl <= __log_level() { + ::std::logging::log(lvl, fmt!(\"%?\", $arg)) + } + }); + ($lvl:expr, $($arg:expr),+) => ({ + let lvl = $lvl; + if lvl <= __log_level() { + ::std::logging::log(lvl, fmt!($($arg),+)) + } + }) ) - - macro_rules! debug2 ( - ($($arg:tt)*) => ( - if cfg!(debug) { __log(4u32, format!($($arg)*)) } - ) + macro_rules! error( ($($arg:tt)+) => (log!(1u32, $($arg)+)) ) + macro_rules! warn ( ($($arg:tt)+) => (log!(2u32, $($arg)+)) ) + macro_rules! info ( ($($arg:tt)+) => (log!(3u32, $($arg)+)) ) + macro_rules! debug( ($($arg:tt)+) => ( + if cfg!(debug) { log!(4u32, $($arg)+) } + )) + + macro_rules! log2( + ($lvl:expr, $($arg:tt)+) => ({ + let lvl = $lvl; + if lvl <= __log_level() { + ::std::logging::log(lvl, format!($($arg)+)) + } + }) ) + macro_rules! error2( ($($arg:tt)+) => (log2!(1u32, $($arg)+)) ) + macro_rules! warn2 ( ($($arg:tt)+) => (log2!(2u32, $($arg)+)) ) + macro_rules! info2 ( ($($arg:tt)+) => (log2!(3u32, $($arg)+)) ) + macro_rules! debug2( ($($arg:tt)+) => ( + if cfg!(debug) { log2!(4u32, $($arg)+) } + )) macro_rules! fail( () => ( @@ -989,13 +971,13 @@ pub fn std_macros() -> @str { // allocation but should rather delegate to an invocation of // write! instead of format! macro_rules! print ( - ($($arg:tt)+) => ( ::std::io::print(format!($($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)+) => (::std::io::println(format!($($arg)+))) ) // NOTE: use this after a snapshot lands to abstract the details diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 7aa0f3abe87..1e4df7811dd 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -616,12 +616,7 @@ pub fn noop_fold_expr(e: &Expr_, fld: @ast_fold) -> Expr_ { ExprRet(ref e) => { ExprRet(e.map_move(|x| fld.fold_expr(x))) } - ExprLog(lv, e) => { - ExprLog( - fld.fold_expr(lv), - fld.fold_expr(e) - ) - } + ExprLogLevel => ExprLogLevel, ExprInlineAsm(ref a) => { ExprInlineAsm(inline_asm { inputs: a.inputs.map(|&(c, input)| (c, fld.fold_expr(input))), diff --git a/src/libsyntax/oldvisit.rs b/src/libsyntax/oldvisit.rs index e9d7b5c4a0d..c9a01cb3804 100644 --- a/src/libsyntax/oldvisit.rs +++ b/src/libsyntax/oldvisit.rs @@ -567,10 +567,7 @@ pub fn visit_expr<E:Clone>(ex: @Expr, (e, v): (E, vt<E>)) { ExprBreak(_) => (), ExprAgain(_) => (), ExprRet(eo) => visit_expr_opt(eo, (e.clone(), v)), - ExprLog(lv, x) => { - (v.visit_expr)(lv, (e.clone(), v)); - (v.visit_expr)(x, (e.clone(), v)); - } + ExprLogLevel => (), ExprMac(ref mac) => visit_mac(mac, (e.clone(), v)), ExprParen(x) => (v.visit_expr)(x, (e.clone(), v)), ExprInlineAsm(ref a) => { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 51c5522ae2f..7afd9c8bf23 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -26,7 +26,7 @@ use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock}; use ast::{ExprBreak, ExprCall, ExprCast, ExprDoBody}; use ast::{ExprField, ExprFnBlock, ExprIf, ExprIndex}; -use ast::{ExprLit, ExprLog, ExprLoop, ExprMac}; +use ast::{ExprLit, ExprLogLevel, ExprLoop, ExprMac}; use ast::{ExprMethodCall, ExprParen, ExprPath, ExprRepeat}; use ast::{ExprRet, ExprSelf, ExprStruct, ExprTup, ExprUnary}; use ast::{ExprVec, ExprVstore, ExprVstoreMutBox}; @@ -1827,13 +1827,10 @@ impl Parser { } } hi = self.last_span.hi; - } else if self.eat_keyword(keywords::__Log) { - // LOG expression + } else if self.eat_keyword(keywords::__LogLevel) { + // LOG LEVEL expression self.expect(&token::LPAREN); - let lvl = self.parse_expr(); - self.expect(&token::COMMA); - let e = self.parse_expr(); - ex = ExprLog(lvl, e); + ex = ExprLogLevel; hi = self.span.hi; self.expect(&token::RPAREN); } else if self.eat_keyword(keywords::Return) { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 591b4b10bd3..15cc7e151b9 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -457,7 +457,7 @@ fn mk_fresh_ident_interner() -> @ident_interner { "if", // 42 "impl", // 43 "let", // 44 - "__log", // 45 + "__log_level", // 45 "loop", // 46 "match", // 47 "mod", // 48 @@ -583,7 +583,7 @@ pub mod keywords { Impl, In, Let, - __Log, + __LogLevel, Loop, Match, Mod, @@ -628,7 +628,7 @@ pub mod keywords { Impl => Ident { name: 43, ctxt: 0 }, In => Ident { name: 63, ctxt: 0 }, Let => Ident { name: 44, ctxt: 0 }, - __Log => Ident { name: 45, ctxt: 0 }, + __LogLevel => Ident { name: 45, ctxt: 0 }, Loop => Ident { name: 46, ctxt: 0 }, Match => Ident { name: 47, ctxt: 0 }, Mod => Ident { name: 48, ctxt: 0 }, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 32cf30fd3a0..e1b0616bfbf 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1407,13 +1407,9 @@ pub fn print_expr(s: @ps, expr: &ast::Expr) { _ => () } } - ast::ExprLog(lexp, expr) => { - word(s.s, "__log"); + ast::ExprLogLevel => { + word(s.s, "__log_level"); popen(s); - print_expr(s, lexp); - word(s.s, ","); - space_if_not_bol(s); - print_expr(s, expr); pclose(s); } ast::ExprInlineAsm(ref a) => { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index ae2044cb979..d96eeeb0d40 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -643,10 +643,7 @@ pub fn walk_expr<E:Clone, V:Visitor<E>>(visitor: &mut V, expression: @Expr, env: ExprRet(optional_expression) => { walk_expr_opt(visitor, optional_expression, env.clone()) } - ExprLog(level, subexpression) => { - visitor.visit_expr(level, env.clone()); - visitor.visit_expr(subexpression, env.clone()); - } + ExprLogLevel => {} ExprMac(ref macro) => walk_mac(visitor, macro, env.clone()), ExprParen(subexpression) => { visitor.visit_expr(subexpression, env.clone()) |
