]> git.proxmox.com Git - rustc.git/blob - src/librustc_borrowck/borrowck/mir/mod.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc_borrowck / borrowck / mir / mod.rs
1 // Copyright 2012-2016 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 use borrowck::BorrowckCtxt;
12
13 use syntax::ast;
14 use syntax::codemap::Span;
15
16 use rustc::hir;
17 use rustc::hir::intravisit::{FnKind};
18
19 use rustc::mir::repr::{BasicBlock, BasicBlockData, Mir, Statement, Terminator};
20
21 mod abs_domain;
22 mod dataflow;
23 mod gather_moves;
24 mod graphviz;
25
26 use self::dataflow::{Dataflow, DataflowState};
27 use self::gather_moves::{MoveData};
28
29 pub fn borrowck_mir<'b, 'a: 'b, 'tcx: 'a>(
30 bcx: &'b mut BorrowckCtxt<'a, 'tcx>,
31 fk: FnKind,
32 _decl: &hir::FnDecl,
33 mir: &'a Mir<'tcx>,
34 body: &hir::Block,
35 _sp: Span,
36 id: ast::NodeId,
37 attributes: &[ast::Attribute]) {
38 match fk {
39 FnKind::ItemFn(name, _, _, _, _, _, _) |
40 FnKind::Method(name, _, _, _) => {
41 debug!("borrowck_mir({}) UNIMPLEMENTED", name);
42 }
43 FnKind::Closure(_) => {
44 debug!("borrowck_mir closure (body.id={}) UNIMPLEMENTED", body.id);
45 }
46 }
47
48 let mut mbcx = MirBorrowckCtxt {
49 bcx: bcx,
50 mir: mir,
51 node_id: id,
52 attributes: attributes,
53 flow_state: DataflowState::new_move_analysis(mir, bcx.tcx),
54 };
55
56 for bb in mir.all_basic_blocks() {
57 mbcx.process_basic_block(bb);
58 }
59
60 mbcx.dataflow();
61
62 debug!("borrowck_mir done");
63 }
64
65 pub struct MirBorrowckCtxt<'b, 'a: 'b, 'tcx: 'a> {
66 bcx: &'b mut BorrowckCtxt<'a, 'tcx>,
67 mir: &'b Mir<'tcx>,
68 node_id: ast::NodeId,
69 attributes: &'b [ast::Attribute],
70 flow_state: DataflowState<MoveData<'tcx>>,
71 }
72
73 impl<'b, 'a: 'b, 'tcx: 'a> MirBorrowckCtxt<'b, 'a, 'tcx> {
74 fn process_basic_block(&mut self, bb: BasicBlock) {
75 let &BasicBlockData { ref statements, ref terminator, is_cleanup: _ } =
76 self.mir.basic_block_data(bb);
77 for stmt in statements {
78 self.process_statement(bb, stmt);
79 }
80
81 self.process_terminator(bb, terminator);
82 }
83
84 fn process_statement(&mut self, bb: BasicBlock, stmt: &Statement<'tcx>) {
85 debug!("MirBorrowckCtxt::process_statement({:?}, {:?}", bb, stmt);
86 }
87
88 fn process_terminator(&mut self, bb: BasicBlock, term: &Option<Terminator<'tcx>>) {
89 debug!("MirBorrowckCtxt::process_terminator({:?}, {:?})", bb, term);
90 }
91 }