Skip to content

Commit 85ff90c

Browse files
committed
syntax: add a some docs/clarification to the fields of ExpnInfo.
1 parent 2c7f3b8 commit 85ff90c

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/libsyntax/codemap.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ to the original source.
8888
pub struct Span {
8989
lo: BytePos,
9090
hi: BytePos,
91+
/// Information about where the macro came from, if this piece of
92+
/// code was created by a macro expansion.
9193
expn_info: Option<@ExpnInfo>
9294
}
9395

@@ -162,26 +164,47 @@ pub struct LocWithOpt {
162164
pub struct FileMapAndLine {fm: Rc<FileMap>, line: uint}
163165
pub struct FileMapAndBytePos {fm: Rc<FileMap>, pos: BytePos}
164166

167+
/// The syntax with which a macro was invoked.
165168
#[deriving(Clone, Hash, Show)]
166169
pub enum MacroFormat {
167-
// e.g. #[deriving(...)] <item>
170+
/// e.g. #[deriving(...)] <item>
168171
MacroAttribute,
169-
// e.g. `format!()`
172+
/// e.g. `format!()`
170173
MacroBang
171174
}
172175

173176
#[deriving(Clone, Hash, Show)]
174177
pub struct NameAndSpan {
178+
/// The name of the macro that was invoked to create the thing
179+
/// with this Span.
175180
name: ~str,
176-
// the format with which the macro was invoked.
181+
/// The format with which the macro was invoked.
177182
format: MacroFormat,
183+
/// The span of the macro definition itself. The macro may not
184+
/// have a sensible definition span (e.g. something defined
185+
/// completely inside libsyntax) in which case this is None.
178186
span: Option<Span>
179187
}
180188

181189
/// Extra information for tracking macro expansion of spans
182190
#[deriving(Hash, Show)]
183191
pub struct ExpnInfo {
192+
/// The location of the actual macro invocation, e.g. `let x =
193+
/// foo!();`
194+
///
195+
/// This may recursively refer to other macro invocations, e.g. if
196+
/// `foo!()` invoked `bar!()` internally, and there was an
197+
/// expression inside `bar!`; the call_site of the expression in
198+
/// the expansion would point to the `bar!` invocation; that
199+
/// call_site span would have its own ExpnInfo, with the call_site
200+
/// pointing to the `foo!` invocation.
184201
call_site: Span,
202+
/// Information about the macro and its definition.
203+
///
204+
/// The `callee` of the inner expression in the `call_site`
205+
/// example would point to the `macro_rules! bar { ... }` and that
206+
/// of the `bar!()` invocation would point to the `macro_rules!
207+
/// foo { ... }`.
185208
callee: NameAndSpan
186209
}
187210

0 commit comments

Comments
 (0)