<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, May 11, 2015 at 12:15 PM, Kim Gräsman <span dir="ltr"><<a href="mailto:kim.grasman@gmail.com" target="_blank">kim.grasman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
For IWYU, we can usually make better suggestions if we know whether a<br>
use happens inside a macro or not.<br>
<br>
I should be able to use SourceLocation::isMacroID to ask whether I'm<br>
in *a* macro, but is there a way to go from there to *which* macro?<br>
I'm guessing that's represented by the new MacroDefinition class.<br>
<br>
I've toyed with the idea of recording all macro definitions in a<br>
PPCallbacks implementation and building a reverse lookup table from<br>
location to macro definition, but I figured Clang might already have<br>
that. Does it?</blockquote><div><br></div><div>Yes, but it depends on what you want. You can ask the SourceManager for information about a macro SourceLocation to find where the macro was defined and where it was expanded. In common cases you can get the name of the macro this way, but if the name of the macro was itself produced by macro expansion, it's tricky to extract that information from the SourceManager.</div><div><br></div><div>If you want more information, one option would be to use clang::PreprocessingRecord. This is a prebuilt implementation of what you mention above: a PPCallbacks implementation that tracks the macro expansion history.</div></div></div></div>