<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><base href="x-msg://3144/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jun 18, 2013, at 11:33 AM, "Thompson, John" <<a href="mailto:John_Thompson@playstation.sony.com">John_Thompson@playstation.sony.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div lang="EN-US" link="blue" vlink="purple" style="font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="WordSection1" style="page: WordSection1; "><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">Hi,<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">I have a need for a function that will do macro substitution in a string.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">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.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">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.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">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?</div></div></div></blockquote><div><br></div><div>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 ?</div><div>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 ?</div><div><br></div><blockquote type="cite"><div lang="EN-US" link="blue" vlink="purple" style="font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="WordSection1" style="page: WordSection1; "><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">Thanks.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">-John<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div></div>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu" style="color: purple; text-decoration: underline; ">cfe-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" style="color: purple; text-decoration: underline; ">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></div></blockquote></div><br></body></html>