[cfe-dev] macro-expanded/preprocessed string (clangLex) question
Thompson, John
John_Thompson at playstation.sony.com
Tue Jun 18 15:43:14 PDT 2013
Or let me rephrase it another way.
Perhaps there is another way of getting the preprocessed snippet without reprocessing, such as might be done in a diagnostic?
-John
From: cfe-dev-bounces at cs.uiuc.edu [mailto:cfe-dev-bounces at cs.uiuc.edu] On Behalf Of Thompson, John
Sent: Tuesday, June 18, 2013 11:34 AM
To: cfe-dev at cs.uiuc.edu
Subject: [cfe-dev] macro-expanded/preprocessed string (clangLex) question
Hi,
I have a need for a function that will do macro substitution in a string.
This is for the modularize tool I am trying to enhance to show where preprocessor conditional directives' condition expressions differ in different instances of preprocessing a header. I use a PPCallbacks-derived class to track the #if/#elif/#ifdef/#ifndef directives. The callback function arguments include a SourceRange. I can use that to get the unpreprocessed source snippet for the condition expression. I want to take either that source snippet or the SourceRange and get a string that has had any macros in the unpreprocessed source snippet expanded, including function-style macros. White space is not important, as it just needs to be consistent. I do a comparison of the macro-expanded condition strings to find out if an instance of a header differs from other instances.
In looking at the Preprocessor class, I didn't see such a function. In thinking about how it might be done, because this is to be done in the context of a PPCallbacks callback call, I'm thinking there might be the potential for problems with interfering with the preprocessor or lexer state. Therefore my current thinking is that I probably will need to instantiate a separate Lexer, and probably a separate Preprocessor too, with the Preprocessor linked to the original preprocessor so it can find the macro definitions. (There seems to be a pointer for this in Preprocessor.) The pragma mode in Lexer seems comparable, but I don't want the raw lexing mode, so I'd probably need a new constructor that lets me set the buffer pointers and the right mode settings. Also, I probably don't want the Preprocessor to be calling PPCallback callbacks such as the MacroExpanded callback.
Could someone point me to existing code that could do this, or otherwise help me get the information or code I need to do this?
Thanks.
-John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130618/ceeed9ca/attachment.html>
More information about the cfe-dev
mailing list