about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-26 08:26:14 -0700
committerbors <bors@rust-lang.org>2013-08-26 08:26:14 -0700
commitc6eb3ec30c945f22acac5dece7c22b0881af4be2 (patch)
treec77579dc668a715f18763baaec44e33f68433829
parent5fc211accf9b08d2e5dd8edd3c52d484e3910499 (diff)
parent2f82d89b2869adb4b1b17d19303676fa635d5df3 (diff)
downloadrust-c6eb3ec30c945f22acac5dece7c22b0881af4be2.tar.gz
rust-c6eb3ec30c945f22acac5dece7c22b0881af4be2.zip
auto merge of #8758 : pnkfelix/rust/fsk-more-oldvisit-ports, r=pnkfelix
Further followup on #7081.

There still remains writeback.rs, but I want to wait to investigate that one because I've seen `make check` issues with it in the past.
-rw-r--r--src/librustc/metadata/creader.rs22
-rw-r--r--src/librustc/middle/lint.rs22
-rw-r--r--src/librustc/middle/moves.rs70
-rw-r--r--src/librustc/middle/stack_check.rs57
-rw-r--r--src/librustc/middle/typeck/check/vtable.rs29
5 files changed, 123 insertions, 77 deletions
diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs
index c8c4a396c87..942d5f1373d 100644
--- a/src/librustc/metadata/creader.rs
+++ b/src/librustc/metadata/creader.rs
@@ -25,7 +25,7 @@ use syntax::codemap::{span, dummy_sp};
 use syntax::diagnostic::span_handler;
 use syntax::parse::token;
 use syntax::parse::token::ident_interner;
-use syntax::oldvisit;
+use syntax::visit;
 
 // Traverses an AST, reading all the information about use'd crates and extern
 // libraries necessary for later resolving, typechecking, linking, etc.
@@ -46,17 +46,25 @@ pub fn read_crates(diag: @mut span_handler,
         next_crate_num: 1,
         intr: intr
     };
-    let v =
-        oldvisit::mk_simple_visitor(@oldvisit::SimpleVisitor {
-            visit_view_item: |a| visit_view_item(e, a),
-            visit_item: |a| visit_item(e, a),
-            .. *oldvisit::default_simple_visitor()});
+    let mut v = ReadCrateVisitor{ e:e };
     visit_crate(e, crate);
-    oldvisit::visit_crate(crate, ((), v));
+    visit::walk_crate(&mut v, crate, ());
     dump_crates(*e.crate_cache);
     warn_if_multiple_versions(e, diag, *e.crate_cache);
 }
 
+struct ReadCrateVisitor { e:@mut Env }
+impl visit::Visitor<()> for ReadCrateVisitor {
+    fn visit_view_item(&mut self, a:&ast::view_item, _:()) {
+        visit_view_item(self.e, a);
+        visit::walk_view_item(self, a, ());
+    }
+    fn visit_item(&mut self, a:@ast::item, _:()) {
+        visit_item(self.e, a);
+        visit::walk_item(self, a, ());
+    }
+}
+
 #[deriving(Clone)]
 struct cache_entry {
     cnum: int,
diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs
index eb42724e800..5a2e3a4b760 100644
--- a/src/librustc/middle/lint.rs
+++ b/src/librustc/middle/lint.rs
@@ -56,7 +56,7 @@ use syntax::visit::Visitor;
  * lint attributes.
  *
  * At each node of the ast which can modify lint attributes, all known lint
- * passes are also applied.  Each lint pass is an oldvisit::vt<()> structure.
+ * passes are also applied.  Each lint pass is a visit::Visitor implementator.
  * The visitors are constructed via the lint_*() functions below. There are
  * also some lint checks which operate directly on ast nodes (such as
  * @ast::item), and those are organized as check_item_*(). Each visitor added
@@ -508,7 +508,7 @@ impl Context {
         }
     }
 
-    fn add_oldvisit_lint(&mut self, v: @mut OuterLint) {
+    fn add_old_lint(&mut self, v: @mut OuterLint) {
         self.visitors.push(OldVisitor(v, v.inner_variant()));
     }
 
@@ -547,7 +547,7 @@ impl Context {
                     }
                 }
             }
-            // Can't use oldvisit::visit_method_helper because the
+            // Can't use visit::walk_method_helper because the
             // item_stopping_visitor has overridden visit_fn(&fk_method(... ))
             // to be a no-op, so manually invoke visit_fn.
             Method(m) => {
@@ -1450,14 +1450,14 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::Crate) {
     }
 
     // Register each of the lint passes with the context
-    cx.add_oldvisit_lint(lint_while_true());
-    cx.add_oldvisit_lint(lint_path_statement());
-    cx.add_oldvisit_lint(lint_heap());
-    cx.add_oldvisit_lint(lint_type_limits());
-    cx.add_oldvisit_lint(lint_unused_unsafe());
-    cx.add_oldvisit_lint(lint_unused_mut());
-    cx.add_oldvisit_lint(lint_unnecessary_allocations());
-    cx.add_oldvisit_lint(lint_missing_doc());
+    cx.add_old_lint(lint_while_true());
+    cx.add_old_lint(lint_path_statement());
+    cx.add_old_lint(lint_heap());
+    cx.add_old_lint(lint_type_limits());
+    cx.add_old_lint(lint_unused_unsafe());
+    cx.add_old_lint(lint_unused_mut());
+    cx.add_old_lint(lint_unnecessary_allocations());
+    cx.add_old_lint(lint_missing_doc());
     cx.add_lint(lint_session(cx));
 
     // Actually perform the lint checks (iterating the ast)
diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs
index 0c553843cd1..7b3fad0b36b 100644
--- a/src/librustc/middle/moves.rs
+++ b/src/librustc/middle/moves.rs
@@ -139,8 +139,8 @@ use std::at_vec;
 use std::hashmap::{HashSet, HashMap};
 use syntax::ast::*;
 use syntax::ast_util;
-use syntax::oldvisit;
-use syntax::oldvisit::vt;
+use syntax::visit;
+use syntax::visit::Visitor;
 use syntax::codemap::span;
 
 #[deriving(Encodable, Decodable)]
@@ -190,16 +190,26 @@ enum UseMode {
     Read         // Read no matter what the type.
 }
 
+struct ComputeModesVisitor;
+
+impl visit::Visitor<VisitContext> for ComputeModesVisitor {
+    fn visit_fn(&mut self, fk:&visit::fn_kind, fd:&fn_decl,
+                b:&Block, s:span, n:NodeId, e:VisitContext) {
+        compute_modes_for_fn(*self, fk, fd, b, s, n, e);
+    }
+    fn visit_expr(&mut self, ex:@expr, e:VisitContext) {
+        compute_modes_for_expr(*self, ex, e);
+    }
+    fn visit_local(&mut self, l:@Local, e:VisitContext) {
+        compute_modes_for_local(*self, l, e);
+    }
+}
+
 pub fn compute_moves(tcx: ty::ctxt,
                      method_map: method_map,
                      crate: &Crate) -> MoveMaps
 {
-    let visitor = oldvisit::mk_vt(@oldvisit::Visitor {
-        visit_fn: compute_modes_for_fn,
-        visit_expr: compute_modes_for_expr,
-        visit_local: compute_modes_for_local,
-        .. *oldvisit::default_visitor()
-    });
+    let mut visitor = ComputeModesVisitor;
     let visit_cx = VisitContext {
         tcx: tcx,
         method_map: method_map,
@@ -209,7 +219,7 @@ pub fn compute_moves(tcx: ty::ctxt,
             moved_variables_set: @mut HashSet::new()
         }
     };
-    oldvisit::visit_crate(crate, (visit_cx, visitor));
+    visit::walk_crate(&mut visitor, crate, visit_cx);
     return visit_cx.move_maps;
 }
 
@@ -227,43 +237,44 @@ pub fn moved_variable_node_id_from_def(def: def) -> Option<NodeId> {
 ///////////////////////////////////////////////////////////////////////////
 // Expressions
 
-fn compute_modes_for_local<'a>(local: @Local,
-                               (cx, v): (VisitContext,
-                                         vt<VisitContext>)) {
+fn compute_modes_for_local<'a>(v: ComputeModesVisitor,
+                               local: @Local,
+                               cx: VisitContext) {
     cx.use_pat(local.pat);
     for &init in local.init.iter() {
         cx.use_expr(init, Read, v);
     }
 }
 
-fn compute_modes_for_fn(fk: &oldvisit::fn_kind,
+fn compute_modes_for_fn(v: ComputeModesVisitor,
+                        fk: &visit::fn_kind,
                         decl: &fn_decl,
                         body: &Block,
                         span: span,
                         id: NodeId,
-                        (cx, v): (VisitContext,
-                                  vt<VisitContext>)) {
+                        cx: VisitContext) {
+    let mut v = v;
     for a in decl.inputs.iter() {
         cx.use_pat(a.pat);
     }
-    oldvisit::visit_fn(fk, decl, body, span, id, (cx, v));
+    visit::walk_fn(&mut v, fk, decl, body, span, id, cx);
 }
 
-fn compute_modes_for_expr(expr: @expr,
-                          (cx, v): (VisitContext,
-                                    vt<VisitContext>))
+fn compute_modes_for_expr(v: ComputeModesVisitor,
+                          expr: @expr,
+                          cx: VisitContext)
 {
     cx.consume_expr(expr, v);
 }
 
 impl VisitContext {
-    pub fn consume_exprs(&self, exprs: &[@expr], visitor: vt<VisitContext>) {
+    pub fn consume_exprs(&self, exprs: &[@expr], visitor: ComputeModesVisitor) {
         for expr in exprs.iter() {
             self.consume_expr(*expr, visitor);
         }
     }
 
-    pub fn consume_expr(&self, expr: @expr, visitor: vt<VisitContext>) {
+    pub fn consume_expr(&self, expr: @expr, visitor: ComputeModesVisitor) {
         /*!
          * Indicates that the value of `expr` will be consumed,
          * meaning either copied or moved depending on its type.
@@ -281,7 +292,7 @@ impl VisitContext {
         };
     }
 
-    pub fn consume_block(&self, blk: &Block, visitor: vt<VisitContext>) {
+    pub fn consume_block(&self, blk: &Block, visitor: ComputeModesVisitor) {
         /*!
          * Indicates that the value of `blk` will be consumed,
          * meaning either copied or moved depending on its type.
@@ -290,7 +301,8 @@ impl VisitContext {
         debug!("consume_block(blk.id=%?)", blk.id);
 
         for stmt in blk.stmts.iter() {
-            (visitor.visit_stmt)(*stmt, (*self, visitor));
+            let mut v = visitor;
+            v.visit_stmt(*stmt, *self);
         }
 
         for tail_expr in blk.expr.iter() {
@@ -301,7 +313,7 @@ impl VisitContext {
     pub fn use_expr(&self,
                     expr: @expr,
                     expr_mode: UseMode,
-                    visitor: vt<VisitContext>) {
+                    visitor: ComputeModesVisitor) {
         /*!
          * Indicates that `expr` is used with a given mode.  This will
          * in turn trigger calls to the subcomponents of `expr`.
@@ -570,7 +582,7 @@ impl VisitContext {
                                    expr: &expr,
                                    receiver_expr: @expr,
                                    arg_exprs: &[@expr],
-                                   visitor: vt<VisitContext>)
+                                   visitor: ComputeModesVisitor)
                                    -> bool {
         if !self.method_map.contains_key(&expr.id) {
             return false;
@@ -587,7 +599,7 @@ impl VisitContext {
         return true;
     }
 
-    pub fn consume_arm(&self, arm: &arm, visitor: vt<VisitContext>) {
+    pub fn consume_arm(&self, arm: &arm, visitor: ComputeModesVisitor) {
         for pat in arm.pats.iter() {
             self.use_pat(*pat);
         }
@@ -630,21 +642,21 @@ impl VisitContext {
 
     pub fn use_receiver(&self,
                         receiver_expr: @expr,
-                        visitor: vt<VisitContext>) {
+                        visitor: ComputeModesVisitor) {
         self.use_fn_arg(receiver_expr, visitor);
     }
 
     pub fn use_fn_args(&self,
                        _: NodeId,
                        arg_exprs: &[@expr],
-                       visitor: vt<VisitContext>) {
+                       visitor: ComputeModesVisitor) {
         //! Uses the argument expressions.
         for arg_expr in arg_exprs.iter() {
             self.use_fn_arg(*arg_expr, visitor);
         }
     }
 
-    pub fn use_fn_arg(&self, arg_expr: @expr, visitor: vt<VisitContext>) {
+    pub fn use_fn_arg(&self, arg_expr: @expr, visitor: ComputeModesVisitor) {
         //! Uses the argument.
         self.consume_expr(arg_expr, visitor)
     }
diff --git a/src/librustc/middle/stack_check.rs b/src/librustc/middle/stack_check.rs
index 8837a9461ed..4266b051c68 100644
--- a/src/librustc/middle/stack_check.rs
+++ b/src/librustc/middle/stack_check.rs
@@ -22,7 +22,8 @@ use syntax::ast;
 use syntax::ast_map;
 use syntax::attr;
 use syntax::codemap::span;
-use visit = syntax::oldvisit;
+use syntax::visit;
+use syntax::visit::Visitor;
 use util::ppaux::Repr;
 
 #[deriving(Clone)]
@@ -31,44 +32,56 @@ struct Context {
     safe_stack: bool
 }
 
+struct StackCheckVisitor;
+
+impl Visitor<Context> for StackCheckVisitor {
+    fn visit_item(&mut self, i:@ast::item, e:Context) {
+        stack_check_item(*self, i, e);
+    }
+    fn visit_fn(&mut self, fk:&visit::fn_kind, fd:&ast::fn_decl,
+                b:&ast::Block, s:span, n:ast::NodeId, e:Context) {
+        stack_check_fn(*self, fk, fd, b, s, n, e);
+    }
+    fn visit_expr(&mut self, ex:@ast::expr, e:Context) {
+        stack_check_expr(*self, ex, e);
+    }
+}
+
 pub fn stack_check_crate(tcx: ty::ctxt,
                          crate: &ast::Crate) {
     let new_cx = Context {
         tcx: tcx,
         safe_stack: false
     };
-    let visitor = visit::mk_vt(@visit::Visitor {
-        visit_item: stack_check_item,
-        visit_fn: stack_check_fn,
-        visit_expr: stack_check_expr,
-        ..*visit::default_visitor()
-    });
-    visit::visit_crate(crate, (new_cx, visitor));
+    let mut visitor = StackCheckVisitor;
+    visit::walk_crate(&mut visitor, crate, new_cx);
 }
 
-fn stack_check_item(item: @ast::item,
-                    (in_cx, v): (Context, visit::vt<Context>)) {
+fn stack_check_item(v: StackCheckVisitor,
+                    item: @ast::item,
+                    in_cx: Context) {
+    let mut v = v;
     match item.node {
         ast::item_fn(_, ast::extern_fn, _, _, _) => {
             // an extern fn is already being called from C code...
             let new_cx = Context {safe_stack: true, ..in_cx};
-            visit::visit_item(item, (new_cx, v));
+            visit::walk_item(&mut v, item, new_cx);
         }
         ast::item_fn(*) => {
             let safe_stack = fixed_stack_segment(item.attrs);
             let new_cx = Context {safe_stack: safe_stack, ..in_cx};
-            visit::visit_item(item, (new_cx, v));
+            visit::walk_item(&mut v, item, new_cx);
         }
         ast::item_impl(_, _, _, ref methods) => {
             // visit_method() would make this nicer
             for &method in methods.iter() {
                 let safe_stack = fixed_stack_segment(method.attrs);
                 let new_cx = Context {safe_stack: safe_stack, ..in_cx};
-                visit::visit_method_helper(method, (new_cx, v));
+                visit::walk_method_helper(&mut v, method, new_cx);
             }
         }
         _ => {
-            visit::visit_item(item, (in_cx, v));
+            visit::walk_item(&mut v, item, in_cx);
         }
     }
 
@@ -77,12 +90,13 @@ fn stack_check_item(item: @ast::item,
     }
 }
 
-fn stack_check_fn<'a>(fk: &visit::fn_kind,
+fn stack_check_fn<'a>(v: StackCheckVisitor,
+                      fk: &visit::fn_kind,
                       decl: &ast::fn_decl,
                       body: &ast::Block,
                       sp: span,
                       id: ast::NodeId,
-                      (in_cx, v): (Context, visit::vt<Context>)) {
+                      in_cx: Context) {
     let safe_stack = match *fk {
         visit::fk_method(*) | visit::fk_item_fn(*) => {
             in_cx.safe_stack // see stack_check_item above
@@ -102,11 +116,13 @@ fn stack_check_fn<'a>(fk: &visit::fn_kind,
     };
     let new_cx = Context {safe_stack: safe_stack, ..in_cx};
     debug!("stack_check_fn(safe_stack=%b, id=%?)", safe_stack, id);
-    visit::visit_fn(fk, decl, body, sp, id, (new_cx, v));
+    let mut v = v;
+    visit::walk_fn(&mut v, fk, decl, body, sp, id, new_cx);
 }
 
-fn stack_check_expr<'a>(expr: @ast::expr,
-                        (cx, v): (Context, visit::vt<Context>)) {
+fn stack_check_expr<'a>(v: StackCheckVisitor,
+                        expr: @ast::expr,
+                        cx: Context) {
     debug!("stack_check_expr(safe_stack=%b, expr=%s)",
            cx.safe_stack, expr.repr(cx.tcx));
     if !cx.safe_stack {
@@ -126,7 +142,8 @@ fn stack_check_expr<'a>(expr: @ast::expr,
             _ => {}
         }
     }
-    visit::visit_expr(expr, (cx, v));
+    let mut v = v;
+    visit::walk_expr(&mut v, expr, cx);
 }
 
 fn call_to_extern_fn(cx: Context, callee: @ast::expr) {
diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs
index cd69a642b72..715c25c4a19 100644
--- a/src/librustc/middle/typeck/check/vtable.rs
+++ b/src/librustc/middle/typeck/check/vtable.rs
@@ -29,7 +29,8 @@ use syntax::ast;
 use syntax::ast_util;
 use syntax::codemap::span;
 use syntax::print::pprust::expr_to_str;
-use syntax::oldvisit;
+use syntax::visit;
+use syntax::visit::Visitor;
 
 // vtable resolution looks for places where trait bounds are
 // substituted in and figures out which vtable is used. There is some
@@ -712,11 +713,11 @@ pub fn early_resolve_expr(ex: @ast::expr,
     }
 }
 
-fn resolve_expr(ex: @ast::expr,
-                (fcx, v): (@mut FnCtxt,
-                           oldvisit::vt<@mut FnCtxt>)) {
+fn resolve_expr(v: &mut VtableResolveVisitor,
+                ex: @ast::expr,
+                fcx: @mut FnCtxt) {
     early_resolve_expr(ex, fcx, false);
-    oldvisit::visit_expr(ex, (fcx, v));
+    visit::walk_expr(v, ex, fcx);
 }
 
 pub fn resolve_impl(ccx: @mut CrateCtxt, impl_item: @ast::item) {
@@ -763,12 +764,20 @@ pub fn resolve_impl(ccx: @mut CrateCtxt, impl_item: @ast::item) {
     }
 }
 
+struct VtableResolveVisitor;
+
+impl visit::Visitor<@mut FnCtxt> for VtableResolveVisitor {
+    fn visit_expr(&mut self, ex:@ast::expr, e:@mut FnCtxt) {
+        resolve_expr(self, ex, e);
+    }
+    fn visit_item(&mut self, _:@ast::item, _:@mut FnCtxt) {
+        // no-op
+    }
+}
+
 // Detect points where a trait-bounded type parameter is
 // instantiated, resolve the impls for the parameters.
 pub fn resolve_in_block(fcx: @mut FnCtxt, bl: &ast::Block) {
-    oldvisit::visit_block(bl, (fcx, oldvisit::mk_vt(@oldvisit::Visitor {
-        visit_expr: resolve_expr,
-        visit_item: |_,_| {},
-        .. *oldvisit::default_visitor()
-    })));
+    let mut visitor = VtableResolveVisitor;
+    visit::walk_block(&mut visitor, bl, fcx);
 }