Refactor field expansion_data of Resolver to use a Mark instead of a u32.
This commit is contained in:
parent
5c2d76d23e
commit
797eb57aa8
5 changed files with 18 additions and 12 deletions
|
|
@ -17,6 +17,7 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex};
|
|||
use middle::cstore::InlinedItem;
|
||||
|
||||
use syntax::ast::*;
|
||||
use syntax::ext::hygiene::Mark;
|
||||
use syntax::visit;
|
||||
use syntax::parse::token::{self, keywords};
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ pub struct DefCollector<'a> {
|
|||
}
|
||||
|
||||
pub struct MacroInvocationData {
|
||||
pub id: NodeId,
|
||||
pub mark: Mark,
|
||||
pub def_index: DefIndex,
|
||||
pub const_integer: bool,
|
||||
}
|
||||
|
|
@ -126,7 +127,7 @@ impl<'a> DefCollector<'a> {
|
|||
fn visit_macro_invoc(&mut self, id: NodeId, const_integer: bool) {
|
||||
if let Some(ref mut visit) = self.visit_macro_invoc {
|
||||
visit(MacroInvocationData {
|
||||
id: id,
|
||||
mark: Mark::from_placeholder_id(id),
|
||||
const_integer: const_integer,
|
||||
def_index: self.parent_def.unwrap(),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -531,7 +531,7 @@ pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {
|
|||
|
||||
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
fn visit_invoc(&mut self, id: ast::NodeId) {
|
||||
self.resolver.expansion_data.get_mut(&id.as_u32()).unwrap().module =
|
||||
self.resolver.expansion_data.get_mut(&Mark::from_placeholder_id(id)).unwrap().module =
|
||||
self.resolver.current_module;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1084,7 +1084,7 @@ pub struct Resolver<'a> {
|
|||
macro_names: FnvHashSet<Name>,
|
||||
|
||||
// Maps the `Mark` of an expansion to its containing module or block.
|
||||
expansion_data: FnvHashMap<u32, macros::ExpansionData<'a>>,
|
||||
expansion_data: FnvHashMap<Mark, macros::ExpansionData<'a>>,
|
||||
}
|
||||
|
||||
pub struct ResolverArenas<'a> {
|
||||
|
|
@ -1202,7 +1202,7 @@ impl<'a> Resolver<'a> {
|
|||
DefCollector::new(&mut definitions).collect_root();
|
||||
|
||||
let mut expansion_data = FnvHashMap();
|
||||
expansion_data.insert(0, macros::ExpansionData::root(graph_root)); // Crate root expansion
|
||||
expansion_data.insert(Mark::root(), macros::ExpansionData::root(graph_root));
|
||||
|
||||
Resolver {
|
||||
session: session,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark {
|
||||
let mark = Mark::fresh();
|
||||
let module = self.module_map[&id];
|
||||
self.expansion_data.insert(mark.as_u32(), ExpansionData {
|
||||
self.expansion_data.insert(mark, ExpansionData {
|
||||
module: module,
|
||||
def_index: module.def_id().unwrap().index,
|
||||
const_integer: false,
|
||||
|
|
@ -65,7 +65,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
|
||||
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion) {
|
||||
self.collect_def_ids(mark, expansion);
|
||||
self.current_module = self.expansion_data[&mark.as_u32()].module;
|
||||
self.current_module = self.expansion_data[&mark].module;
|
||||
expansion.visit_with(&mut BuildReducedGraphVisitor { resolver: self });
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
self.macro_names.insert(ident.name);
|
||||
}
|
||||
|
||||
let mut module = self.expansion_data[&scope.as_u32()].module;
|
||||
let mut module = self.expansion_data[&scope].module;
|
||||
while module.macros_escape {
|
||||
module = module.parent.unwrap();
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
fn find_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute> {
|
||||
for i in 0..attrs.len() {
|
||||
let name = intern(&attrs[i].name());
|
||||
match self.expansion_data[&0].module.macros.borrow().get(&name) {
|
||||
match self.expansion_data[&Mark::root()].module.macros.borrow().get(&name) {
|
||||
Some(binding) => match *binding.ext {
|
||||
MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => {
|
||||
return Some(attrs.remove(i))
|
||||
|
|
@ -132,7 +132,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
InvocationKind::Attr { ref attr, .. } => (intern(&*attr.name()), attr.span),
|
||||
};
|
||||
|
||||
let mut module = self.expansion_data[&scope.as_u32()].module;
|
||||
let mut module = self.expansion_data[&scope].module;
|
||||
loop {
|
||||
if let Some(binding) = module.macros.borrow().get(&name) {
|
||||
return Some(binding.ext.clone());
|
||||
|
|
@ -168,9 +168,9 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
fn collect_def_ids(&mut self, mark: Mark, expansion: &Expansion) {
|
||||
let expansion_data = &mut self.expansion_data;
|
||||
let ExpansionData { def_index, const_integer, module } = expansion_data[&mark.as_u32()];
|
||||
let ExpansionData { def_index, const_integer, module } = expansion_data[&mark];
|
||||
let visit_macro_invoc = &mut |invoc: map::MacroInvocationData| {
|
||||
expansion_data.entry(invoc.id.as_u32()).or_insert(ExpansionData {
|
||||
expansion_data.entry(invoc.mark).or_insert(ExpansionData {
|
||||
def_index: invoc.def_index,
|
||||
const_integer: invoc.const_integer,
|
||||
module: module,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
|
||||
//! DOI=10.1017/S0956796812000093 http://dx.doi.org/10.1017/S0956796812000093
|
||||
|
||||
use ast::NodeId;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
|
|
@ -46,6 +47,10 @@ impl Mark {
|
|||
Mark(0)
|
||||
}
|
||||
|
||||
pub fn from_placeholder_id(id: NodeId) -> Self {
|
||||
Mark(id.as_u32())
|
||||
}
|
||||
|
||||
pub fn as_u32(&self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue