use middle::cfg::*;
use middle::def::Def;
use middle::pat_util;
-use middle::ty;
+use middle::ty::{self, TyCtxt};
use syntax::ast;
use syntax::ptr::P;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
struct CFGBuilder<'a, 'tcx: 'a> {
- tcx: &'a ty::ctxt<'tcx>,
+ tcx: &'a TyCtxt<'tcx>,
graph: CFGGraph,
fn_exit: CFGIndex,
loop_scopes: Vec<LoopScope>,
break_index: CFGIndex, // where to go on a `break
}
-pub fn construct(tcx: &ty::ctxt,
+pub fn construct(tcx: &TyCtxt,
blk: &hir::Block) -> CFG {
let mut graph = graph::Graph::new();
let entry = graph.add_node(CFGNodeData::Entry);
fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {
match pat.node {
- hir::PatIdent(_, _, None) |
- hir::PatEnum(_, None) |
- hir::PatQPath(..) |
- hir::PatLit(..) |
- hir::PatRange(..) |
- hir::PatWild => {
+ PatKind::Ident(_, _, None) |
+ PatKind::TupleStruct(_, None) |
+ PatKind::Path(..) |
+ PatKind::QPath(..) |
+ PatKind::Lit(..) |
+ PatKind::Range(..) |
+ PatKind::Wild => {
self.add_ast_node(pat.id, &[pred])
}
- hir::PatBox(ref subpat) |
- hir::PatRegion(ref subpat, _) |
- hir::PatIdent(_, _, Some(ref subpat)) => {
+ PatKind::Box(ref subpat) |
+ PatKind::Ref(ref subpat, _) |
+ PatKind::Ident(_, _, Some(ref subpat)) => {
let subpat_exit = self.pat(&subpat, pred);
self.add_ast_node(pat.id, &[subpat_exit])
}
- hir::PatEnum(_, Some(ref subpats)) |
- hir::PatTup(ref subpats) => {
+ PatKind::TupleStruct(_, Some(ref subpats)) |
+ PatKind::Tup(ref subpats) => {
let pats_exit = self.pats_all(subpats.iter(), pred);
self.add_ast_node(pat.id, &[pats_exit])
}
- hir::PatStruct(_, ref subpats, _) => {
+ PatKind::Struct(_, ref subpats, _) => {
let pats_exit =
self.pats_all(subpats.iter().map(|f| &f.node.pat), pred);
self.add_ast_node(pat.id, &[pats_exit])
}
- hir::PatVec(ref pre, ref vec, ref post) => {
+ PatKind::Vec(ref pre, ref vec, ref post) => {
let pre_exit = self.pats_all(pre.iter(), pred);
let vec_exit = self.pats_all(vec.iter(), pre_exit);
let post_exit = self.pats_all(post.iter(), vec_exit);
self.call(expr, pred, &l, Some(&**r).into_iter())
}
- hir::ExprRange(ref start, ref end) => {
- let fields = start.as_ref().map(|e| &**e).into_iter()
- .chain(end.as_ref().map(|e| &**e));
- self.straightline(expr, pred, fields)
- }
-
hir::ExprUnary(_, ref e) if self.tcx.is_method_call(expr.id) => {
self.call(expr, pred, &e, None::<hir::Expr>.iter())
}
self.straightline(expr, pred, Some(&**e).into_iter())
}
- hir::ExprInlineAsm(ref inline_asm) => {
- let inputs = inline_asm.inputs.iter();
- let outputs = inline_asm.outputs.iter();
- let post_inputs = self.exprs(inputs.map(|a| {
- debug!("cfg::construct InlineAsm id:{} input:{:?}", expr.id, a);
- let &(_, ref expr) = a;
- &**expr
- }), pred);
- let post_outputs = self.exprs(outputs.map(|a| {
- debug!("cfg::construct InlineAsm id:{} output:{:?}", expr.id, a);
- &*a.expr
- }), post_inputs);
- self.add_ast_node(expr.id, &[post_outputs])
+ hir::ExprInlineAsm(_, ref outputs, ref inputs) => {
+ let post_outputs = self.exprs(outputs.iter().map(|e| &**e), pred);
+ let post_inputs = self.exprs(inputs.iter().map(|e| &**e), post_outputs);
+ self.add_ast_node(expr.id, &[post_inputs])
}
hir::ExprClosure(..) |