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.
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 //! Module that constructs a control-flow graph representing an item.
12 //! Uses `Graph` as the underlying representation.
17 use util::nodemap::NodeMap;
23 pub exit_map: NodeMap<CFGIndex>,
30 pub struct CFGNodeData {
34 pub struct CFGEdgeData {
35 pub exiting_scopes: Vec<ast::NodeId>
38 pub type CFGIndex = graph::NodeIndex;
40 pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
42 pub type CFGNode = graph::Node<CFGNodeData>;
44 pub type CFGEdge = graph::Edge<CFGEdgeData>;
47 pub fn new(tcx: &ty::ctxt,
48 blk: &ast::Block) -> CFG {
49 construct::construct(tcx, blk)
52 pub fn node_is_reachable(&self, id: ast::NodeId) -> bool {
53 self.graph.depth_traverse(self.entry).any(|node| node.id == id)