@@ -88,6 +88,8 @@ to the original source.
88
88
pub struct Span {
89
89
lo : BytePos ,
90
90
hi : BytePos ,
91
+ /// Information about where the macro came from, if this piece of
92
+ /// code was created by a macro expansion.
91
93
expn_info : Option < @ExpnInfo >
92
94
}
93
95
@@ -162,26 +164,47 @@ pub struct LocWithOpt {
162
164
pub struct FileMapAndLine { fm : Rc < FileMap > , line : uint }
163
165
pub struct FileMapAndBytePos { fm : Rc < FileMap > , pos : BytePos }
164
166
167
+ /// The syntax with which a macro was invoked.
165
168
#[ deriving( Clone , Hash , Show ) ]
166
169
pub enum MacroFormat {
167
- // e.g. #[deriving(...)] <item>
170
+ /// e.g. #[deriving(...)] <item>
168
171
MacroAttribute ,
169
- // e.g. `format!()`
172
+ /// e.g. `format!()`
170
173
MacroBang
171
174
}
172
175
173
176
#[ deriving( Clone , Hash , Show ) ]
174
177
pub struct NameAndSpan {
178
+ /// The name of the macro that was invoked to create the thing
179
+ /// with this Span.
175
180
name : ~str ,
176
- // the format with which the macro was invoked.
181
+ /// The format with which the macro was invoked.
177
182
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.
178
186
span : Option < Span >
179
187
}
180
188
181
189
/// Extra information for tracking macro expansion of spans
182
190
#[ deriving( Hash , Show ) ]
183
191
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.
184
201
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 { ... }`.
185
208
callee : NameAndSpan
186
209
}
187
210
0 commit comments