Treat macros as HIR items
This commit is contained in:
parent
ac50a53359
commit
8c62fa0575
31 changed files with 162 additions and 256 deletions
|
@ -170,7 +170,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
self.lower_item_id_use_tree(use_tree, i.id, &mut vec);
|
||||
vec
|
||||
}
|
||||
ItemKind::MacroDef(..) => SmallVec::new(),
|
||||
ItemKind::Fn(..) | ItemKind::Impl(box ImplKind { of_trait: None, .. }) => {
|
||||
smallvec![i.id]
|
||||
}
|
||||
|
@ -212,28 +211,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item<'hir>> {
|
||||
let mut ident = i.ident;
|
||||
let mut vis = self.lower_visibility(&i.vis, None);
|
||||
|
||||
if let ItemKind::MacroDef(MacroDef { ref body, macro_rules }) = i.kind {
|
||||
if !macro_rules || self.sess.contains_name(&i.attrs, sym::macro_export) {
|
||||
let hir_id = self.lower_node_id(i.id);
|
||||
self.lower_attrs(hir_id, &i.attrs);
|
||||
let body = P(self.lower_mac_args(body));
|
||||
self.insert_macro_def(hir::MacroDef {
|
||||
ident,
|
||||
vis,
|
||||
def_id: hir_id.expect_owner(),
|
||||
span: i.span,
|
||||
ast: MacroDef { body, macro_rules },
|
||||
});
|
||||
} else {
|
||||
for a in i.attrs.iter() {
|
||||
let a = self.lower_attr(a);
|
||||
self.non_exported_macro_attrs.push(a);
|
||||
}
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
let hir_id = self.lower_node_id(i.id);
|
||||
let attrs = self.lower_attrs(hir_id, &i.attrs);
|
||||
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind);
|
||||
|
@ -465,7 +442,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
self.lower_generics(generics, ImplTraitContext::disallowed()),
|
||||
self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
|
||||
),
|
||||
ItemKind::MacroDef(..) | ItemKind::MacCall(..) => {
|
||||
ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => {
|
||||
let body = P(self.lower_mac_args(body));
|
||||
|
||||
hir::ItemKind::Macro(ast::MacroDef { body, macro_rules })
|
||||
}
|
||||
ItemKind::MacCall(..) => {
|
||||
panic!("`TyMac` should have been expanded by now")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,6 @@ struct LoweringContext<'a, 'hir: 'a> {
|
|||
/// The items being lowered are collected here.
|
||||
owners: IndexVec<LocalDefId, Option<hir::OwnerNode<'hir>>>,
|
||||
bodies: BTreeMap<hir::BodyId, hir::Body<'hir>>,
|
||||
non_exported_macro_attrs: Vec<ast::Attribute>,
|
||||
|
||||
trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
|
||||
|
||||
|
@ -330,7 +329,6 @@ pub fn lower_crate<'a, 'hir>(
|
|||
trait_impls: BTreeMap::new(),
|
||||
modules: BTreeMap::new(),
|
||||
attrs: BTreeMap::default(),
|
||||
non_exported_macro_attrs: Vec::new(),
|
||||
catch_scopes: Vec::new(),
|
||||
loop_scopes: Vec::new(),
|
||||
is_in_loop_condition: false,
|
||||
|
@ -551,7 +549,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
}
|
||||
|
||||
let krate = hir::Crate {
|
||||
non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs),
|
||||
owners: self.owners,
|
||||
bodies: self.bodies,
|
||||
body_ids,
|
||||
|
@ -600,13 +597,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
id
|
||||
}
|
||||
|
||||
fn insert_macro_def(&mut self, item: hir::MacroDef<'hir>) {
|
||||
let def_id = item.def_id;
|
||||
let item = self.arena.alloc(item);
|
||||
self.owners.ensure_contains_elem(def_id, || None);
|
||||
self.owners[def_id] = Some(hir::OwnerNode::MacroDef(item));
|
||||
}
|
||||
|
||||
fn allocate_hir_id_counter(&mut self, owner: NodeId) -> hir::HirId {
|
||||
// Set up the counter if needed.
|
||||
self.item_local_id_counters.entry(owner).or_insert(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue