[cfe-dev] Macro expansion in the Rewriter?

David Chisnall David.Chisnall at cl.cam.ac.uk
Tue Nov 27 01:23:17 PST 2012

On 27 Nov 2012, at 00:30, Eli Friedman wrote:

> It sounds like useful functionality.  We don't store whether an
> identifier is an expanded macro or what it expanded to in any
> convenient way, though, so it would be a pain to implement.

I investigated this over the weekend and came to a similar conclusion.  I have a student currently working on a code reformatting tool who wants to be able to see, from libclang, if a macro expansion contains open or close braces.  I'd assumed that this would be something easy to expose, but it seems that we don't actually have any way of finding the sequence of tokens generated by a macro expansion (this is generated by the preprocessor, but not stored anywhere).  Even the HTML Rewriter, which (given the output in the static analyser) I assumed would already have code for doing it contains a half-implemented duplication of the macro expansion logic.

If someone's looking for a project, then factoring the macro expansion code out so that it could be rerun (the current code is destructive) would be very helpful.  It would also improve diagnostics a lot if you could say exactly what the macro expansion was, not just the chain of macros that caused it.


More information about the cfe-dev mailing list