diff options
| author | bors <bors@rust-lang.org> | 2014-03-26 13:36:52 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-26 13:36:52 -0700 |
| commit | 533a5263279d177127607f1883b9a85824d5ef52 (patch) | |
| tree | 989c6a0211cbf2f3aa64194df383e6663d98c683 | |
| parent | 2c71cdf64bf39cb4d2bbc14c279eeda60e46d140 (diff) | |
| parent | 6419848e66e1a8dd73204711d4e589e4b7f341ef (diff) | |
| download | rust-533a5263279d177127607f1883b9a85824d5ef52.tar.gz rust-533a5263279d177127607f1883b9a85824d5ef52.zip | |
auto merge of #13152 : huonw/rust/wtf-are-things-in-spans, r=alexcrichton
Add some docs to ExpnInfo. Add a single overlooked `new_span` call to the folder (I'm pretty sure nothing reads this span, though, so it's probably pointless).
| -rw-r--r-- | src/libsyntax/codemap.rs | 29 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 2 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 325df5fda60..4a9e53c63e7 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -88,6 +88,8 @@ to the original source. pub struct Span { lo: BytePos, hi: BytePos, + /// Information about where the macro came from, if this piece of + /// code was created by a macro expansion. expn_info: Option<@ExpnInfo> } @@ -162,26 +164,47 @@ pub struct LocWithOpt { pub struct FileMapAndLine {fm: Rc<FileMap>, line: uint} pub struct FileMapAndBytePos {fm: Rc<FileMap>, pos: BytePos} +/// The syntax with which a macro was invoked. #[deriving(Clone, Hash, Show)] pub enum MacroFormat { - // e.g. #[deriving(...)] <item> + /// e.g. #[deriving(...)] <item> MacroAttribute, - // e.g. `format!()` + /// e.g. `format!()` MacroBang } #[deriving(Clone, Hash, Show)] pub struct NameAndSpan { + /// The name of the macro that was invoked to create the thing + /// with this Span. name: ~str, - // the format with which the macro was invoked. + /// The format with which the macro was invoked. format: MacroFormat, + /// The span of the macro definition itself. The macro may not + /// have a sensible definition span (e.g. something defined + /// completely inside libsyntax) in which case this is None. span: Option<Span> } /// Extra information for tracking macro expansion of spans #[deriving(Hash, Show)] pub struct ExpnInfo { + /// The location of the actual macro invocation, e.g. `let x = + /// foo!();` + /// + /// This may recursively refer to other macro invocations, e.g. if + /// `foo!()` invoked `bar!()` internally, and there was an + /// expression inside `bar!`; the call_site of the expression in + /// the expansion would point to the `bar!` invocation; that + /// call_site span would have its own ExpnInfo, with the call_site + /// pointing to the `foo!` invocation. call_site: Span, + /// Information about the macro and its definition. + /// + /// The `callee` of the inner expression in the `call_site` + /// example would point to the `macro_rules! bar { ... }` and that + /// of the `bar!()` invocation would point to the `macro_rules! + /// foo { ... }`. callee: NameAndSpan } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 0afde5be9a0..291502ff229 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -134,7 +134,7 @@ pub trait Folder { node.move_iter().map(|node| { @Spanned { node: node, - span: d.span, + span: self.new_span(d.span), } }).collect() } |
