summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-02 01:35:39 +0000
committerbors <bors@rust-lang.org>2016-02-02 01:35:39 +0000
commita4a249fcab3d495e75110aa78cea6b637f303509 (patch)
tree57cefec8d3b2bcfaac133560f5fd1a7135ca3415 /src/libsyntax
parentb94cd7a5bd488324e39047682e1e4dad9c08fa93 (diff)
parent1d326419a13edf205f905be4de9c699207777934 (diff)
downloadrust-a4a249fcab3d495e75110aa78cea6b637f303509.tar.gz
rust-a4a249fcab3d495e75110aa78cea6b637f303509.zip
Auto merge of #31279 - DanielJCampbell:MacroReferencing, r=nrc
r? @nrc
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 9557310f318..9da5e1e3881 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -1064,6 +1064,27 @@ impl CodeMap {
         span
     }
 
+    /// Return the source callee.
+    ///
+    /// Returns None if the supplied span has no expansion trace,
+    /// else returns the NameAndSpan for the macro definition
+    /// corresponding to the source callsite.
+    pub fn source_callee(&self, sp: Span) -> Option<NameAndSpan> {
+        let mut span = sp;
+        while let Some(callsite) = self.with_expn_info(span.expn_id,
+                                            |ei| ei.map(|ei| ei.call_site.clone())) {
+            if let Some(_) = self.with_expn_info(callsite.expn_id,
+                                                |ei| ei.map(|ei| ei.call_site.clone())) {
+                span = callsite;
+            }
+            else {
+                return self.with_expn_info(span.expn_id,
+                                           |ei| ei.map(|ei| ei.callee.clone()));
+            }
+        }
+        None
+    }
+
     pub fn span_to_filename(&self, sp: Span) -> FileName {
         self.lookup_char_pos(sp.lo).file.name.to_string()
     }