about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2014-04-21 19:21:53 -0400
committerNiko Matsakis <niko@alum.mit.edu>2014-04-24 19:59:49 -0400
commit96dfed2b62c6e84a542f9a170133ec528e2191c2 (patch)
tree858758be479d75ed97b70014ce19927fa750280a /src/libsyntax
parent77a975df85694a4de07abb5f99f1159799b1160d (diff)
downloadrust-96dfed2b62c6e84a542f9a170133ec528e2191c2.tar.gz
rust-96dfed2b62c6e84a542f9a170133ec528e2191c2.zip
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.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_util.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index adb97af7490..0fb9a2491db 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -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,