[cfe-dev] macro-expanded/preprocessed string (clangLex) question
Thompson, John
John_Thompson at playstation.sony.com
Fri Jun 21 11:05:33 PDT 2013
Argyrios,
Sorry, I totally missed your message.
>It seems to me that you mainly need to keep track of whether the conditional directive block was skipped or not, so how about adding a bool parameter to the If/Elif/Else callbacks to have them provide that info ?
Then you apparently want to inform the user what macros were different (that caused the condition to evaluate differently) so maybe keep track of macro expansions inside the condition and point/warn at the macro definitions when they differ ?
Yes, that is what I was thinking. But I wanted to have a go at it first without modifying the PPCallbacks API. Currently I'm collecting macro expansions from the MacroExpanded callback, but function-style macros are a bit trickier.
-John
From: Argyrios Kyrtzidis [mailto:akyrtzi at gmail.com]
Sent: Tuesday, June 18, 2013 5:31 PM
To: Thompson, John
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] macro-expanded/preprocessed string (clangLex) question
On Jun 18, 2013, at 11:33 AM, "Thompson, John" <John_Thompson at playstation.sony.com<mailto:John_Thompson at playstation.sony.com>> wrote:
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?
It seems to me that you mainly need to keep track of whether the conditional directive block was skipped or not, so how about adding a bool parameter to the If/Elif/Else callbacks to have them provide that info ?
Then you apparently want to inform the user what macros were different (that caused the condition to evaluate differently) so maybe keep track of macro expansions inside the condition and point/warn at the macro definitions when they differ ?
Thanks.
-John
_______________________________________________
cfe-dev mailing list
cfe-dev at cs.uiuc.edu<mailto:cfe-dev at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130621/14a3cb2e/attachment.html>
More information about the cfe-dev
mailing list