diff options
| author | bors <bors@rust-lang.org> | 2014-07-31 16:41:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-31 16:41:36 +0000 |
| commit | 8c00357f9d60ef67479a85e8df83aa59fe690623 (patch) | |
| tree | c58173ece36ca6b00e70cd4a355504c13c960968 /src/libsyntax/ext | |
| parent | 9826e801bed408c2497a06c535a5691e1161c85f (diff) | |
| parent | da6070dbef81c1028ce3e87fd0102b2abbbc181e (diff) | |
| download | rust-8c00357f9d60ef67479a85e8df83aa59fe690623.tar.gz rust-8c00357f9d60ef67479a85e8df83aa59fe690623.zip | |
auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
Note: This PR is motivated by an attempt to write an custom syntax extension that tried to use `syntax::fold`, and that could only do so by fixing bugs in it and copying out private functions. --- Refactored `syntax::fold` Prior to this, the code there had a few issues: - Default implementations inconsistenly either had the prefix `noop_` or not. - Some default methods where implemented in terms of a public noop function for user code to call, others where implemented directly on the trait and did not allow users of the trait to reuse the code. - Some of the default implementations where private, and thus not reusable for other implementors. - There where some bugs where default implemntations called other default implementations directly, rather than to the underlying Folder, with the result of some ast nodes never being visted even if the user implemented that method. (For example, the current Folder never folded struct fields) This commit solves this situation somewhat radically by making __all__ `fold_...` functions in the module into Folder methods, and implementing them all in terms of public `noop_...` functions for other implementors to call out to. Some public functions had to be renamed to fit the new system, so this is a breaking change. --- Also added a few trait implementations to `ast` types
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index a51a79b6d58..808532d55bb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -341,7 +341,7 @@ fn expand_item_underscore(item: &ast::Item_, fld: &mut MacroExpander) -> ast::It ast::ItemFn(decl, fn_style, abi, ref generics, body) => { let (rewritten_fn_decl, rewritten_body) = expand_and_rename_fn_decl_and_block(&*decl, body, fld); - let expanded_generics = fold::fold_generics(generics,fld); + let expanded_generics = fold::noop_fold_generics(generics,fld); ast::ItemFn(rewritten_fn_decl, fn_style, abi, expanded_generics, rewritten_body) } _ => noop_fold_item_underscore(&*item, fld) @@ -795,7 +795,7 @@ impl<'a> Folder for IdentRenamer<'a> { } } fn fold_mac(&mut self, macro: &ast::Mac) -> ast::Mac { - fold::fold_mac(macro, self) + fold::noop_fold_mac(macro, self) } } @@ -827,7 +827,7 @@ impl<'a> Folder for PatIdentRenamer<'a> { } } fn fold_mac(&mut self, macro: &ast::Mac) -> ast::Mac { - fold::fold_mac(macro, self) + fold::noop_fold_mac(macro, self) } } @@ -850,7 +850,7 @@ fn expand_method(m: &ast::Method, fld: &mut MacroExpander) -> SmallVector<Gc<ast id: id, span: fld.new_span(m.span), node: ast::MethDecl(fld.fold_ident(ident), - fold_generics(generics, fld), + noop_fold_generics(generics, fld), abi, fld.fold_explicit_self(explicit_self), fn_style, @@ -1017,7 +1017,7 @@ impl Folder for Marker { let macro = match m.node { MacInvocTT(ref path, ref tts, ctxt) => { MacInvocTT(self.fold_path(path), - fold_tts(tts.as_slice(), self), + self.fold_tts(tts.as_slice()), mtwt::apply_mark(self.mark, ctxt)) } }; @@ -1030,7 +1030,7 @@ impl Folder for Marker { // apply a given mark to the given token trees. Used prior to expansion of a macro. fn mark_tts(tts: &[TokenTree], m: Mrk) -> Vec<TokenTree> { - fold_tts(tts, &mut Marker{mark:m}) + noop_fold_tts(tts, &mut Marker{mark:m}) } // apply a given mark to the given expr. Used following the expansion of a macro. |
