about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2013-08-13 03:29:15 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2013-08-15 04:06:17 +0200
commit54ee3d03ff3b9fc485306ed55754d21035a22dd8 (patch)
treeccb35fada1396305f2df8f58432d2b48f0cd123a /src
parent356341192fdf8234b6a6ff8c3385ba227928ae9a (diff)
downloadrust-54ee3d03ff3b9fc485306ed55754d21035a22dd8.tar.gz
rust-54ee3d03ff3b9fc485306ed55754d21035a22dd8.zip
Port check_match from oldvisit to <V:Visitor> trait API.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/check_match.rs54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs
index 37f45142a11..f3d7565da26 100644
--- a/src/librustc/middle/check_match.rs
+++ b/src/librustc/middle/check_match.rs
@@ -25,7 +25,8 @@ use extra::sort;
 use syntax::ast::*;
 use syntax::ast_util::{unguarded_pat, walk_pat};
 use syntax::codemap::{span, dummy_sp, spanned};
-use syntax::oldvisit;
+use syntax::visit;
+use syntax::visit::{Visitor,fn_kind};
 
 pub struct MatchCheckCtxt {
     tcx: ty::ctxt,
@@ -33,6 +34,22 @@ pub struct MatchCheckCtxt {
     moves_map: moves::MovesMap
 }
 
+struct CheckMatchVisitor {
+    cx: @MatchCheckCtxt
+}
+
+impl Visitor<()> for CheckMatchVisitor {
+    fn visit_expr(&mut self, ex:@expr, e:()) {
+        check_expr(self, self.cx, ex, e);
+    }
+    fn visit_local(&mut self, l:@Local, e:()) {
+        check_local(self, self.cx, l, e);
+    }
+    fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl, b:&Block, s:span, n:NodeId, e:()) {
+        check_fn(self, self.cx, fk, fd, b, s, n, e);
+    }
+}
+
 pub fn check_crate(tcx: ty::ctxt,
                    method_map: method_map,
                    moves_map: moves::MovesMap,
@@ -40,20 +57,18 @@ pub fn check_crate(tcx: ty::ctxt,
     let cx = @MatchCheckCtxt {tcx: tcx,
                               method_map: method_map,
                               moves_map: moves_map};
-    oldvisit::visit_crate(crate, ((), oldvisit::mk_vt(@oldvisit::Visitor {
-        visit_expr: |a,b| check_expr(cx, a, b),
-        visit_local: |a,b| check_local(cx, a, b),
-        visit_fn: |kind, decl, body, sp, id, (e, v)|
-            check_fn(cx, kind, decl, body, sp, id, (e, v)),
-        .. *oldvisit::default_visitor::<()>()
-    })));
+    let mut v = CheckMatchVisitor { cx: cx };
+
+    visit::walk_crate(&mut v, crate, ());
+
     tcx.sess.abort_if_errors();
 }
 
-pub fn check_expr(cx: @MatchCheckCtxt,
+pub fn check_expr(v: &mut CheckMatchVisitor,
+                  cx: @MatchCheckCtxt,
                   ex: @expr,
-                  (s, v): ((), oldvisit::vt<()>)) {
-    oldvisit::visit_expr(ex, (s, v));
+                  s: ()) {
+    visit::walk_expr(v, ex, s);
     match ex.node {
       expr_match(scrut, ref arms) => {
         // First, check legality of move bindings.
@@ -787,10 +802,11 @@ pub fn default(cx: &MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> {
     else { None }
 }
 
-pub fn check_local(cx: &MatchCheckCtxt,
+pub fn check_local(v: &mut CheckMatchVisitor,
+                   cx: &MatchCheckCtxt,
                    loc: @Local,
-                   (s, v): ((), oldvisit::vt<()>)) {
-    oldvisit::visit_local(loc, (s, v));
+                   s: ()) {
+    visit::walk_local(v, loc, s);
     if is_refutable(cx, loc.pat) {
         cx.tcx.sess.span_err(loc.pat.span,
                              "refutable pattern in local binding");
@@ -800,15 +816,15 @@ pub fn check_local(cx: &MatchCheckCtxt,
     check_legality_of_move_bindings(cx, false, [ loc.pat ]);
 }
 
-pub fn check_fn(cx: &MatchCheckCtxt,
-                kind: &oldvisit::fn_kind,
+pub fn check_fn(v: &mut CheckMatchVisitor,
+                cx: &MatchCheckCtxt,
+                kind: &visit::fn_kind,
                 decl: &fn_decl,
                 body: &Block,
                 sp: span,
                 id: NodeId,
-                (s, v): ((),
-                         oldvisit::vt<()>)) {
-    oldvisit::visit_fn(kind, decl, body, sp, id, (s, v));
+                s: ()) {
+    visit::walk_fn(v, kind, decl, body, sp, id, s);
     for input in decl.inputs.iter() {
         if is_refutable(cx, input.pat) {
             cx.tcx.sess.span_err(input.pat.span,