<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 30, 2011, at 10:02 AM, Chandler Carruth wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Sun, May 29, 2011 at 2:38 PM, Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>> wrote:<br><blockquote type="cite">I completely agree and the extra info about argument expansion is a great improvement but it still doesn't provide *all* the info a client may need to fully explore a macro expansion.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I think what a client ultimately needs (and hopefully Abramo may offer further insights) is 2 things, a list of all the locations of tokens of the macro expansion and the source location of the macro definition that was responsible for the expansion.<br></blockquote><br>This isn't sufficient for some of our applications, and I don't think<br>is sufficient to generate these diagnostics.<br><br>We also need to know what tokens come from macro arguments as opposed<br>to the macro definition's tokens.<br><br>Currently, the lexer expands function-style macros recursively on<br>demand. This means that we actually don't have a token sequence<br>representing the definition of the macro (pre-expansion). I actually<br>like this because it accurately reflects the defined semantics of the<br>preprocessor.<br><br>What we need are for the source locations of each token in the fully<br>expanded token stream to accurately represent whether the token was<br>expanded directly from the macro definition's tokens, or whether it<br>was expanded first from the argument token stream into the macro<br>definition token stream, and then back into the final fully-expanded<br>token stream. That's precisely what my patch does.<br><br>I also don't think we need to store any extra info to find the<br>location of a macro definition. It should be the immediate spelling<br>location. Macro arguments have a second instantiation record that will<br>take you back to the original spelling location in the call site, but<br>its first spelling location step should step into macro definition.<br><br><blockquote type="cite">All info that a client may need can be derived/reconstructed by these 2 pieces of info and we can offer helper routines for the more commonly useful info (e.g. for the position of the macro argument, or the source range of the input to the macro argument).<br></blockquote><br>It's not clear to me how you get the position of the macro argument<br>without re-lexing... which would be really unfortunate cost.<br></div></blockquote><div><br></div><div>Yeah but is the cost unacceptable ? We only do this to display the diagnostic. Nevertheless I'm not opposed to your patch if it doesn't affect normal performance. I'm mostly interested in providing a general solution to clients for analyzing macros without having to resort to re-lexing the whole translation unit (!).</div><br><blockquote type="cite"><div><br><blockquote type="cite">We can already get a list of tokens, we just don't expose it to clients; we can provide a list of all the source locations of the macro tokens and the client can derive a list of the spelling locations/tokens.<br></blockquote><blockquote type="cite">We are unable to provide the location of the macro definition responsible for the expansion because we don't keep it anywhere. Maybe add a SourceLocation in InstantiationInfo ?<br></blockquote><br>I think this is already available via the spelling location chain...<br></div></blockquote></div><div><br></div>Let's say:<div><br><div><font class="Apple-style-span" face="Courier">#define M1 blah \</font></div><div><font class="Apple-style-span" face="Courier">           blah \</font></div><div><font class="Apple-style-span" face="Courier">           foo</font></div><div><br></div><div>I want to be able to say "the token came from a macro whose definition is here:</div><div><br></div><div><font class="Apple-style-span" face="Courier">#define M1 blah \</font></div><div><font class="Apple-style-span" face="Courier">        ^</font></div><div><div><br></div><div>How do you do that with the spelling location chain ?</div><div><br></div></div></div></body></html>