From 4ec7b713dd2de43f4b0b03d33271f9c7dbb56d1c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 27 Aug 2015 05:16:05 +0530 Subject: Enumify CompilerExpansion in ExpnInfo --- src/libsyntax/codemap.rs | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/libsyntax/codemap.rs') diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 0aeb572b6bc..ce2adccbfc3 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -257,21 +257,38 @@ pub struct FileMapAndBytePos { pub fm: Rc, 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(...)] - 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 } +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 { -- cgit 1.4.1-3-g733a5