[cfe-dev] SourceLocation -> MacroDefinition(Record?)

Kim Gräsman kim.grasman at gmail.com
Thu May 14 23:59:13 PDT 2015

On Tue, May 12, 2015 at 4:39 AM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Mon, May 11, 2015 at 12:15 PM, Kim Gräsman <kim.grasman at gmail.com> wrote:
>> I've toyed with the idea of recording all macro definitions in a
>> PPCallbacks implementation and building a reverse lookup table from
>> location to macro definition, but I figured Clang might already have
>> that. Does it?
> 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.
> 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.

I honestly can't remember exactly what I want anymore :-), it's been a
few months since I worked on the problematic case, but the
PreprocessingRecord looks interesting.

I think I should be able to use that as a backend for detecting macro
uses more easily and correctly than a custom PPCallbacks, and it looks
like it holds the information necessary to map decl/type uses to the
right file (for some value of right).

Appreciate it, thanks!

- Kim

More information about the cfe-dev mailing list