1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(non_camel_case_types)]
12
13 use syntax::ast;
14 use syntax::visit;
15 use syntax::visit::Visitor;
16
17 use time;
18
19 pub fn time<T, U>(do_it: bool, what: &str, u: U, f: |U| -> T) -> T {
20 local_data_key!(depth: uint);
21 if !do_it { return f(u); }
22
23 let old = depth.get().map(|d| *d).unwrap_or(0);
24 depth.replace(Some(old + 1));
25
26 let start = time::precise_time_s();
27 let rv = f(u);
28 let end = time::precise_time_s();
29
30 println!("{}time: {:3.3f} s\t{}", " ".repeat(old), end - start, what);
31 depth.replace(Some(old));
32
33 rv
34 }
35
36 pub fn indent<R>(op: || -> R) -> R {
37 // Use in conjunction with the log post-processor like `src/etc/indenter`
38 // to make debug output more readable.
39 debug!(">>");
40 let r = op();
41 debug!("<< (Result = {:?})", r);
42 r
43 }
44
45 pub struct _indenter {
46 _i: (),
47 }
48
49 impl Drop for _indenter {
50 fn drop(&mut self) { debug!("<<"); }
51 }
52
53 pub fn _indenter(_i: ()) -> _indenter {
54 _indenter {
55 _i: ()
56 }
57 }
58
59 pub fn indenter() -> _indenter {
60 debug!(">>");
61 _indenter(())
62 }
63
64 struct LoopQueryVisitor<'a> {
65 p: |&ast::Expr_|: 'a -> bool,
66 flag: bool,
67 }
68
69 impl<'a> Visitor<()> for LoopQueryVisitor<'a> {
70 fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
71 self.flag |= (self.p)(&e.node);
72 match e.node {
73 // Skip inner loops, since a break in the inner loop isn't a
74 // break inside the outer loop
75 ast::ExprLoop(..) | ast::ExprWhile(..) => {}
76 _ => visit::walk_expr(self, e, ())
77 }
78 }
79 }
80
81 // Takes a predicate p, returns true iff p is true for any subexpressions
82 // of b -- skipping any inner loops (loop, while, loop_body)
83 pub fn loop_query(b: &ast::Block, p: |&ast::Expr_| -> bool) -> bool {
84 let mut v = LoopQueryVisitor {
85 p: p,
86 flag: false,
87 };
88 visit::walk_block(&mut v, b, ());
89 return v.flag;
90 }
91
92 struct BlockQueryVisitor<'a> {
93 p: |&ast::Expr|: 'a -> bool,
94 flag: bool,
95 }
96
97 impl<'a> Visitor<()> for BlockQueryVisitor<'a> {
98 fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
99 self.flag |= (self.p)(e);
100 visit::walk_expr(self, e, ())
101 }
102 }
103
104 // Takes a predicate p, returns true iff p is true for any subexpressions
105 // of b -- skipping any inner loops (loop, while, loop_body)
106 pub fn block_query(b: ast::P<ast::Block>, p: |&ast::Expr| -> bool) -> bool {
107 let mut v = BlockQueryVisitor {
108 p: p,
109 flag: false,
110 };
111 visit::walk_block(&mut v, b, ());
112 return v.flag;
113 }
librustc/util/common.rs:91:1-91:1 -struct- definition:
struct BlockQueryVisitor<'a> {
p: |&ast::Expr|: 'a -> bool,
flag: bool,
references:- 297: impl<'a> Visitor<()> for BlockQueryVisitor<'a> {
98: fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
--
106: pub fn block_query(b: ast::P<ast::Block>, p: |&ast::Expr| -> bool) -> bool {
107: let mut v = BlockQueryVisitor {
108: p: p,
librustc/util/common.rs:44:1-44:1 -struct- definition:
pub struct _indenter {
_i: (),
}
references:- 453: pub fn _indenter(_i: ()) -> _indenter {
54: _indenter {
55: _i: ()
--
59: pub fn indenter() -> _indenter {
60: debug!(">>");
librustc/util/common.rs:63:1-63:1 -struct- definition:
struct LoopQueryVisitor<'a> {
p: |&ast::Expr_|: 'a -> bool,
flag: bool,
references:- 269: impl<'a> Visitor<()> for LoopQueryVisitor<'a> {
70: fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
--
83: pub fn loop_query(b: &ast::Block, p: |&ast::Expr_| -> bool) -> bool {
84: let mut v = LoopQueryVisitor {
85: p: p,
librustc/util/common.rs:58:1-58:1 -fn- definition:
pub fn indenter() -> _indenter {
debug!(">>");
_indenter(())
references:- 32librustc/middle/trans/expr.rs:
librustc/middle/trans/base.rs:
librustc/middle/trans/_match.rs:
librustc/middle/trans/meth.rs:
librustc/middle/ty.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/liveness.rs:
librustc/middle/trans/_match.rs:
librustc/util/common.rs:18:1-18:1 -fn- definition:
pub fn time<T, U>(do_it: bool, what: &str, u: U, f: |U| -> T) -> T {
local_data_key!(depth: uint);
if !do_it { return f(u); }
references:- 49librustc/middle/typeck/mod.rs:
librustc/back/link.rs:
librustc/back/lto.rs:
librustc/driver/driver.rs:
librustc/back/link.rs:
librustc/util/common.rs:35:1-35:1 -fn- definition:
pub fn indent<R>(op: || -> R) -> R {
// Use in conjunction with the log post-processor like `src/etc/indenter`
// to make debug output more readable.
references:- 10librustc/middle/typeck/infer/mod.rs:
412: debug!("mk_coercety({} -> {})", a.inf_str(cx), b.inf_str(cx));
413: indent(|| {
414: cx.commit(|| {
--
544: debug!("commit()");
545: indent(|| {
546: let r = self.try(|| f());
librustc/middle/typeck/infer/combine.rs:
331: let sub = this.sub();
332: indent(|| {
333: this.infcx().try(|| {
librustc/middle/typeck/infer/resolve.rs:
144: self.err = None;
145: let resolved = indent(|| self.resolve_region(orig) );
146: match self.err {
librustc/middle/typeck/infer/mod.rs:
572: debug!("probe()");
573: indent(|| {
574: let snapshot = self.start_snapshot();