diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-08-27 05:16:05 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-08-27 05:16:05 +0530 |
| commit | 4ec7b713dd2de43f4b0b03d33271f9c7dbb56d1c (patch) | |
| tree | f4573efc079c86e78860263e99dcc17e5ba414d0 /src/libsyntax/codemap.rs | |
| parent | 5c630a61c658cb7d861a60da6951ee06619337b2 (diff) | |
| download | rust-4ec7b713dd2de43f4b0b03d33271f9c7dbb56d1c.tar.gz rust-4ec7b713dd2de43f4b0b03d33271f9c7dbb56d1c.zip | |
Enumify CompilerExpansion in ExpnInfo
Diffstat (limited to 'src/libsyntax/codemap.rs')
| -rw-r--r-- | src/libsyntax/codemap.rs | 41 |
1 files changed, 34 insertions, 7 deletions
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<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 { |
