]> granicus.if.org Git - clang/commitdiff
[libclang] Have clang_getCursorExtent() return the range of the main file when
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 19 Mar 2012 23:17:58 +0000 (23:17 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 19 Mar 2012 23:17:58 +0000 (23:17 +0000)
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

tools/libclang/CIndex.cpp

index 52a7cd6a5dd933a2e2916e0f9c566296b150eb99..cb86c46ba44bf39de0b98a17922943c2fbc06c8e 100644 (file)
@@ -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)