From 85ff90c86c98b9fad41f792a8fabb145db320a50 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 27 Mar 2014 00:40:51 +1100 Subject: [PATCH 1/2] syntax: add a some docs/clarification to the fields of ExpnInfo. --- src/libsyntax/codemap.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 325df5fda60e7..4a9e53c63e7bf 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, line: uint} pub struct FileMapAndBytePos {fm: Rc, pos: BytePos} +/// The syntax with which a macro was invoked. #[deriving(Clone, Hash, Show)] pub enum MacroFormat { - // e.g. #[deriving(...)] + /// e.g. #[deriving(...)] 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 } /// 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 } From 6419848e66e1a8dd73204711d4e589e4b7f341ef Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 27 Mar 2014 00:47:14 +1100 Subject: [PATCH 2/2] syntax: add a missing span rewrite in fold. This was leaving Decls without the new spans; this is a minor change, since literally nothing reads in the code base reads the span of a Decl itself, always just its contents. --- src/libsyntax/fold.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 0afde5be9a076..291502ff229b6 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() }