Skip to content

Commit 9a9c84f

Browse files
committed
auto merge of #7688 : nikomatsakis/rust/issue-6298-dataflow-graph, r=graydon
This patch is a step towards #6298. It extracts the graph abstraction from region inference into a library, and then ports the region inference to use it. It also adds a control-flow graph abstraction that will eventually be used by dataflow. The CFG code is not yet used, but I figured better to add it so as to make later rebasing etc easier.
2 parents 4478ded + 3b91181 commit 9a9c84f

File tree

8 files changed

+1178
-195
lines changed

8 files changed

+1178
-195
lines changed

src/librustc/middle/cfg/construct.rs

+523
Large diffs are not rendered by default.

src/librustc/middle/cfg/mod.rs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
use middle::graph;
19+
use middle::ty;
20+
use middle::typeck;
21+
use std::hashmap::HashMap;
22+
use syntax::ast;
23+
use syntax::opt_vec::OptVec;
24+
25+
mod construct;
26+
27+
pub struct CFG {
28+
exit_map: HashMap<ast::node_id, CFGIndex>,
29+
graph: CFGGraph,
30+
entry: CFGIndex,
31+
exit: CFGIndex,
32+
}
33+
34+
pub struct CFGNodeData {
35+
id: ast::node_id
36+
}
37+
38+
pub struct CFGEdgeData {
39+
exiting_scopes: OptVec<ast::node_id>
40+
}
41+
42+
pub type CFGIndex = graph::NodeIndex;
43+
44+
pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
45+
46+
pub type CFGNode = graph::Node<CFGNodeData>;
47+
48+
pub type CFGEdge = graph::Edge<CFGEdgeData>;
49+
50+
pub struct CFGIndices {
51+
entry: CFGIndex,
52+
exit: CFGIndex,
53+
}
54+
55+
impl CFG {
56+
pub fn new(tcx: ty::ctxt,
57+
method_map: typeck::method_map,
58+
blk: &ast::blk) -> CFG {
59+
construct::construct(tcx, method_map, blk)
60+
}
61+
}

0 commit comments

Comments
 (0)