Add an ExpnKind for AST passes
This commit is contained in:
parent
5ade61a4f1
commit
0133941f47
4 changed files with 33 additions and 2 deletions
|
@ -411,9 +411,17 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData {
|
|||
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind {
|
||||
Root,
|
||||
Macro(kind, descr),
|
||||
AstPass(kind),
|
||||
Desugaring(kind)
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(enum ::syntax_pos::hygiene::AstPass {
|
||||
StdImports,
|
||||
TestHarness,
|
||||
ProcMacroHarness,
|
||||
PluginMacroDefs,
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind {
|
||||
CondTemporary,
|
||||
Async,
|
||||
|
|
|
@ -888,7 +888,7 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
|||
let expn_data = span.ctxt().outer_expn_data();
|
||||
match expn_data.kind {
|
||||
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
|
||||
ExpnKind::Desugaring(_) => true, // well, it's "external"
|
||||
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
|
||||
ExpnKind::Macro(MacroKind::Bang, _) => {
|
||||
if expn_data.def_site.is_dummy() {
|
||||
// dummy span for the def_site means it's an external macro
|
||||
|
|
|
@ -639,8 +639,9 @@ pub enum ExpnKind {
|
|||
/// No expansion, aka root expansion. Only `ExpnId::root()` has this kind.
|
||||
Root,
|
||||
/// Expansion produced by a macro.
|
||||
/// FIXME: Some code injected by the compiler before HIR lowering also gets this kind.
|
||||
Macro(MacroKind, Symbol),
|
||||
/// Transform done by the compiler on the AST.
|
||||
AstPass(AstPass),
|
||||
/// Desugaring done by the compiler during HIR lowering.
|
||||
Desugaring(DesugaringKind)
|
||||
}
|
||||
|
@ -650,6 +651,7 @@ impl ExpnKind {
|
|||
match *self {
|
||||
ExpnKind::Root => kw::PathRoot,
|
||||
ExpnKind::Macro(_, descr) => descr,
|
||||
ExpnKind::AstPass(kind) => Symbol::intern(kind.descr()),
|
||||
ExpnKind::Desugaring(kind) => Symbol::intern(kind.descr()),
|
||||
}
|
||||
}
|
||||
|
@ -683,6 +685,26 @@ impl MacroKind {
|
|||
}
|
||||
}
|
||||
|
||||
/// The kind of AST transform.
|
||||
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub enum AstPass {
|
||||
StdImports,
|
||||
TestHarness,
|
||||
ProcMacroHarness,
|
||||
PluginMacroDefs,
|
||||
}
|
||||
|
||||
impl AstPass {
|
||||
fn descr(self) -> &'static str {
|
||||
match self {
|
||||
AstPass::StdImports => "standard library imports",
|
||||
AstPass::TestHarness => "test harness",
|
||||
AstPass::ProcMacroHarness => "proc macro harness",
|
||||
AstPass::PluginMacroDefs => "plugin macro definitions",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The kind of compiler desugaring.
|
||||
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub enum DesugaringKind {
|
||||
|
|
|
@ -442,6 +442,7 @@ impl Span {
|
|||
let (pre, post) = match expn_data.kind {
|
||||
ExpnKind::Root => break,
|
||||
ExpnKind::Desugaring(..) => ("desugaring of ", ""),
|
||||
ExpnKind::AstPass(..) => ("", ""),
|
||||
ExpnKind::Macro(macro_kind, _) => match macro_kind {
|
||||
MacroKind::Bang => ("", "!"),
|
||||
MacroKind::Attr => ("#[", "]"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue