Add variants Def::Macro and Namespace::MacroNS.

This commit is contained in:
Jeffrey Seyfried 2016-10-25 22:05:02 +00:00
parent dd0781ea25
commit 85f74c0eea
7 changed files with 36 additions and 7 deletions

View File

@ -52,6 +52,9 @@ pub enum Def {
ast::NodeId), // expr node that creates the closure
Label(ast::NodeId),
// Macro namespace
Macro(DefId),
// Both namespaces
Err,
}
@ -133,7 +136,7 @@ impl Def {
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::TyAlias(id) |
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) => {
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id) => {
id
}
@ -173,6 +176,7 @@ impl Def {
Def::Upvar(..) => "closure capture",
Def::Label(..) => "label",
Def::SelfTy(..) => "self type",
Def::Macro(..) => "macro",
Def::Err => "unresolved item",
}
}

View File

@ -834,7 +834,8 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
Def::Const(..) |
Def::AssociatedConst(..) |
Def::Local(..) |
Def::Upvar(..) => {
Def::Upvar(..) |
Def::Macro(..) => {
DefHash::SawDefId.hash(self.st);
self.hash_def_id(def.def_id());
}

View File

@ -690,9 +690,7 @@ impl<'a, 'tcx> CrateMetadata {
pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F)
where F: FnMut(def::Export)
{
if self.dep_kind.get() == DepKind::MacrosOnly {
return
}
let macros_only = self.dep_kind.get() == DepKind::MacrosOnly;
// Find the item.
let item = match self.maybe_entry(id) {
@ -702,9 +700,19 @@ impl<'a, 'tcx> CrateMetadata {
// Iterate over all children.
for child_index in item.children.decode(self) {
if macros_only {
continue
}
// Get the item.
if let Some(child) = self.maybe_entry(child_index) {
let child = child.decode(self);
match child.kind {
EntryKind::MacroDef(..) => {}
_ if macros_only => continue,
_ => {}
}
// Hand off the item to the callback.
match child.kind {
// FIXME(eddyb) Don't encode these in children.
@ -763,6 +771,11 @@ impl<'a, 'tcx> CrateMetadata {
if let EntryKind::Mod(data) = item.kind {
for exp in data.decode(self).reexports.decode(self) {
match exp.def {
Def::Macro(..) => {}
_ if macros_only => continue,
_ => {}
}
callback(exp);
}
}

View File

@ -17,7 +17,7 @@ use macros::{InvocationData, LegacyScope};
use resolve_imports::ImportDirective;
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport};
use {Module, ModuleS, ModuleKind};
use Namespace::{self, TypeNS, ValueNS};
use Namespace::{self, TypeNS, ValueNS, MacroNS};
use {NameBinding, NameBindingKind, ToNameBinding};
use Resolver;
use {resolve_error, resolve_struct_error, ResolutionError};
@ -485,6 +485,9 @@ impl<'b> Resolver<'b> {
let field_names = self.session.cstore.struct_field_names(def_id);
self.insert_field_names(def_id, field_names);
}
Def::Macro(..) => {
self.define(parent, name, MacroNS, (def, DUMMY_SP, vis));
}
Def::Local(..) |
Def::PrimTy(..) |
Def::TyParam(..) |

View File

@ -533,6 +533,7 @@ impl PatternSource {
pub enum Namespace {
TypeNS,
ValueNS,
MacroNS,
}
impl<'a> Visitor for Resolver<'a> {
@ -1346,7 +1347,11 @@ impl<'a> Resolver<'a> {
}
fn get_ribs<'b>(&'b mut self, ns: Namespace) -> &'b mut Vec<Rib<'a>> {
match ns { ValueNS => &mut self.value_ribs, TypeNS => &mut self.type_ribs }
match ns {
ValueNS => &mut self.value_ribs,
TypeNS => &mut self.type_ribs,
MacroNS => panic!("The macro namespace has no ribs"),
}
}
fn record_use(&mut self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>, span: Span)
@ -3421,6 +3426,7 @@ impl<'a> Resolver<'a> {
let msg = {
let kind = match (ns, old_binding.module()) {
(ValueNS, _) => "a value",
(MacroNS, _) => "a macro",
(TypeNS, _) if old_binding.is_extern_crate() => "an extern crate",
(TypeNS, Ok(module)) if module.is_normal() => "a module",
(TypeNS, Ok(module)) if module.is_trait() => "a trait",

View File

@ -341,6 +341,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
Def::AssociatedTy(..) |
Def::AssociatedConst(..) |
Def::PrimTy(_) |
Def::Macro(_) |
Def::Err => {
span_bug!(span,
"process_def_kind for unexpected item: {:?}",

View File

@ -565,6 +565,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
Def::PrimTy(..) |
Def::SelfTy(..) |
Def::Label(..) |
Def::Macro(..) |
Def::Err => None,
}
}