<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Dec 17, 2009, at 5:23 AM, steve naroff wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On Dec 17, 2009, at 7:05 AM, Abramo Bagnara wrote:<br><br><blockquote type="cite">In an application that uses clang libraries we need to transform some<br></blockquote><blockquote type="cite">specially written comments in C construct.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">e.g:<br></blockquote><blockquote type="cite">int p() {<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">   </span>int a = 3;<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">     </span>/* #instrument(a)# */<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">should be parsed as<br></blockquote><blockquote type="cite">int p() {<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre"> </span>int a = 3;<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">     </span>instrument(a);<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I've added a CommentHandler to Preprocessor to catch comments and I<br></blockquote><blockquote type="cite">thought to use Rewriter class to manipulate the input buffer inserting<br></blockquote><blockquote type="cite">after the comment the text to be parsed, but then I've realized that<br></blockquote><blockquote type="cite">Rewriter class is not designed to rewrite lexer input buffers, but to<br></blockquote><blockquote type="cite">build a separate object where original text and changes live together.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Now I'm a bit confused: what's the proper way to cope with the need<br></blockquote><blockquote type="cite">described above?<br></blockquote><blockquote type="cite"><br></blockquote><br>Hi Abramo,<br><br>The ASTContext class has a 'Comments' member that contains all the  <br>SourceRanges's for all comments in the source file.<br><br>This assumes you've told the preprocessor to keep comments.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><br></div><div>You actually don't have to tell the preprocessor to keep comments; it keeps the source ranges for the comments regardless, and you can go back to the source to get the content of the comments.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">   </span>- Doug</div><br></body></html>