Adjust clang_annotateTokens() to correctly account for the TypeSourceInfo for DeclaratorDecls
when annotating tokens. Fixes <rdar://problem/7971430>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103577 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 3d55a10..0e6f341 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -2426,12 +2426,31 @@
CXSourceRange cursorExtent = clang_getCursorExtent(cursor);
SourceRange cursorRange = cxloc::translateCXSourceRange(cursorExtent);
-
+
if (cursorRange.isInvalid())
return CXChildVisit_Continue;
-
+
SourceLocation L = SourceLocation::getFromRawEncoding(Loc.int_data);
+ // Adjust the annotated range based specific declarations.
+ const enum CXCursorKind cursorK = clang_getCursorKind(cursor);
+ if (cursorK >= CXCursor_FirstDecl && cursorK <= CXCursor_LastDecl) {
+ if (const DeclaratorDecl *DD =
+ dyn_cast<DeclaratorDecl>(cxcursor::getCursorDecl(cursor))) {
+ if (TypeSourceInfo *TI = DD->getTypeSourceInfo()) {
+ TypeLoc TL = TI->getTypeLoc();
+ SourceLocation TLoc = TL.getFullSourceRange().getBegin();
+ unsigned col1 = SrcMgr.getSpellingColumnNumber(L);
+ unsigned col2 = SrcMgr.getSpellingColumnNumber(TLoc);
+
+ if (TLoc.isValid()) {
+ assert(SrcMgr.isBeforeInTranslationUnit(TLoc, L));
+ cursorRange.setBegin(TLoc);
+ }
+ }
+ }
+ }
+
const enum CXCursorKind K = clang_getCursorKind(parent);
const CXCursor updateC =
(clang_isInvalid(K) || K == CXCursor_TranslationUnit ||
@@ -2441,6 +2460,7 @@
while (MoreTokens()) {
const unsigned I = NextToken();
SourceLocation TokLoc = GetTokenLoc(I);
+ unsigned col3 = SrcMgr.getSpellingColumnNumber(TokLoc);
switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) {
case RangeBefore:
Cursors[I] = updateC;