]>
git.proxmox.com Git - rustc.git/blob - src/librustc/middle/cfg/mod.rs
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.
14 use rustc_data_structures
::graph
;
27 #[derive(Copy, Clone, Debug, PartialEq)]
28 pub enum CFGNodeData
{
37 pub fn id(&self) -> ast
::NodeId
{
38 if let CFGNodeData
::AST(id
) = *self {
47 pub struct CFGEdgeData
{
48 pub exiting_scopes
: Vec
<ast
::NodeId
>
51 pub type CFGIndex
= graph
::NodeIndex
;
53 pub type CFGGraph
= graph
::Graph
<CFGNodeData
, CFGEdgeData
>;
55 pub type CFGNode
= graph
::Node
<CFGNodeData
>;
57 pub type CFGEdge
= graph
::Edge
<CFGEdgeData
>;
60 pub fn new(tcx
: &ty
::ctxt
,
61 blk
: &ast
::Block
) -> CFG
{
62 construct
::construct(tcx
, blk
)
65 pub fn node_is_reachable(&self, id
: ast
::NodeId
) -> bool
{
66 self.graph
.depth_traverse(self.entry
).any(|node
| node
.id() == id
)