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. 


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85425 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 5ffa6d7..71d7653 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/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;
diff --git a/tools/CIndex/CIndex.exports b/tools/CIndex/CIndex.exports
index b726aa0..d2933cb 100644
--- a/tools/CIndex/CIndex.exports
+++ b/tools/CIndex/CIndex.exports
@@ -7,7 +7,6 @@
 _clang_getCursorKind
 _clang_getCursorLine
 _clang_getCursorSource
-_clang_getCursorWithHint
 _clang_getDeclarationName
 _clang_getDeclSpelling
 _clang_getDeclLine
@@ -21,7 +20,6 @@
 _clang_createTranslationUnit
 _clang_createTranslationUnitFromSourceFile
 _clang_disposeTranslationUnit
-_clang_initCXLookupHint
 _clang_isDeclaration
 _clang_isReference
 _clang_isDefinition
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 56b29ac..8791ee2 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -70,7 +70,6 @@
         CXCursor Ref;
 
         while (startBuf < endBuf) {
-          CXLookupHint hint;
           if (*startBuf == '\n') {
             startBuf++;
             curLine++;
@@ -78,11 +77,8 @@
           } else if (*startBuf != '\t')
             curColumn++;
           
-          clang_initCXLookupHint(&hint);
-          hint.decl = Cursor.decl;
-
-          Ref = clang_getCursorWithHint(Unit, clang_getCursorSource(Cursor),
-                                        curLine, curColumn, &hint);
+          Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor),
+                                curLine, curColumn);
           if (Ref.kind == CXCursor_NoDeclFound) {
             /* Nothing found here; that's fine. */
           } else if (Ref.kind != CXCursor_FunctionDecl) {