[cfe-dev] #undefine cursors

Iestyn Bleasdale-Shepherd iestyn at valvesoftware.com
Mon Nov 5 11:59:35 PST 2012

This is perfect - thanks for the info, guys! :)


From: cfe-dev-bounces at cs.uiuc.edu [mailto:cfe-dev-bounces at cs.uiuc.edu] On Behalf Of Douglas Gregor
Sent: Monday, November 05, 2012 10:47 AM
To: Alexander Kornienko
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] #undefine cursors

On Nov 4, 2012, at 5:11 PM, Alexander Kornienko <alexfh at google.com<mailto:alexfh at google.com>> wrote:

On Sat, Nov 3, 2012 at 2:43 PM, Matthieu Monrocq <matthieu.monrocq at gmail.com<mailto:matthieu.monrocq at gmail.com>> wrote:

On Fri, Nov 2, 2012 at 10:34 PM, Iestyn Bleasdale-Shepherd <iestyn at valvesoftware.com<mailto:iestyn at valvesoftware.com>> wrote:

When using the libclang API, '#define' statements yield cursors, but '#undefine' statements do not.

Without a record of #undefines, I can't determine which #defines are extant at any given point in the code, and am thus unable to fully determine dependencies between source files.

Is it possible to determine which #defines are active for a given source location, or would the addition of #undefine cursors be a reasonable feature request for the libclang API?


iestyn Bleasdale-Shepherd

Well, you are lucky in that a good chunk of work went on recently into what was called "Macro History" whose goal is exactly to remember every single #define/#undef that a macro encountered in the pre-processing of the translation unit. Therefore, using this macro history, it should be possible to extract this information.

Unfortunately, I do not know the exact API, Alexander Kornienko initiated the work on this, so he probably followed it, I have added him in CC so he can help us figure out exactly where this feature stands.

-- Matthieu

Yep, there were a couple of related patches: http://llvm-reviews.chandlerc.com/rL162810, http://llvm-reviews.chandlerc.com/rL164610.

If you want to have a read-only access to macro history in libclang, you'll probably need to forward these methods:
IdentifierInfo::hadMacroDefinition(), Preprocessor::getMacroInfoHistory(IdentifierInfo *), MacroInfo::getPreviousDefinition(), MacroInfo::getUndefLoc()

The longer-term goal here is to switch libclang's macro cursors over to the Preprocessor's MacroInfo, abolishing the "detailed preprocessor record" currently used by libclang.

            - Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121105/77a331de/attachment.html>

More information about the cfe-dev mailing list