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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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>+ }</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>