1 // Copyright 2012-2015 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.
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.
11 //! Code for debugging the dep-graph.
13 use super::dep_node::DepNode;
14 use std::error::Error;
16 /// A dep-node filter goes from a user-defined string to a query over
17 /// nodes. Right now the format is like this:
21 /// where the format-string of the dep-node must contain `x`, `y`, and
24 pub struct DepNodeFilter {
29 pub fn new(text: &str) -> Self {
31 text: text.trim().to_string()
35 /// True if all nodes always pass the filter.
36 pub fn accepts_all(&self) -> bool {
40 /// Tests whether `node` meets the filter, returning true if so.
41 pub fn test(&self, node: &DepNode) -> bool {
42 let debug_str = format!("{:?}", node);
45 .all(|f| debug_str.contains(f))
49 /// A filter like `F -> G` where `F` and `G` are valid dep-node
50 /// filters. This can be used to test the source/target independently.
51 pub struct EdgeFilter {
52 pub source: DepNodeFilter,
53 pub target: DepNodeFilter,
57 pub fn new(test: &str) -> Result<EdgeFilter, Box<Error>> {
58 let parts: Vec<_> = test.split("->").collect();
60 Err(format!("expected a filter like `a&b -> c&d`, not `{}`", test).into())
63 source: DepNodeFilter::new(parts[0]),
64 target: DepNodeFilter::new(parts[1]),
73 self.source.test(source) && self.target.test(target)