librustc: Change fold to use traits instead of @fn
.
This commit is contained in:
parent
9705399504
commit
3e5de06135
12 changed files with 1335 additions and 1258 deletions
|
@ -15,6 +15,7 @@ use ast_util;
|
|||
use codemap::{Span, respan, dummy_sp};
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::quote::rt::*;
|
||||
use fold;
|
||||
use opt_vec;
|
||||
use opt_vec::OptVec;
|
||||
|
||||
|
@ -862,3 +863,32 @@ impl AstBuilder for @ExtCtxt {
|
|||
ast::view_path_glob(self.path(sp, path), ast::DUMMY_NODE_ID))])
|
||||
}
|
||||
}
|
||||
|
||||
struct Duplicator {
|
||||
cx: @ExtCtxt,
|
||||
}
|
||||
|
||||
impl fold::ast_fold for Duplicator {
|
||||
fn new_id(&self, _: NodeId) -> NodeId {
|
||||
ast::DUMMY_NODE_ID
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Duplicate {
|
||||
//
|
||||
// Duplication functions
|
||||
//
|
||||
// These functions just duplicate AST nodes.
|
||||
//
|
||||
|
||||
fn duplicate(&self, cx: @ExtCtxt) -> Self;
|
||||
}
|
||||
|
||||
impl Duplicate for @ast::Expr {
|
||||
fn duplicate(&self, cx: @ExtCtxt) -> @ast::Expr {
|
||||
let folder = @Duplicator {
|
||||
cx: cx,
|
||||
} as @fold::ast_fold;
|
||||
folder.fold_expr(*self)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue