diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-03-17 21:58:48 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-05-25 05:47:25 +0000 |
| commit | 9c6430b3257a96d587349d85aa7596d3f4704c28 (patch) | |
| tree | 5272a2c2e50ea53bd9766c889748a9a3e84d9276 | |
| parent | cf747fcbf716a8afced9d23aa15bb47d93805209 (diff) | |
| download | rust-9c6430b3257a96d587349d85aa7596d3f4704c28.tar.gz rust-9c6430b3257a96d587349d85aa7596d3f4704c28.zip | |
Refactor out `ast::MacroDef`.
| -rw-r--r-- | src/librustc/hir/lowering.rs | 2 | ||||
| -rw-r--r-- | src/librustc/lint/context.rs | 3 | ||||
| -rw-r--r-- | src/librustc_metadata/cstore_impl.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 3 |
10 files changed, 36 insertions, 14 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d359c69d3a0..77bcde22ef7 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1505,7 +1505,7 @@ impl<'a> LoweringContext<'a> { if let ItemKind::MacroDef(ref tts) = i.node { if i.attrs.iter().any(|attr| attr.path == "macro_export") { self.exported_macros.push(hir::MacroDef { - name: name, attrs: attrs, id: i.id, span: i.span, body: tts.clone().into(), + name: name, attrs: attrs, id: i.id, span: i.span, body: tts.stream(), }); } return None; diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 9d5ba2c8f95..a265a84114a 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -49,7 +49,6 @@ use hir; use hir::def_id::LOCAL_CRATE; use hir::intravisit as hir_visit; use syntax::visit as ast_visit; -use syntax::tokenstream::ThinTokenStream; /// Information about the registered lints. /// @@ -1127,7 +1126,7 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { run_lints!(self, check_attribute, early_passes, attr); } - fn visit_mac_def(&mut self, _mac: &'a ThinTokenStream, id: ast::NodeId) { + fn visit_mac_def(&mut self, _mac: &'a ast::MacroDef, id: ast::NodeId) { let lints = self.sess.lints.borrow_mut().take(id); for early_lint in lints { self.early_lint(&early_lint); diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 7478f902e06..06472ed7fd1 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -386,7 +386,9 @@ impl CrateStore for cstore::CStore { id: ast::DUMMY_NODE_ID, span: local_span, attrs: attrs.iter().cloned().collect(), - node: ast::ItemKind::MacroDef(body.into()), + node: ast::ItemKind::MacroDef(ast::MacroDef { + tokens: body.into(), + }), vis: ast::Visibility::Inherited, }) } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d463e41c58a..39ebe490d0e 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -16,7 +16,6 @@ use std::mem; use syntax::abi; use syntax::ast; use syntax::attr; -use syntax::tokenstream::TokenStream; use syntax_pos::Span; use rustc::hir::map as hir_map; @@ -214,8 +213,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { LoadedMacro::ProcMacro(..) => continue, }; - let matchers = if let ast::ItemKind::MacroDef(ref tokens) = def.node { - let tts: Vec<_> = TokenStream::from(tokens.clone()).into_trees().collect(); + let matchers = if let ast::ItemKind::MacroDef(ref def) = def.node { + let tts: Vec<_> = def.stream().into_trees().collect(); tts.chunks(4).map(|arm| arm[0].span()).collect() } else { unreachable!() diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 24ce99208ed..6a30072c835 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1019,6 +1019,17 @@ impl Mac_ { } } +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +pub struct MacroDef { + pub tokens: ThinTokenStream, +} + +impl MacroDef { + pub fn stream(&self) -> TokenStream { + self.tokens.clone().into() + } +} + #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum StrStyle { /// A regular string, like `"foo"` @@ -1863,7 +1874,7 @@ pub enum ItemKind { Mac(Mac), /// A macro definition. - MacroDef(ThinTokenStream), + MacroDef(MacroDef), } impl ItemKind { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 73494d47fee..7ac3990def4 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -189,7 +189,7 @@ pub fn compile(sess: &ParseSess, features: &RefCell<Features>, def: &ast::Item) // Parse the macro_rules! invocation let body = match def.node { - ast::ItemKind::MacroDef(ref body) => body.clone().into(), + ast::ItemKind::MacroDef(ref body) => body.stream(), _ => unreachable!(), }; let argument_map = match parse(sess, body, &argument_gram, None, true) { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 58cf50cdc00..9aeb9ecca5a 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -189,6 +189,10 @@ pub trait Folder : Sized { // fold::noop_fold_mac(_mac, self) } + fn fold_macro_def(&mut self, def: MacroDef) -> MacroDef { + noop_fold_macro_def(def, self) + } + fn fold_lifetime(&mut self, l: Lifetime) -> Lifetime { noop_fold_lifetime(l, self) } @@ -515,6 +519,12 @@ pub fn noop_fold_mac<T: Folder>(Spanned {node, span}: Mac, fld: &mut T) -> Mac { } } +pub fn noop_fold_macro_def<T: Folder>(def: MacroDef, fld: &mut T) -> MacroDef { + MacroDef { + tokens: fld.fold_tts(def.tokens.into()).into(), + } +} + pub fn noop_fold_meta_list_item<T: Folder>(li: NestedMetaItem, fld: &mut T) -> NestedMetaItem { Spanned { @@ -919,7 +929,7 @@ pub fn noop_fold_item_kind<T: Folder>(i: ItemKind, folder: &mut T) -> ItemKind { items.move_flat_map(|item| folder.fold_trait_item(item)), ), ItemKind::Mac(m) => ItemKind::Mac(folder.fold_mac(m)), - ItemKind::MacroDef(tts) => ItemKind::MacroDef(folder.fold_tts(tts.into()).into()), + ItemKind::MacroDef(def) => ItemKind::MacroDef(folder.fold_macro_def(def)), } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c28f678cb51..3c9ad8ca9c0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3781,7 +3781,9 @@ impl<'a> Parser<'a> { } let span = lo.to(self.prev_span); - let kind = ItemKind::MacroDef(tts); + let kind = ItemKind::MacroDef(ast::MacroDef { + tokens: tts, + }); Ok(Some(self.mk_item(span, id, kind, Visibility::Inherited, attrs.to_owned()))) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 83c289ff80b..6c5bf56070e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1392,7 +1392,7 @@ impl<'a> State<'a> { self.print_ident(item.ident)?; self.cbox(INDENT_UNIT)?; self.popen()?; - self.print_tts(tts.clone().into())?; + self.print_tts(tts.stream())?; self.pclose()?; word(&mut self.s, ";")?; self.end()?; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 0fa0753b22c..d29d2497afe 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -27,7 +27,6 @@ use abi::Abi; use ast::*; use syntax_pos::Span; use codemap::Spanned; -use tokenstream::ThinTokenStream; #[derive(Copy, Clone, PartialEq, Eq)] pub enum FnKind<'a> { @@ -113,7 +112,7 @@ pub trait Visitor<'ast>: Sized { // definition in your trait impl: // visit::walk_mac(self, _mac) } - fn visit_mac_def(&mut self, _mac: &'ast ThinTokenStream, _id: NodeId) { + fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) { // Nothing to do } fn visit_path(&mut self, path: &'ast Path, _id: NodeId) { |
