<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Hi Clint,</div><div><br></div><div>On Mar 18, 2012, at 1:18 PM, Clint Caywood wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Ping.<div><br></div><div>I apologize for the poorly named subject of this submission, but rather than resubmit, I figured it would be better to continue the thread. </div><div><br></div><div>This patch fixes clang_getCursorExtent() when called with a CXCursor of kind CXCursor_TranslationUnit.</div>

<div><br></div><div>Currently, the following snippet (using libclang) will return an empty range:<div><br></div><div><div>    CXCursor Cursor = clang_getTranslationUnitCursor(TranslationUnit);</div><div>    CXSourceRange Range = clang_getCursorExtent(Cursor);</div>

</div><div><br></div><div>This patch will cause the range to include the entire file from which the translation unit was created. I have a attached the fresh patch.</div><div><br></div><div>Thanks,</div><div>Clint</div><br>

<div class="gmail_quote">On Sat, Mar 10, 2012 at 8:40 PM, Clint Caywood <span dir="ltr"><<a href="mailto:clint@clintcaywood.com">clint@clintcaywood.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">

Hi folks,<div><br></div><div>I'm new to this, but I've made a patch to libclang that allows it to properly get the range for a translation unit cursor (which I needed for a project I'm working on).  It's pretty straightforward.</div>


<div><br></div><div>Thanks,</div><div>Clint</div><div><br></div><div><div>Index: tools/libclang/CIndex.cpp</div><div>===================================================================</div><div>--- tools/libclang/CIndex.cpp<span style="white-space:pre-wrap">     </span>(revision 152526)</div>


<div>+++ tools/libclang/CIndex.cpp<span style="white-space:pre-wrap">     </span>(working copy)</div><div>@@ -3869,6 +3869,15 @@</div><div>     return TU->mapRangeFromPreamble(Range);</div><div>   }</div>
<div> </div><div>+  if (C.kind == CXCursor_TranslationUnit) {</div><div>+    ASTUnit *TU = getCursorASTUnit(C);</div><div>+    FileID MainID = TU->getSourceManager().getMainFileID();</div><div>+    SourceLocation Start = TU->getSourceManager().getLocForStartOfFile(MainID);</div>


<div>+    SourceLocation End = TU->getSourceManager().getLocForEndOfFile(MainID);</div><div>+    SourceRange Range(Start, End);</div><div>+    return TU->mapRangeFromPreamble(Range);</div></div></blockquote></div></div></blockquote><div><br></div><div>The mapRangeFromPreamble() call is not necessary, since the range comes from the main FileID, not the preamble FileID.</div><div><br></div><div>Can you elaborate on how you are using the this extent range later on your application ? Would it be useful to be able to get the extent of any file, not just the main one ?</div><div><br></div><div>-Argyrios</div><br><blockquote type="cite"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; "><div><div>+  }</div><div>+</div>


<div>   if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) {</div><div>     Decl *D = cxcursor::getCursorDecl(C);</div><div>     if (!D)</div></div>
</blockquote></div><br></div>
<span><tUnitExtents.patch></span>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits<br></blockquote></div><br></body></html>