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 /*!
12
13 Module that constructs a control-flow graph representing an item.
14 Uses `Graph` as the underlying representation.
15
16 */
17
18 #![allow(dead_code)] // still a WIP, #6298
19
20 use middle::graph;
21 use middle::ty;
22 use middle::typeck;
23 use syntax::ast;
24 use util::nodemap::NodeMap;
25
26 mod construct;
27
28 pub struct CFG {
29 exit_map: NodeMap<CFGIndex>,
30 graph: CFGGraph,
31 entry: CFGIndex,
32 exit: CFGIndex,
33 }
34
35 pub struct CFGNodeData {
36 id: ast::NodeId
37 }
38
39 pub struct CFGEdgeData {
40 exiting_scopes: Vec<ast::NodeId>
41 }
42
43 pub type CFGIndex = graph::NodeIndex;
44
45 pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
46
47 pub type CFGNode = graph::Node<CFGNodeData>;
48
49 pub type CFGEdge = graph::Edge<CFGEdgeData>;
50
51 pub struct CFGIndices {
52 entry: CFGIndex,
53 exit: CFGIndex,
54 }
55
56 impl CFG {
57 pub fn new(tcx: &ty::ctxt,
58 method_map: typeck::MethodMap,
59 blk: &ast::Block) -> CFG {
60 construct::construct(tcx, method_map, blk)
61 }
62 }
librustc/middle/cfg/mod.rs:42:1-42:1 -NK_AS_STR_TODO- definition:
pub type CFGIndex = graph::NodeIndex;
pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
pub type CFGNode = graph::Node<CFGNodeData>;
references:- 38librustc/middle/cfg/construct.rs:
librustc/middle/cfg/mod.rs:34:1-34:1 -struct- definition:
pub struct CFGNodeData {
id: ast::NodeId
}
references:- 345: pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
47: pub type CFGNode = graph::Node<CFGNodeData>;
librustc/middle/cfg/construct.rs:
460: assert!(!self.exit_map.contains_key(&id));
461: let node = self.graph.add_node(CFGNodeData {id: id});
462: self.exit_map.insert(id, node);
librustc/middle/cfg/mod.rs:38:1-38:1 -struct- definition:
pub struct CFGEdgeData {
exiting_scopes: Vec<ast::NodeId>
}
references:- 4librustc/middle/cfg/construct.rs:
471: target: CFGIndex) {
472: let data = CFGEdgeData {exiting_scopes: vec!() };
473: self.graph.add_edge(source, target, data);
librustc/middle/cfg/mod.rs:
49: pub type CFGEdge = graph::Edge<CFGEdgeData>;
librustc/middle/cfg/construct.rs:
480: to_index: CFGIndex) {
481: let mut data = CFGEdgeData {exiting_scopes: vec!() };
482: let mut scope_id = from_expr.id;
librustc/middle/cfg/mod.rs:27:1-27:1 -struct- definition:
pub struct CFG {
exit_map: NodeMap<CFGIndex>,
graph: CFGGraph,
references:- 4librustc/middle/cfg/construct.rs:
45: let CFGBuilder {exit_map, graph, ..} = cfg_builder;
46: CFG {exit_map: exit_map,
47: graph: graph,
librustc/middle/cfg/mod.rs:
58: method_map: typeck::MethodMap,
59: blk: &ast::Block) -> CFG {
60: construct::construct(tcx, method_map, blk)
librustc/middle/cfg/construct.rs:
34: method_map: typeck::MethodMap,
35: blk: &ast::Block) -> CFG {
36: let mut cfg_builder = CFGBuilder {
librustc/middle/cfg/mod.rs:
56: impl CFG {
57: pub fn new(tcx: &ty::ctxt,
librustc/middle/cfg/mod.rs:44:1-44:1 -NK_AS_STR_TODO- definition:
pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
pub type CFGNode = graph::Node<CFGNodeData>;
pub type CFGEdge = graph::Edge<CFGEdgeData>;
references:- 2librustc/middle/cfg/construct.rs:
22: exit_map: NodeMap<CFGIndex>,
23: graph: CFGGraph,
24: loop_scopes: Vec<LoopScope> ,
librustc/middle/cfg/mod.rs:
29: exit_map: NodeMap<CFGIndex>,
30: graph: CFGGraph,
31: entry: CFGIndex,