Pre-step towards issue #12624 and others: Introduce ExprUseVisitor, remove the

moves computation. ExprUseVisitor is a visitor that walks the AST for a
function and calls a delegate to inform it where borrows, copies, and moves
occur.

In this patch, I rewrite the gather_loans visitor to use ExprUseVisitor, but in
future patches, I think we could rewrite regionck, check_loans, and possibly
other passes to use it as well. This would refactor the repeated code between
those places that tries to determine where copies/moves/etc occur.
This commit is contained in:
Niko Matsakis
2014-04-21 19:21:53 -04:00
parent 77a975df85
commit 96dfed2b62
27 changed files with 1271 additions and 1630 deletions

View File

@@ -469,7 +469,6 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
visit::walk_pat(self, pattern, env)
}
fn visit_expr(&mut self, expression: &Expr, env: ()) {
self.operation.visit_id(expression.id);
visit::walk_expr(self, expression, env)
@@ -590,6 +589,30 @@ pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange {
visitor.result.get()
}
pub fn compute_id_range_for_fn_body(fk: &visit::FnKind,
decl: &FnDecl,
body: &Block,
sp: Span,
id: NodeId)
-> IdRange
{
/*!
* Computes the id range for a single fn body,
* ignoring nested items.
*/
let visitor = IdRangeComputingVisitor {
result: Cell::new(IdRange::max())
};
let mut id_visitor = IdVisitor {
operation: &visitor,
pass_through_items: false,
visited_outermost: false,
};
id_visitor.visit_fn(fk, decl, body, sp, id, ());
visitor.result.get()
}
pub fn is_item_impl(item: @ast::Item) -> bool {
match item.node {
ItemImpl(..) => true,