Move MacroKind into Def::Macro
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
use hir::def_id::DefId;
|
use hir::def_id::DefId;
|
||||||
use util::nodemap::NodeMap;
|
use util::nodemap::NodeMap;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
use syntax::ext::base::MacroKind;
|
||||||
use hir;
|
use hir;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
@@ -53,7 +54,7 @@ pub enum Def {
|
|||||||
Label(ast::NodeId),
|
Label(ast::NodeId),
|
||||||
|
|
||||||
// Macro namespace
|
// Macro namespace
|
||||||
Macro(DefId),
|
Macro(DefId, MacroKind),
|
||||||
|
|
||||||
// Both namespaces
|
// Both namespaces
|
||||||
Err,
|
Err,
|
||||||
@@ -128,7 +129,7 @@ impl Def {
|
|||||||
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::TyAlias(id) |
|
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::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
|
||||||
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
|
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
|
||||||
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id) => {
|
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id, ..) => {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ use rustc_serialize::{Decodable, Decoder, SpecializedDecoder, opaque};
|
|||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::codemap;
|
use syntax::codemap;
|
||||||
|
use syntax::ext::base::MacroKind;
|
||||||
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP};
|
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP};
|
||||||
|
|
||||||
pub struct DecodeContext<'a, 'tcx: 'a> {
|
pub struct DecodeContext<'a, 'tcx: 'a> {
|
||||||
@@ -434,7 +435,7 @@ impl<'tcx> EntryKind<'tcx> {
|
|||||||
EntryKind::Variant(_) => Def::Variant(did),
|
EntryKind::Variant(_) => Def::Variant(did),
|
||||||
EntryKind::Trait(_) => Def::Trait(did),
|
EntryKind::Trait(_) => Def::Trait(did),
|
||||||
EntryKind::Enum(..) => Def::Enum(did),
|
EntryKind::Enum(..) => Def::Enum(did),
|
||||||
EntryKind::MacroDef(_) => Def::Macro(did),
|
EntryKind::MacroDef(_) => Def::Macro(did, MacroKind::Bang),
|
||||||
|
|
||||||
EntryKind::ForeignMod |
|
EntryKind::ForeignMod |
|
||||||
EntryKind::Impl(_) |
|
EntryKind::Impl(_) |
|
||||||
@@ -483,9 +484,11 @@ impl<'a, 'tcx> CrateMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_def(&self, index: DefIndex) -> Option<Def> {
|
pub fn get_def(&self, index: DefIndex) -> Option<Def> {
|
||||||
match self.is_proc_macro(index) {
|
if !self.is_proc_macro(index) {
|
||||||
true => Some(Def::Macro(self.local_def_id(index))),
|
self.entry(index).kind.to_def(self.local_def_id(index))
|
||||||
false => self.entry(index).kind.to_def(self.local_def_id(index)),
|
} else {
|
||||||
|
let kind = self.proc_macros.as_ref().unwrap()[index.as_usize() - 1].1.kind();
|
||||||
|
Some(Def::Macro(self.local_def_id(index), kind))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -688,8 +691,14 @@ impl<'a, 'tcx> CrateMetadata {
|
|||||||
{
|
{
|
||||||
if let Some(ref proc_macros) = self.proc_macros {
|
if let Some(ref proc_macros) = self.proc_macros {
|
||||||
if id == CRATE_DEF_INDEX {
|
if id == CRATE_DEF_INDEX {
|
||||||
for (id, &(name, _)) in proc_macros.iter().enumerate() {
|
for (id, &(name, ref ext)) in proc_macros.iter().enumerate() {
|
||||||
let def = Def::Macro(DefId { krate: self.cnum, index: DefIndex::new(id + 1) });
|
let def = Def::Macro(
|
||||||
|
DefId {
|
||||||
|
krate: self.cnum,
|
||||||
|
index: DefIndex::new(id + 1)
|
||||||
|
},
|
||||||
|
ext.kind()
|
||||||
|
);
|
||||||
callback(def::Export { name: name, def: def });
|
callback(def::Export { name: name, def: def });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -495,7 +495,7 @@ impl<'a> Resolver<'a> {
|
|||||||
|
|
||||||
pub fn get_macro(&mut self, def: Def) -> Rc<SyntaxExtension> {
|
pub fn get_macro(&mut self, def: Def) -> Rc<SyntaxExtension> {
|
||||||
let def_id = match def {
|
let def_id = match def {
|
||||||
Def::Macro(def_id) => def_id,
|
Def::Macro(def_id, ..) => def_id,
|
||||||
_ => panic!("Expected Def::Macro(..)"),
|
_ => panic!("Expected Def::Macro(..)"),
|
||||||
};
|
};
|
||||||
if let Some(ext) = self.macro_map.get(&def_id) {
|
if let Some(ext) = self.macro_map.get(&def_id) {
|
||||||
|
|||||||
@@ -2329,7 +2329,9 @@ impl<'a> Resolver<'a> {
|
|||||||
if primary_ns != MacroNS && path.len() == 1 &&
|
if primary_ns != MacroNS && path.len() == 1 &&
|
||||||
self.macro_names.contains(&path[0].name) {
|
self.macro_names.contains(&path[0].name) {
|
||||||
// Return some dummy definition, it's enough for error reporting.
|
// Return some dummy definition, it's enough for error reporting.
|
||||||
return Some(PathResolution::new(Def::Macro(DefId::local(CRATE_DEF_INDEX))));
|
return Some(
|
||||||
|
PathResolution::new(Def::Macro(DefId::local(CRATE_DEF_INDEX), MacroKind::Bang))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fin_res
|
fin_res
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,9 +159,10 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||||||
krate: BUILTIN_MACROS_CRATE,
|
krate: BUILTIN_MACROS_CRATE,
|
||||||
index: DefIndex::new(self.macro_map.len()),
|
index: DefIndex::new(self.macro_map.len()),
|
||||||
};
|
};
|
||||||
|
let kind = ext.kind();
|
||||||
self.macro_map.insert(def_id, ext);
|
self.macro_map.insert(def_id, ext);
|
||||||
let binding = self.arenas.alloc_name_binding(NameBinding {
|
let binding = self.arenas.alloc_name_binding(NameBinding {
|
||||||
kind: NameBindingKind::Def(Def::Macro(def_id)),
|
kind: NameBindingKind::Def(Def::Macro(def_id, kind)),
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
vis: ty::Visibility::Invisible,
|
vis: ty::Visibility::Invisible,
|
||||||
expansion: Mark::root(),
|
expansion: Mark::root(),
|
||||||
@@ -561,7 +562,7 @@ impl<'a> Resolver<'a> {
|
|||||||
});
|
});
|
||||||
self.macro_exports.push(Export {
|
self.macro_exports.push(Export {
|
||||||
name: def.ident.name,
|
name: def.ident.name,
|
||||||
def: Def::Macro(self.definitions.local_def_id(def.id)),
|
def: Def::Macro(self.definitions.local_def_id(def.id), MacroKind::Bang),
|
||||||
});
|
});
|
||||||
self.exported_macros.push(def);
|
self.exported_macros.push(def);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
|||||||
Def::AssociatedTy(..) |
|
Def::AssociatedTy(..) |
|
||||||
Def::AssociatedConst(..) |
|
Def::AssociatedConst(..) |
|
||||||
Def::PrimTy(_) |
|
Def::PrimTy(_) |
|
||||||
Def::Macro(_) |
|
Def::Macro(..) |
|
||||||
Def::Err => {
|
Def::Err => {
|
||||||
span_bug!(span,
|
span_bug!(span,
|
||||||
"process_def_kind for unexpected item: {:?}",
|
"process_def_kind for unexpected item: {:?}",
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
self.inside_public_path = orig_inside_public_path;
|
self.inside_public_path = orig_inside_public_path;
|
||||||
if let Some(exports) = self.cx.export_map.get(&id) {
|
if let Some(exports) = self.cx.export_map.get(&id) {
|
||||||
for export in exports {
|
for export in exports {
|
||||||
if let Def::Macro(def_id) = export.def {
|
if let Def::Macro(def_id, ..) = export.def {
|
||||||
if def_id.krate == LOCAL_CRATE {
|
if def_id.krate == LOCAL_CRATE {
|
||||||
continue // These are `krate.exported_macros`, handled in `self.visit()`.
|
continue // These are `krate.exported_macros`, handled in `self.visit()`.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ pub type BuiltinDeriveFn =
|
|||||||
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut FnMut(Annotatable));
|
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut FnMut(Annotatable));
|
||||||
|
|
||||||
/// Represents different kinds of macro invocations that can be resolved.
|
/// Represents different kinds of macro invocations that can be resolved.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
pub enum MacroKind {
|
pub enum MacroKind {
|
||||||
/// A bang macro - foo!()
|
/// A bang macro - foo!()
|
||||||
Bang,
|
Bang,
|
||||||
|
|||||||
Reference in New Issue
Block a user