[cfe-commits] Patch suggestion for libclang
Clint Caywood
clint at clintcaywood.com
Sun Mar 18 13:18:49 PDT 2012
Ping.
I apologize for the poorly named subject of this submission, but rather
than resubmit, I figured it would be better to continue the thread.
This patch fixes clang_getCursorExtent() when called with a CXCursor of
kind CXCursor_TranslationUnit.
Currently, the following snippet (using libclang) will return an empty
range:
CXCursor Cursor = clang_getTranslationUnitCursor(TranslationUnit);
CXSourceRange Range = clang_getCursorExtent(Cursor);
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.
Thanks,
Clint
On Sat, Mar 10, 2012 at 8:40 PM, Clint Caywood <clint at clintcaywood.com>wrote:
> Hi folks,
>
> 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.
>
> Thanks,
> Clint
>
> Index: tools/libclang/CIndex.cpp
> ===================================================================
> --- tools/libclang/CIndex.cpp (revision 152526)
> +++ tools/libclang/CIndex.cpp (working copy)
> @@ -3869,6 +3869,15 @@
> return TU->mapRangeFromPreamble(Range);
> }
>
> + if (C.kind == CXCursor_TranslationUnit) {
> + ASTUnit *TU = getCursorASTUnit(C);
> + FileID MainID = TU->getSourceManager().getMainFileID();
> + SourceLocation Start =
> TU->getSourceManager().getLocForStartOfFile(MainID);
> + SourceLocation End =
> TU->getSourceManager().getLocForEndOfFile(MainID);
> + SourceRange Range(Start, End);
> + return TU->mapRangeFromPreamble(Range);
> + }
> +
> if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) {
> Decl *D = cxcursor::getCursorDecl(C);
> if (!D)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120318/0f0c73f8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tUnitExtents.patch
Type: text/x-patch
Size: 787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120318/0f0c73f8/attachment.bin>
More information about the cfe-commits
mailing list