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 15:31:07 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2013-08-15 04:09:19 +0200
commit7328f4cc12cc271d458a03786ff7ec6c2f37b3cb (patch)
tree61b94a094cdf8ff37c394b4b9a126b95c0796a0b /src
parent23ce08a4cde573f3ab5e3f57a7c5142a472595ff (diff)
downloadrust-7328f4cc12cc271d458a03786ff7ec6c2f37b3cb.tar.gz
rust-7328f4cc12cc271d458a03786ff7ec6c2f37b3cb.zip
port type_use.rs from oldvisit to <V:Visitor> trait.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/trans/type_use.rs52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs
index 74661098348..c67035021a3 100644
--- a/src/librustc/middle/trans/type_use.rs
+++ b/src/librustc/middle/trans/type_use.rs
@@ -42,7 +42,8 @@ use syntax::ast::*;
 use syntax::ast_map;
 use syntax::ast_util;
 use syntax::parse::token;
-use syntax::oldvisit;
+use syntax::visit;
+use syntax::visit::Visitor;
 
 pub type type_uses = uint; // Bitmask
 pub static use_repr: uint = 1;   /* Dependency on size/alignment/mode and
@@ -50,7 +51,7 @@ pub static use_repr: uint = 1;   /* Dependency on size/alignment/mode and
 pub static use_tydesc: uint = 2; /* Takes the tydesc, or compares */
 pub static use_all: uint = use_repr|use_tydesc;
 
-
+#[deriving(Clone)]
 pub struct Context {
     ccx: @mut CrateContext,
     uses: @mut ~[type_uses]
@@ -416,28 +417,39 @@ pub fn mark_for_expr(cx: &Context, e: &expr) {
     }
 }
 
-pub fn handle_body(cx: &Context, body: &Block) {
-    let v = oldvisit::mk_vt(@oldvisit::Visitor {
-        visit_expr: |e, (cx, v)| {
-            oldvisit::visit_expr(e, (cx, v));
+struct TypeUseVisitor;
+
+impl<'self> Visitor<&'self Context> for TypeUseVisitor {
+
+    fn visit_expr<'a>(&mut self, e:@expr, cx: &'a Context) {
+            visit::walk_expr(self, e, cx);
             mark_for_expr(cx, e);
-        },
-        visit_local: |l, (cx, v)| {
-            oldvisit::visit_local(l, (cx, v));
+    }
+
+    fn visit_local<'a>(&mut self, l:@Local, cx: &'a Context) {
+            visit::walk_local(self, l, cx);
             node_type_needs(cx, use_repr, l.id);
-        },
-        visit_pat: |p, (cx, v)| {
-            oldvisit::visit_pat(p, (cx, v));
+    }
+
+    fn visit_pat<'a>(&mut self, p:@pat, cx: &'a Context) {
+            visit::walk_pat(self, p, cx);
             node_type_needs(cx, use_repr, p.id);
-        },
-        visit_block: |b, (cx, v)| {
-            oldvisit::visit_block(b, (cx, v));
+    }
+
+    fn visit_block<'a>(&mut self, b:&Block, cx: &'a Context) {
+            visit::walk_block(self, b, cx);
             for e in b.expr.iter() {
                 node_type_needs(cx, use_repr, e.id);
             }
-        },
-        visit_item: |_i, (_cx, _v)| { },
-        ..*oldvisit::default_visitor()
-    });
-    (v.visit_block)(body, (cx, v));
+    }
+
+    fn visit_item<'a>(&mut self, _:@item, _: &'a Context) {
+        // do nothing
+    }
+
+}
+
+pub fn handle_body(cx: &Context, body: &Block) {
+    let mut v = TypeUseVisitor;
+    v.visit_block(body, cx);
 }