<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Apr 24, 2008, at 9:42 AM, Emerson Murphy-Hill wrote:</div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite">Same thing works for those.  An example s HTMLRewriter.cpp, html::SyntaxHighlight:<br><br>    unsigned TokOffs = SourceMgr.getFullFilePos(Tok.getLocation());<br>    unsigned TokLen = Tok.getLength();<br>...<br>    case tok::comment:<br>      HighlightRange(RB, TokOffs, TokOffs+TokLen, BufferStart,<br>                     "<span class='comment'>", "</span>");<br></blockquote></div><br><div>I did find this code, and my code works properly for single line comments. I still don't see how this technique works for multiline comments (but I could just be being dense [well, more so than usual]).  How about this; fill in the question marks:</div><div><br></div><div><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "><span style="color: #5c2699">SourceLocation</span> startLoc = token.<span style="color: #2e0d6e">getLocation</span>();</span></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: #aa0d91">int</span> startLine = <span style="color: #3f6e74">_manager</span>-><span style="color: #2e0d6e">getLogicalLineNumber</span>(startLoc);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: #aa0d91">int</span> startCol = <span style="color: #3f6e74">_manager</span>-><span style="color: #2e0d6e">getLogicalColumnNumber</span>(startLoc);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #aa0d91">int</span><span style="color: #000000"> endLine = ?;</span>//"startLine" is wrong for multi-line comments</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #aa0d91">int</span><span style="color: #000000"> endCol = ?;</span>//"startCol + token.getLength()" is wrong too</div></div></div></blockquote><br></div><div>To get the end position, you need to get a SourceLocation for the end of the token, then ask SM the line/col of that *location*.  This will properly handle the various craziness that C includes.</div><div><br class="webkit-block-placeholder"></div><div>See this post for info on getting the source location for the end of a token:</div><div><a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-April/001501.html">http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-April/001501.html</a></div><div><br class="webkit-block-placeholder"></div><div>Incidentally, improvements to the internals document are very welcome :)</div><div><br class="webkit-block-placeholder"></div><div>-Chris</div></body></html>