]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #9005 : alexcrichton/rust/rusty-log, r=brson
authorbors <bors@rust-lang.org>
Mon, 9 Sep 2013 17:41:05 +0000 (10:41 -0700)
committerbors <bors@rust-lang.org>
Mon, 9 Sep 2013 17:41:05 +0000 (10:41 -0700)
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.

23 files changed:
src/librustc/middle/cfg/construct.rs
src/librustc/middle/dataflow.rs
src/librustc/middle/lang_items.rs
src/librustc/middle/liveness.rs
src/librustc/middle/mem_categorization.rs
src/librustc/middle/moves.rs
src/librustc/middle/trans/controlflow.rs
src/librustc/middle/trans/debuginfo.rs
src/librustc/middle/trans/expr.rs
src/librustc/middle/trans/type_use.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/regionck.rs
src/libstd/logging.rs
src/libstd/std.rs
src/libsyntax/ast.rs
src/libsyntax/ext/expand.rs
src/libsyntax/fold.rs
src/libsyntax/oldvisit.rs
src/libsyntax/parse/parser.rs
src/libsyntax/parse/token.rs
src/libsyntax/print/pprust.rs
src/libsyntax/visit.rs

index c6341abe3a6bdb2b320479901c2d8675d7c7a1df..20e422e5df1a2ebde961ed0dee3c76d1247d3dd6 100644 (file)
@@ -389,7 +389,6 @@ fn expr(&mut self, expr: @ast::Expr, pred: CFGIndex) -> CFGIndex {
                 self.straightline(expr, pred, [r, l])
             }
 
-            ast::ExprLog(l, r) |
             ast::ExprIndex(_, l, r) |
             ast::ExprBinary(_, _, l, r) => { // NB: && and || handled earlier
                 self.straightline(expr, pred, [l, r])
@@ -405,6 +404,7 @@ fn expr(&mut self, expr: @ast::Expr, pred: CFGIndex) -> CFGIndex {
                 self.straightline(expr, pred, [e])
             }
 
+            ast::ExprLogLevel |
             ast::ExprMac(*) |
             ast::ExprInlineAsm(*) |
             ast::ExprSelf |
index b392351c2f2935408183e92caf2a2b5eee40d5d0..0c0a839512470e644748168549ff76ad935c9346 100644 (file)
@@ -702,12 +702,12 @@ fn walk_expr(&mut self,
                 join_bits(&self.dfcx.oper, temp, in_out);
             }
 
-            ast::ExprLog(l, r) |
             ast::ExprIndex(_, l, r) |
             ast::ExprBinary(_, _, l, r) => {
                 self.walk_exprs([l, r], in_out, loop_scopes);
             }
 
+            ast::ExprLogLevel |
             ast::ExprLit(*) |
             ast::ExprPath(*) |
             ast::ExprSelf => {
index c8e1a46fa78548796c8db5f356043d7bb6e7d3b6..41bdba49845b5502c803028898e04ffe24a4a2b6 100644 (file)
@@ -59,7 +59,6 @@ pub enum LangItem {
 
     StrEqFnLangItem,                   // 19
     UniqStrEqFnLangItem,               // 20
-    LogTypeFnLangItem,                 // 21
     FailFnLangItem,                    // 22
     FailBoundsCheckFnLangItem,         // 23
     ExchangeMallocFnLangItem,          // 24
@@ -238,9 +237,6 @@ pub fn str_eq_fn(&self) -> Option<DefId> {
     pub fn uniq_str_eq_fn(&self) -> Option<DefId> {
         self.items[UniqStrEqFnLangItem as uint]
     }
-    pub fn log_type_fn(&self) -> Option<DefId> {
-        self.items[LogTypeFnLangItem as uint]
-    }
     pub fn fail_fn(&self) -> Option<DefId> {
         self.items[FailFnLangItem as uint]
     }
@@ -357,7 +353,6 @@ pub fn new<'a>(crate: &'a Crate, session: Session)
 
         item_refs.insert(@"str_eq", StrEqFnLangItem as uint);
         item_refs.insert(@"uniq_str_eq", UniqStrEqFnLangItem as uint);
-        item_refs.insert(@"log_type", LogTypeFnLangItem as uint);
         item_refs.insert(@"fail_", FailFnLangItem as uint);
         item_refs.insert(@"fail_bounds_check",
                          FailBoundsCheckFnLangItem as uint);
index 27a155403ed0fdd101ab32a09d060acc0c18eee2..27f21385e9bf1a924bebb6b414016929bee2d490 100644 (file)
@@ -526,7 +526,7 @@ fn visit_expr(v: &mut LivenessVisitor, expr: @Expr, this: @mut IrMaps) {
 
       // otherwise, live nodes are not required:
       ExprIndex(*) | ExprField(*) | ExprVstore(*) | ExprVec(*) |
-      ExprCall(*) | ExprMethodCall(*) | ExprTup(*) | ExprLog(*) |
+      ExprCall(*) | ExprMethodCall(*) | ExprTup(*) | ExprLogLevel |
       ExprBinary(*) | ExprAddrOf(*) |
       ExprDoBody(*) | ExprCast(*) | ExprUnary(*) | ExprBreak(_) |
       ExprAgain(_) | ExprLit(_) | ExprRet(*) | ExprBlock(*) |
@@ -1217,7 +1217,6 @@ pub fn propagate_through_expr(&self, expr: @Expr, succ: LiveNode)
             self.propagate_through_expr(l, ln)
           }
 
-          ExprLog(l, r) |
           ExprIndex(_, l, r) |
           ExprBinary(_, _, l, r) => {
             self.propagate_through_exprs([l, r], succ)
@@ -1240,6 +1239,7 @@ pub fn propagate_through_expr(&self, expr: @Expr, succ: LiveNode)
             }
           }
 
+          ExprLogLevel |
           ExprLit(*) => {
             succ
           }
@@ -1496,7 +1496,7 @@ fn check_expr(vt: &mut ErrorCheckVisitor, expr: @Expr, this: @Liveness) {
       // no correctness conditions related to liveness
       ExprCall(*) | ExprMethodCall(*) | ExprIf(*) | ExprMatch(*) |
       ExprWhile(*) | ExprLoop(*) | ExprIndex(*) | ExprField(*) |
-      ExprVstore(*) | ExprVec(*) | ExprTup(*) | ExprLog(*) |
+      ExprVstore(*) | ExprVec(*) | ExprTup(*) | ExprLogLevel |
       ExprBinary(*) | ExprDoBody(*) |
       ExprCast(*) | ExprUnary(*) | ExprRet(*) | ExprBreak(*) |
       ExprAgain(*) | ExprLit(_) | ExprBlock(*) |
index 0f5dd8cda7a99f180bb35312b31f18920d0e899c..b284cd967a75b74c317294c93dd5bd3b78f54b11 100644 (file)
@@ -429,7 +429,7 @@ pub fn cat_expr_unadjusted(&self, expr: @ast::Expr) -> cmt {
           ast::ExprDoBody(*) | ast::ExprUnary(*) |
           ast::ExprMethodCall(*) | ast::ExprCast(*) | ast::ExprVstore(*) |
           ast::ExprVec(*) | ast::ExprTup(*) | ast::ExprIf(*) |
-          ast::ExprLog(*) | ast::ExprBinary(*) | ast::ExprWhile(*) |
+          ast::ExprLogLevel | ast::ExprBinary(*) | ast::ExprWhile(*) |
           ast::ExprBlock(*) | ast::ExprLoop(*) | ast::ExprMatch(*) |
           ast::ExprLit(*) | ast::ExprBreak(*) | ast::ExprMac(*) |
           ast::ExprAgain(*) | ast::ExprStruct(*) | ast::ExprRepeat(*) |
index 55783e3568ea6b42854380f0cdf2e78672be7e42..0d9091e4e44104fad75bd03c5162af7396c7a615 100644 (file)
@@ -480,6 +480,7 @@ pub fn use_expr(&self,
                 self.use_expr(base, Read, visitor);
             }
 
+            ExprLogLevel |
             ExprInlineAsm(*) |
             ExprBreak(*) |
             ExprAgain(*) |
@@ -489,11 +490,6 @@ pub fn use_expr(&self,
                 self.consume_block(blk, visitor);
             }
 
-            ExprLog(a_expr, b_expr) => {
-                self.consume_expr(a_expr, visitor);
-                self.use_expr(b_expr, Read, visitor);
-            }
-
             ExprWhile(cond_expr, ref blk) => {
                 self.consume_expr(cond_expr, visitor);
                 self.consume_block(blk, visitor);
index c3d5598d234cf17bbfcd75d89b43e5664212a964..db4b85605ca3e53d4e0c762b2875c338290a1b3f 100644 (file)
@@ -8,13 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::c_str::ToCStr;
-
-use back::link;
-use lib;
 use lib::llvm::*;
 use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem};
-use middle::lang_items::LogTypeFnLangItem;
 use middle::trans::base::*;
 use middle::trans::build::*;
 use middle::trans::callee;
@@ -28,7 +23,6 @@
 
 use syntax::ast;
 use syntax::ast::Ident;
-use syntax::ast_map::path_mod;
 use syntax::ast_util;
 use syntax::codemap::Span;
 
@@ -206,72 +200,6 @@ pub fn trans_loop(bcx:@mut Block,
     return next_bcx;
 }
 
-pub fn trans_log(log_ex: &ast::Expr,
-                 lvl: @ast::Expr,
-                 bcx: @mut Block,
-                 e: @ast::Expr) -> @mut Block {
-    let _icx = push_ctxt("trans_log");
-    let ccx = bcx.ccx();
-    let mut bcx = bcx;
-    if ty::type_is_bot(expr_ty(bcx, lvl)) {
-       return expr::trans_into(bcx, lvl, expr::Ignore);
-    }
-
-    let (modpath, modname) = {
-        let path = &mut bcx.fcx.path;
-        let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
-        for e in path.iter() {
-            match *e {
-                path_mod(_) => { modpath.push(*e) }
-                _ => {}
-            }
-        }
-        let modname = path_str(ccx.sess, modpath);
-        (modpath, modname)
-    };
-
-    let global = if ccx.module_data.contains_key(&modname) {
-        ccx.module_data.get_copy(&modname)
-    } else {
-        let s = link::mangle_internal_name_by_path_and_seq(
-            ccx, modpath, "loglevel");
-        let global;
-        unsafe {
-            global = do s.with_c_str |buf| {
-                llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
-            };
-            llvm::LLVMSetGlobalConstant(global, False);
-            llvm::LLVMSetInitializer(global, C_null(Type::i32()));
-            lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
-        }
-        ccx.module_data.insert(modname, global);
-        global
-    };
-    let current_level = Load(bcx, global);
-    let level = unpack_result!(bcx, {
-        do with_scope_result(bcx, lvl.info(), "level") |bcx| {
-            expr::trans_to_datum(bcx, lvl).to_result()
-        }
-    });
-
-    let llenabled = ICmp(bcx, lib::llvm::IntUGE, current_level, level);
-    do with_cond(bcx, llenabled) |bcx| {
-        do with_scope(bcx, log_ex.info(), "log") |bcx| {
-            let mut bcx = bcx;
-
-            // Translate the value to be logged
-            let val_datum = unpack_datum!(bcx, expr::trans_to_datum(bcx, e));
-
-            // Call the polymorphic log function
-            let val = val_datum.to_ref_llval(bcx);
-            let did = langcall(bcx, Some(e.span), "", LogTypeFnLangItem);
-            let bcx = callee::trans_lang_call_with_type_params(
-                bcx, did, [level, val], [val_datum.ty], expr::Ignore);
-            bcx
-        }
-    }
-}
-
 pub fn trans_break_cont(bcx: @mut Block,
                         opt_label: Option<Ident>,
                         to_end: bool)
index b89414a6a53a00407633870400a62cc2a01295ce..70630e3ee49b226b37a3494a323fa09aa815e417 100644 (file)
@@ -1995,6 +1995,7 @@ fn walk_expr(cx: &mut CrateContext,
         scope_map.insert(exp.id, scope_stack.last().scope_metadata);
 
         match exp.node {
+            ast::ExprLogLevel |
             ast::ExprSelf     |
             ast::ExprLit(_)   |
             ast::ExprBreak(_) |
@@ -2033,7 +2034,6 @@ fn walk_expr(cx: &mut CrateContext,
             }
 
             ast::ExprAssign(@ref sub_exp1, @ref sub_exp2)    |
-            ast::ExprLog(@ref sub_exp1, @ref sub_exp2)       |
             ast::ExprRepeat(@ref sub_exp1, @ref sub_exp2, _) => {
                 walk_expr(cx, sub_exp1, scope_stack, scope_map);
                 walk_expr(cx, sub_exp2, scope_stack, scope_map);
index 819d390ac28b09ac6997cd5633ee2ebfdb39604a..4b2df0db3c31cefa0c201072041a9055414bb753 100644 (file)
 
 
 use back::abi;
-use lib::llvm::{ValueRef, llvm, SetLinkage, ExternalLinkage};
+use back::link;
+use lib::llvm::{ValueRef, llvm, SetLinkage, ExternalLinkage, False};
 use lib;
 use metadata::csearch;
 use middle::trans::_match;
 use std::vec;
 use syntax::print::pprust::{expr_to_str};
 use syntax::ast;
+use syntax::ast_map::path_mod;
 use syntax::codemap;
 
 // Destinations
@@ -578,6 +580,9 @@ fn trans_rvalue_datum_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> DatumBloc
         ast::ExprParen(e) => {
             return trans_rvalue_datum_unadjusted(bcx, e);
         }
+        ast::ExprLogLevel => {
+            return trans_log_level(bcx);
+        }
         _ => {
             bcx.tcx().sess.span_bug(
                 expr.span,
@@ -608,9 +613,6 @@ fn trans_rvalue_stmt_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> @mut Block
         ast::ExprRet(ex) => {
             return controlflow::trans_ret(bcx, ex);
         }
-        ast::ExprLog(lvl, a) => {
-            return controlflow::trans_log(expr, lvl, bcx, a);
-        }
         ast::ExprWhile(cond, ref body) => {
             return controlflow::trans_while(bcx, cond, body);
         }
@@ -1757,3 +1759,41 @@ fn trans_assign_op(bcx: @mut Block,
 fn shorten(x: &str) -> @str {
     (if x.char_len() > 60 {x.slice_chars(0, 60)} else {x}).to_managed()
 }
+
+pub fn trans_log_level(bcx: @mut Block) -> DatumBlock {
+    let _icx = push_ctxt("trans_log_level");
+    let ccx = bcx.ccx();
+
+    let (modpath, modname) = {
+        let path = &mut bcx.fcx.path;
+        let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
+        for e in path.iter() {
+            match *e {
+                path_mod(_) => { modpath.push(*e) }
+                _ => {}
+            }
+        }
+        let modname = path_str(ccx.sess, modpath);
+        (modpath, modname)
+    };
+
+    let global = if ccx.module_data.contains_key(&modname) {
+        ccx.module_data.get_copy(&modname)
+    } else {
+        let s = link::mangle_internal_name_by_path_and_seq(
+            ccx, modpath, "loglevel");
+        let global;
+        unsafe {
+            global = do s.with_c_str |buf| {
+                llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
+            };
+            llvm::LLVMSetGlobalConstant(global, False);
+            llvm::LLVMSetInitializer(global, C_null(Type::i32()));
+            lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
+        }
+        ccx.module_data.insert(modname, global);
+        global
+    };
+
+    return immediate_rvalue_bcx(bcx, Load(bcx, global), ty::mk_u32());
+}
index 1a51cdfb60e01d57b456523e1b60e635683c4591..1cccca963081141f02673a5f0cda56b842b58679 100644 (file)
@@ -377,9 +377,6 @@ pub fn mark_for_expr(cx: &Context, e: &Expr) {
         let base_ty = ty::node_id_to_type(cx.ccx.tcx, base.id);
         type_needs(cx, use_repr, ty::type_autoderef(cx.ccx.tcx, base_ty));
       }
-      ExprLog(_, val) => {
-        node_type_needs(cx, use_tydesc, val.id);
-      }
       ExprCall(f, _, _) => {
           let r = ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id));
           for a in r.iter() {
@@ -411,7 +408,7 @@ pub fn mark_for_expr(cx: &Context, e: &Expr) {
       ExprMatch(*) | ExprBlock(_) | ExprIf(*) | ExprWhile(*) |
       ExprBreak(_) | ExprAgain(_) | ExprUnary(*) | ExprLit(_) |
       ExprMac(_) | ExprAddrOf(*) | ExprRet(_) | ExprLoop(*) |
-      ExprDoBody(_) => (),
+      ExprDoBody(_) | ExprLogLevel => (),
 
       ExprForLoop(*) => fail!("non-desugared expr_for_loop")
     }
index 4a42efc339328f8f2fbe008bfc0680ab1e024bb3..852f29119d49d016bad13ea5c2d554cb9f624d8c 100644 (file)
@@ -3320,7 +3320,6 @@ pub fn expr_kind(tcx: ctxt,
         ast::ExprBreak(*) |
         ast::ExprAgain(*) |
         ast::ExprRet(*) |
-        ast::ExprLog(*) |
         ast::ExprWhile(*) |
         ast::ExprLoop(*) |
         ast::ExprAssign(*) |
@@ -3331,6 +3330,7 @@ pub fn expr_kind(tcx: ctxt,
 
         ast::ExprForLoop(*) => fail!("non-desugared expr_for_loop"),
 
+        ast::ExprLogLevel |
         ast::ExprLit(_) | // Note: lit_str is carved out above
         ast::ExprUnary(*) |
         ast::ExprAddrOf(*) |
index 50c93468bb1619ade57c11771e6a1e0a246200ab..b6e0fd93fa9bb7f2d76c5f651c535c3247c8843a 100644 (file)
@@ -2526,18 +2526,8 @@ fn check_struct_enum_variant(fcx: @mut FnCtxt,
         }
         fcx.write_bot(id);
       }
-      ast::ExprLog(lv, e) => {
-        check_expr_has_type(fcx, lv,
-                                  ty::mk_mach_uint(ast::ty_u32));
-
-        // Note: this does not always execute, so do not propagate bot:
-        check_expr(fcx, e);
-        if ty::type_is_error(fcx.expr_ty(e)) {
-            fcx.write_error(id);
-        }
-        else {
-            fcx.write_nil(id);
-        }
+      ast::ExprLogLevel => {
+        fcx.write_ty(id, ty::mk_u32())
       }
       ast::ExprParen(a) => {
         check_expr_with_opt_hint(fcx, a, expected);
index d121496af2b2dec398c13dee98ffd5ac3bdfb4d4..29f087094fb433eee4b595b19702ee41c76828ec 100644 (file)
@@ -1020,7 +1020,7 @@ fn guarantor(rcx: @mut Rcx, expr: @ast::Expr) -> Option<ty::Region> {
             ast::ExprBreak(*) |
             ast::ExprAgain(*) |
             ast::ExprRet(*) |
-            ast::ExprLog(*) |
+            ast::ExprLogLevel |
             ast::ExprWhile(*) |
             ast::ExprLoop(*) |
             ast::ExprAssign(*) |
index a885a4f722789470cf9a6fe53e8c70b7f1a162ef..1b91276f904d6ee2a717215cce7586d0da20d416 100644 (file)
@@ -37,7 +37,7 @@ pub fn console_off() {
     rt::logging::console_off();
 }
 
-#[cfg(not(test))]
+#[cfg(not(test), stage0)]
 #[lang="log_type"]
 #[allow(missing_doc)]
 pub fn log_type<T>(_level: u32, object: &T) {
@@ -67,3 +67,10 @@ fn newsched_log_str(msg: ~str) {
         }
     }
 }
+
+// XXX: This will change soon to not require an allocation. This is an unstable
+//      api which should not be used outside of the macros in ext/expand.
+#[doc(hidden)]
+pub fn log(_level: u32, msg: ~str) {
+    newsched_log_str(msg);
+}
index 65fd24b7219803bbecfd9644665c17b01b19d62c..d78ea9f00938db24fb6e32012c88138e8d5ff5c1 100644 (file)
@@ -218,6 +218,7 @@ mod std {
     pub use option;
     pub use kinds;
     pub use local_data;
+    pub use logging;
     pub use sys;
     pub use unstable;
     pub use str;
index 6957f9ae3519d20cbdd2f215fc564660e3e6bd7c..c403893261308ea3aa72ae41490add9e8879cc6c 100644 (file)
@@ -550,7 +550,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),
 
index 099fa54c0c2991900e801b57b57ef58cda11ae38..50a14c0fd714f226554e065a3a11616a9887f3fe 100644 (file)
@@ -870,59 +870,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! 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! debug2 (
-        ($($arg:tt)*) => (
-            if cfg!(debug) { __log(4u32, format!($($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(
         () => (
@@ -1149,13 +1131,13 @@ macro_rules! printfln (
     //              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
index 11e39163992d86313514899446506e2e40871737..664bd3f128a45dad49d18e48a739eec10e7249e7 100644 (file)
@@ -617,12 +617,7 @@ fn fold_field_(field: Field, fld: @ast_fold) -> Field {
         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))),
index 850f73096edbb21beedffae02a692718d08651b0..80e037bce812da2d5a862dcaaa98d0c7895ab24b 100644 (file)
@@ -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) => {
index b86153525047e2b8e53a6937629582cfc0390ce1..9410d0194c32ee34a634127388163e99edc38fce 100644 (file)
@@ -26,7 +26,7 @@
 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};
@@ -1832,13 +1832,10 @@ pub fn parse_bottom_expr(&self) -> @Expr {
                 }
             }
             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) {
index 6b3a95a14f8e6cb87b13fe05aaaff446b81d838a..fa00b536837c5b212a37a5233c94257cfc10875f 100644 (file)
@@ -456,7 +456,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
@@ -606,7 +606,7 @@ pub enum Keyword {
         Impl,
         In,
         Let,
-        __Log,
+        __LogLevel,
         Loop,
         Match,
         Mod,
@@ -651,7 +651,7 @@ pub fn to_ident(&self) -> Ident {
                 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 },
index 282b66b2c59ef61cf9671a1c4a71b44261690a08..ca0ff81b65b76b472ff6572ef5d27a911413552b 100644 (file)
@@ -1414,13 +1414,9 @@ fn print_field(s: @ps, field: &ast::Field) {
           _ => ()
         }
       }
-      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) => {
index 191b4509a80b32881b1d525d9f396616059530f7..ea8edf0b3d1529156bb3d67e0d586d05f81121e8 100644 (file)
@@ -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())