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 /src/libsyntax | |
| parent | cf747fcbf716a8afced9d23aa15bb47d93805209 (diff) | |
Refactor out `ast::MacroDef`.
Diffstat (limited to 'src/libsyntax')
| -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 |
6 files changed, 29 insertions, 7 deletions
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) { |
