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;
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.
///
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);
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,
})
}
use syntax::abi;
use syntax::ast;
use syntax::attr;
-use syntax::tokenstream::TokenStream;
use syntax_pos::Span;
use rustc::hir::map as hir_map;
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!()
}
}
+#[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"`
Mac(Mac),
/// A macro definition.
- MacroDef(ThinTokenStream),
+ MacroDef(MacroDef),
}
impl ItemKind {
// 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) {
// 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)
}
}
}
+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 {
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)),
}
}
}
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())))
}
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()?;
use ast::*;
use syntax_pos::Span;
use codemap::Spanned;
-use tokenstream::ThinTokenStream;
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum FnKind<'a> {
// 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) {