summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorDaniel Campbell <campbelldj@hotmail.com>2016-01-29 20:22:55 +1300
committerDaniel Campbell <campbelldj@hotmail.com>2016-02-01 19:09:18 +1300
commit1d326419a13edf205f905be4de9c699207777934 (patch)
tree5d1864aebfbb57353029479031fcd07aef847453 /src/libsyntax
parent142214d1f2232a4e88ff7bd99951b01f36052c61 (diff)
downloadrust-1d326419a13edf205f905be4de9c699207777934.tar.gz
rust-1d326419a13edf205f905be4de9c699207777934.zip
Implemented macro referencing for save analysis
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 ca01623fef9..e80c9e4a6ce 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -1065,6 +1065,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()
     }