Remove _clang_initCXLookupHint() and _clang_getCursorWithHint(). Related to <rdar://problem/7310688>.
Localize the optimization to ResolveLocationInAST(). The last valid AST location is now stored with ASTUnit. There still isn't optimal, however it's an improvement (with a much cleaner API). Having the client manage an "hint" is error prone and complex.
I wanted to land the major changes before finishing up the optimizations.
llvm-svn: 85425
diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp
index 5ffa6d7..71d7653 100644
--- a/clang/tools/CIndex/CIndex.cpp
+++ b/clang/tools/CIndex/CIndex.cpp
@@ -116,6 +116,10 @@
if (ND->getPCHLevel() > MaxPCHLevel)
return;
+ // Filter any implicit declarations (since the source info will be bogus).
+ if (ND->isImplicit())
+ return;
+
CXCursor C = { CK, ND, 0 };
Callback(TUnit, C, CData);
}
@@ -721,26 +725,12 @@
//
// CXCursor Operations.
//
-void clang_initCXLookupHint(CXLookupHint *hint) {
- memset(hint, 0, sizeof(*hint));
-}
-
CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
- unsigned line, unsigned column) {
- return clang_getCursorWithHint(CTUnit, source_name, line, column, NULL);
-}
-
-CXCursor clang_getCursorWithHint(CXTranslationUnit CTUnit,
- const char *source_name,
- unsigned line, unsigned column,
- CXLookupHint *hint)
+ unsigned line, unsigned column)
{
assert(CTUnit && "Passed null CXTranslationUnit");
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
- // FIXME: Make this better.
- CXDecl RelativeToDecl = hint ? hint->decl : NULL;
-
FileManager &FMgr = CXXUnit->getFileManager();
const FileEntry *File = FMgr.getFile(source_name,
source_name+strlen(source_name));
@@ -751,9 +741,13 @@
SourceLocation SLoc =
CXXUnit->getSourceManager().getLocation(File, line, column);
- ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc,
- static_cast<NamedDecl *>(RelativeToDecl));
-
+ ASTLocation LastLoc = CXXUnit->getLastASTLocation();
+
+ ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc,
+ &LastLoc);
+ if (ALoc.isValid())
+ CXXUnit->setLastASTLocation(ALoc);
+
Decl *Dcl = ALoc.getParentDecl();
if (ALoc.isNamedRef())
Dcl = ALoc.AsNamedRef().ND;