From: Argyrios Kyrtzidis Date: Mon, 19 Mar 2012 23:17:58 +0000 (+0000) Subject: [libclang] Have clang_getCursorExtent() return the range of the main file when X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0822c5f29d91a08697416b0d0be28dd3e71d945a;p=clang [libclang] Have clang_getCursorExtent() return the range of the main file when the passed cursor is the translation unit cursor. Patch by Clint Caywood! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153062 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 52a7cd6a5d..cb86c46ba4 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -3869,6 +3869,14 @@ static SourceRange getRawCursorExtent(CXCursor C) { 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); + return SourceRange(Start, End); + } + if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) { Decl *D = cxcursor::getCursorDecl(C); if (!D)