Skip to content

Commit

Permalink
expansion: Rename Expansion to AstFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jun 23, 2018
1 parent 869fa27 commit a127264
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 194 deletions.
17 changes: 9 additions & 8 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use syntax::attr::{self, HasAttrs};
use syntax::errors::DiagnosticBuilder;
use syntax::ext::base::{self, Annotatable, Determinacy, MultiModifier, MultiDecorator};
use syntax::ext::base::{MacroKind, SyntaxExtension, Resolver as SyntaxResolver};
use syntax::ext::expand::{Expansion, ExpansionKind, Invocation, InvocationKind, find_attr_invoc};
use syntax::ext::expand::{self, AstFragment, AstFragmentKind, Invocation, InvocationKind};
use syntax::ext::hygiene::{self, Mark, Transparency};
use syntax::ext::placeholders::placeholder;
use syntax::ext::tt::macro_rules;
Expand Down Expand Up @@ -187,9 +187,10 @@ impl<'a> base::Resolver for Resolver<'a> {
self.whitelisted_legacy_custom_derives.contains(&name)
}

fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion, derives: &[Mark]) {
fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFragment,
derives: &[Mark]) {
let invocation = self.invocations[&mark];
self.collect_def_ids(mark, invocation, expansion);
self.collect_def_ids(mark, invocation, fragment);

self.current_module = invocation.module.get();
self.current_module.unresolved_invocations.borrow_mut().remove(&mark);
Expand All @@ -202,7 +203,7 @@ impl<'a> base::Resolver for Resolver<'a> {
legacy_scope: LegacyScope::Invocation(invocation),
expansion: mark,
};
expansion.visit_with(&mut visitor);
fragment.visit_with(&mut visitor);
invocation.expansion.set(visitor.legacy_scope);
}

Expand Down Expand Up @@ -396,14 +397,14 @@ impl<'a> Resolver<'a> {
Ok(ext) => if let SyntaxExtension::ProcMacroDerive(_, ref inert_attrs, _) = *ext {
if inert_attrs.contains(&attr_name) {
// FIXME(jseyfried) Avoid `mem::replace` here.
let dummy_item = placeholder(ExpansionKind::Items, ast::DUMMY_NODE_ID)
let dummy_item = placeholder(AstFragmentKind::Items, ast::DUMMY_NODE_ID)
.make_items().pop().unwrap();
let dummy_item = Annotatable::Item(dummy_item);
*item = mem::replace(item, dummy_item).map_attrs(|mut attrs| {
let inert_attr = attr.take().unwrap();
attr::mark_known(&inert_attr);
if self.proc_macro_enabled {
*attr = find_attr_invoc(&mut attrs);
*attr = expand::find_attr_invoc(&mut attrs);
}
attrs.push(inert_attr);
attrs
Expand Down Expand Up @@ -769,7 +770,7 @@ impl<'a> Resolver<'a> {
fn collect_def_ids(&mut self,
mark: Mark,
invocation: &'a InvocationData<'a>,
expansion: &Expansion) {
fragment: &AstFragment) {
let Resolver { ref mut invocations, arenas, graph_root, .. } = *self;
let InvocationData { def_index, .. } = *invocation;

Expand All @@ -787,7 +788,7 @@ impl<'a> Resolver<'a> {
let mut def_collector = DefCollector::new(&mut self.definitions, mark);
def_collector.visit_macro_invoc = Some(visit_macro_invoc);
def_collector.with_parent(def_index, |def_collector| {
expansion.visit_with(def_collector)
fragment.visit_with(def_collector)
});
}

Expand Down
8 changes: 5 additions & 3 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use codemap::{self, CodeMap, Spanned, respan};
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
use edition::Edition;
use errors::{DiagnosticBuilder, DiagnosticId};
use ext::expand::{self, Expansion, Invocation};
use ext::expand::{self, AstFragment, Invocation};
use ext::hygiene::{self, Mark, SyntaxContext};
use fold::{self, Folder};
use parse::{self, parser, DirectoryOwnership};
Expand Down Expand Up @@ -697,7 +697,8 @@ pub trait Resolver {
fn eliminate_crate_var(&mut self, item: P<ast::Item>) -> P<ast::Item>;
fn is_whitelisted_legacy_custom_derive(&self, name: Name) -> bool;

fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion, derives: &[Mark]);
fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFragment,
derives: &[Mark]);
fn add_builtin(&mut self, ident: ast::Ident, ext: Lrc<SyntaxExtension>);

fn resolve_imports(&mut self);
Expand Down Expand Up @@ -726,7 +727,8 @@ impl Resolver for DummyResolver {
fn eliminate_crate_var(&mut self, item: P<ast::Item>) -> P<ast::Item> { item }
fn is_whitelisted_legacy_custom_derive(&self, _name: Name) -> bool { false }

fn visit_expansion(&mut self, _invoc: Mark, _expansion: &Expansion, _derives: &[Mark]) {}
fn visit_ast_fragment_with_placeholders(&mut self, _invoc: Mark, _fragment: &AstFragment,
_derives: &[Mark]) {}
fn add_builtin(&mut self, _ident: ast::Ident, _ext: Lrc<SyntaxExtension>) {}

fn resolve_imports(&mut self) {}
Expand Down
Loading

0 comments on commit a127264

Please sign in to comment.