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.
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 use borrowck
::BorrowckCtxt
;
14 use syntax
::codemap
::Span
;
17 use rustc
::hir
::intravisit
::{FnKind}
;
19 use rustc
::mir
::repr
::{BasicBlock, BasicBlockData, Mir, Statement, Terminator}
;
26 use self::dataflow
::{Dataflow, DataflowState}
;
27 use self::gather_moves
::{MoveData}
;
29 pub fn borrowck_mir
<'b
, 'a
: 'b
, 'tcx
: 'a
>(
30 bcx
: &'b
mut BorrowckCtxt
<'a
, 'tcx
>,
37 attributes
: &[ast
::Attribute
]) {
39 FnKind
::ItemFn(name
, _
, _
, _
, _
, _
, _
) |
40 FnKind
::Method(name
, _
, _
, _
) => {
41 debug
!("borrowck_mir({}) UNIMPLEMENTED", name
);
43 FnKind
::Closure(_
) => {
44 debug
!("borrowck_mir closure (body.id={}) UNIMPLEMENTED", body
.id
);
48 let mut mbcx
= MirBorrowckCtxt
{
52 attributes
: attributes
,
53 flow_state
: DataflowState
::new_move_analysis(mir
, bcx
.tcx
),
56 for bb
in mir
.all_basic_blocks() {
57 mbcx
.process_basic_block(bb
);
62 debug
!("borrowck_mir done");
65 pub struct MirBorrowckCtxt
<'b
, 'a
: 'b
, 'tcx
: 'a
> {
66 bcx
: &'b
mut BorrowckCtxt
<'a
, 'tcx
>,
69 attributes
: &'b
[ast
::Attribute
],
70 flow_state
: DataflowState
<MoveData
<'tcx
>>,
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
);
81 self.process_terminator(bb
, terminator
);
84 fn process_statement(&mut self, bb
: BasicBlock
, stmt
: &Statement
<'tcx
>) {
85 debug
!("MirBorrowckCtxt::process_statement({:?}, {:?}", bb
, stmt
);
88 fn process_terminator(&mut self, bb
: BasicBlock
, term
: &Option
<Terminator
<'tcx
>>) {
89 debug
!("MirBorrowckCtxt::process_terminator({:?}, {:?})", bb
, term
);