auto merge of #8623 : pnkfelix/rust/fsk-visitor-vpar-defaults-step4, r=nmatsakis
Follow up to #8619 (step 3 of 5). (See #8527, which was step 1 of 5, for the full outline.) Part of #7081.
This commit is contained in:
commit
e6e678fac7
8 changed files with 314 additions and 217 deletions
|
|
@ -13,24 +13,31 @@ use syntax::ast;
|
|||
use syntax::print::pp;
|
||||
use syntax::print::pprust;
|
||||
use syntax::parse::token;
|
||||
use syntax::visit;
|
||||
|
||||
pub fn each_binding(l: @ast::Local, f: @fn(&ast::Path, ast::NodeId)) {
|
||||
use syntax::oldvisit;
|
||||
struct EachBindingVisitor {
|
||||
f: @fn(&ast::Path, ast::NodeId)
|
||||
}
|
||||
|
||||
let vt = oldvisit::mk_simple_visitor(
|
||||
@oldvisit::SimpleVisitor {
|
||||
visit_pat: |pat| {
|
||||
impl visit::Visitor<()> for EachBindingVisitor {
|
||||
fn visit_pat(&mut self, pat:@ast::pat, _:()) {
|
||||
match pat.node {
|
||||
ast::pat_ident(_, ref path, _) => {
|
||||
f(path, pat.id);
|
||||
(self.f)(path, pat.id);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
.. *oldvisit::default_simple_visitor()
|
||||
}
|
||||
);
|
||||
(vt.visit_pat)(l.pat, ((), vt));
|
||||
|
||||
visit::walk_pat(self, pat, ());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn each_binding(l: @ast::Local, f: @fn(&ast::Path, ast::NodeId)) {
|
||||
use syntax::visit::Visitor;
|
||||
|
||||
let mut vt = EachBindingVisitor{ f: f };
|
||||
|
||||
vt.visit_pat(l.pat, ());
|
||||
}
|
||||
|
||||
/// A utility function that hands off a pretty printer to a callback.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue