[cfe-dev] Determining macros used in a function or SourceRange (using clang plugin)

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 28 11:50:33 PDT 2016

On Wed, Sep 28, 2016 at 11:29 AM, Eric Bayer via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Oh, one follow on question... If I persist a MacroDefinition* or
> MacroInfo* in a datastructure, will this still exist when processing the
> AST tree or will these have been deleted out from under me?  Just trying to
> understand how much info I need to copy in a few cases.

MacroInfo, MacroDirective and ModuleMacro objects should persist until the
Preprocessor object is destroyed. You can hold onto them until that happens.

MacroDefinition has value semantics, so if you want to persist a
MacroDefinition* it's up to you to store the MacroDefinition object
somewhere. But you should probably just be passing it around by value.

>    -Eric
> On 9/27/2016 6:59 PM, Eric Bayer wrote:
>> Hi Alex,
>> Thanks again for all your help.  Actually I did manage to make this
>> eventually work with a huge amount of Lexer/Token magic. Unfortunately I
>> could not actually follow it past 1 level, so it looks like an unworkable
>> solution for what I have in mind. I had thought the macro definitons were
>> expanded from other macros. After digging though the SLocEntries, this is
>> clearly not the case and they are expanded at their final uses.  This means
>> I'm going back to the PPCallbacks and digging in there.  I think I can get
>> the whole tree without annotating every macro I meet. Apparently
>> MacroExpands gets called repeatedly at the point the macro gets used.
>> Kind Regards,
>>    -Eric
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160928/9b3a78cc/attachment.html>

More information about the cfe-dev mailing list