提交 53de24bb 编写于 作者: J Jeffrey Seyfried

Refactor away fields `MacroDef::{use_locally, export}`.

上级 e4baeaa3
......@@ -716,8 +716,6 @@ fn lower_macro_def(&mut self, m: &MacroDef) -> hir::MacroDef {
id: m.id,
span: m.span,
imported_from: m.imported_from.map(|x| x.name),
export: m.export,
use_locally: m.use_locally,
allow_internal_unstable: m.allow_internal_unstable,
body: m.body.clone().into(),
}
......
......@@ -458,8 +458,6 @@ pub struct MacroDef {
pub id: NodeId,
pub span: Span,
pub imported_from: Option<Name>,
pub export: bool,
pub use_locally: bool,
pub allow_internal_unstable: bool,
pub body: HirVec<TokenTree>,
}
......
......@@ -675,13 +675,11 @@ fn visit_attribute(&mut self, _: &ast::Attribute) {
fn visit_macro_def(&mut self, macro_def: &'tcx MacroDef) {
debug!("visit_macro_def: st={:?}", self.st);
if macro_def.export {
SawMacroDef.hash(self.st);
hash_attrs!(self, &macro_def.attrs);
visit::walk_macro_def(self, macro_def)
// FIXME(mw): We should hash the body of the macro too but we don't
// have a stable way of doing so yet.
}
SawMacroDef.hash(self.st);
hash_attrs!(self, &macro_def.attrs);
visit::walk_macro_def(self, macro_def)
// FIXME(mw): We should hash the body of the macro too but we don't
// have a stable way of doing so yet.
}
}
......
......@@ -594,9 +594,6 @@ pub fn read_macros(&mut self, item: &ast::Item) -> Macros {
id: ast::DUMMY_NODE_ID,
span: local_span,
imported_from: Some(item.ident),
// overridden in plugin/load.rs
export: false,
use_locally: false,
allow_internal_unstable: attr::contains_name(&def.attrs, "allow_internal_unstable"),
attrs: def.attrs,
body: body,
......
......@@ -114,22 +114,22 @@ fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion) {
invocation.expansion.set(visitor.legacy_scope);
}
fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef) {
fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef, export: bool) {
if &def.ident.name.as_str() == "macro_rules" {
self.session.span_err(def.span, "user-defined macros may not be named `macro_rules`");
}
if def.use_locally {
let invocation = self.invocations[&scope];
let binding = self.arenas.alloc_legacy_binding(LegacyBinding {
parent: invocation.legacy_scope.get(),
name: def.ident.name,
ext: Rc::new(macro_rules::compile(&self.session.parse_sess, &def)),
span: def.span,
});
invocation.legacy_scope.set(LegacyScope::Binding(binding));
self.macro_names.insert(def.ident.name);
}
if def.export {
let invocation = self.invocations[&scope];
let binding = self.arenas.alloc_legacy_binding(LegacyBinding {
parent: invocation.legacy_scope.get(),
name: def.ident.name,
ext: Rc::new(macro_rules::compile(&self.session.parse_sess, &def)),
span: def.span,
});
invocation.legacy_scope.set(LegacyScope::Binding(binding));
self.macro_names.insert(def.ident.name);
if export {
def.id = self.next_node_id();
self.exported_macros.push(def);
}
......
......@@ -2012,8 +2012,6 @@ pub struct MacroDef {
pub id: NodeId,
pub span: Span,
pub imported_from: Option<Ident>,
pub export: bool,
pub use_locally: bool,
pub allow_internal_unstable: bool,
pub body: Vec<TokenTree>,
}
......
......@@ -519,7 +519,7 @@ pub trait Resolver {
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion);
fn add_macro(&mut self, scope: Mark, def: ast::MacroDef);
fn add_macro(&mut self, scope: Mark, def: ast::MacroDef, export: bool);
fn add_ext(&mut self, ident: ast::Ident, ext: Rc<SyntaxExtension>);
fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec<Mark>);
......@@ -541,7 +541,7 @@ fn next_node_id(&mut self) -> ast::NodeId { ast::DUMMY_NODE_ID }
fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() }
fn visit_expansion(&mut self, _invoc: Mark, _expansion: &Expansion) {}
fn add_macro(&mut self, _scope: Mark, _def: ast::MacroDef) {}
fn add_macro(&mut self, _scope: Mark, _def: ast::MacroDef, _export: bool) {}
fn add_ext(&mut self, _ident: ast::Ident, _ext: Rc<SyntaxExtension>) {}
fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec<Mark>) {}
......
......@@ -157,14 +157,13 @@ fn expand(&self,
tts: Vec<tokenstream::TokenTree>,
attrs: Vec<ast::Attribute>)
-> Box<MacResult> {
let export = attr::contains_name(&attrs, "macro_export");
let def = ast::MacroDef {
ident: ident,
id: ast::DUMMY_NODE_ID,
span: span,
imported_from: None,
use_locally: true,
body: tts,
export: attr::contains_name(&attrs, "macro_export"),
allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"),
attrs: attrs,
};
......@@ -176,7 +175,7 @@ fn expand(&self,
MacEager::items(placeholders::macro_scope_placeholder().make_items())
};
cx.resolver.add_macro(cx.current_expansion.mark, def);
cx.resolver.add_macro(cx.current_expansion.mark, def, export);
result
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册