Enumify CompilerExpansion in ExpnInfo

This commit is contained in:
Manish Goregaokar
2015-08-27 05:16:05 +05:30
parent 5c630a61c6
commit 4ec7b713dd
8 changed files with 68 additions and 53 deletions

View File

@@ -257,21 +257,38 @@ pub struct FileMapAndBytePos { pub fm: Rc<FileMap>, pub pos: BytePos }
//
/// The source of expansion.
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub enum ExpnFormat {
/// e.g. #[derive(...)] <item>
MacroAttribute,
MacroAttribute(String),
/// e.g. `format!()`
MacroBang,
MacroBang(String),
/// Syntax sugar expansion performed by the compiler (libsyntax::expand).
CompilerExpansion,
CompilerExpansion(CompilerExpansionFormat),
}
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
pub enum CompilerExpansionFormat {
IfLet,
PlacementIn,
WhileLet,
ForLoop,
Closure,
}
impl CompilerExpansionFormat {
pub fn name(self) -> &'static str {
match self {
CompilerExpansionFormat::IfLet => "if let expansion",
CompilerExpansionFormat::PlacementIn => "placement-in expansion",
CompilerExpansionFormat::WhileLet => "while let expansion",
CompilerExpansionFormat::ForLoop => "for loop expansion",
CompilerExpansionFormat::Closure => "closure expansion",
}
}
}
#[derive(Clone, Hash, Debug)]
pub struct NameAndSpan {
/// The name of the macro that was invoked to create the thing
/// with this Span.
pub name: String,
/// The format with which the macro was invoked.
pub format: ExpnFormat,
/// Whether the macro is allowed to use #[unstable]/feature-gated
@@ -284,6 +301,16 @@ pub struct NameAndSpan {
pub span: Option<Span>
}
impl NameAndSpan {
pub fn name(&self) -> &str{
match self.format {
ExpnFormat::MacroAttribute(ref s) => &s,
ExpnFormat::MacroBang(ref s) => &s,
ExpnFormat::CompilerExpansion(ce) => ce.name(),
}
}
}
/// Extra information for tracking spans of macro and syntax sugar expansion
#[derive(Hash, Debug)]
pub struct ExpnInfo {