[libclang] Indexing API:

-For indexDeclaration, also pass the declaration attributes as an array of cursors.
-Rename CXIndexOpt_OneRefPerFile -> CXIndexOpt_SuppressRedundantRefs, and only pass
  a reference if a declaration/definition does not exist in the file.
-Other fixes.

llvm-svn: 144942
diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp
index 4540f97..5858faa 100644
--- a/clang/tools/libclang/Indexing.cpp
+++ b/clang/tools/libclang/Indexing.cpp
@@ -117,6 +117,10 @@
 
   virtual void HandleTopLevelDecl(DeclGroupRef DG) {
     IndexCtx.indexDeclGroupRef(DG);
+    // FIXME: Indicate to parser to abort.
+//    if (IndexCtx.shouldAbort()) {
+//      
+//    }
   }
 
   /// \brief Handle the specified top-level declaration that occurred inside
@@ -133,29 +137,9 @@
 };
 
 //===----------------------------------------------------------------------===//
-// IndexingDiagnosticConsumer
+// CaptureDiagnosticConsumer
 //===----------------------------------------------------------------------===//
 
-class IndexingDiagnosticConsumer : public DiagnosticConsumer {
-  IndexingContext &IndexCtx;
-  
-public:
-  explicit IndexingDiagnosticConsumer(IndexingContext &indexCtx)
-    : IndexCtx(indexCtx) {}
-  
-  virtual void HandleDiagnostic(DiagnosticsEngine::Level Level,
-                                const Diagnostic &Info) {
-    // Default implementation (Warnings/errors count).
-    DiagnosticConsumer::HandleDiagnostic(Level, Info);
-
-    IndexCtx.handleDiagnostic(StoredDiagnostic(Level, Info));
-  }
-
-  DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
-    return new IgnoringDiagConsumer();
-  }
-};
-
 class CaptureDiagnosticConsumer : public DiagnosticConsumer {
   SmallVector<StoredDiagnostic, 4> Errors;
 public:
@@ -187,8 +171,6 @@
 
   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
                                          StringRef InFile) {
-    CI.getDiagnostics().setClient(new IndexingDiagnosticConsumer(IndexCtx),
-                                  /*own=*/true);
     IndexCtx.setASTContext(CI.getASTContext());
     Preprocessor &PP = CI.getPreprocessor();
     PP.addPPCallbacks(new IndexPPCallbacks(PP, IndexCtx));
@@ -426,6 +408,8 @@
                                   TLEnd = Unit.top_level_end();
            TL != TLEnd; ++TL) {
       IdxCtx.indexTopLevelDecl(*TL);
+      if (IdxCtx.shouldAbort())
+        return;
     }
 
   } else {
@@ -433,17 +417,15 @@
     for (TranslationUnitDecl::decl_iterator
            I = TUDecl->decls_begin(), E = TUDecl->decls_end(); I != E; ++I) {
       IdxCtx.indexTopLevelDecl(*I);
+      if (IdxCtx.shouldAbort())
+        return;
     }
   }
 }
 
 static void indexDiagnostics(CXTranslationUnit TU, IndexingContext &IdxCtx) {
-  unsigned Num = clang_getNumDiagnostics(TU);
-  for (unsigned i = 0; i != Num; ++i) {
-    CXDiagnostic Diag = clang_getDiagnostic(TU, i);
-    IdxCtx.handleDiagnostic(Diag);
-    clang_disposeDiagnostic(Diag);
-  }
+  // FIXME: Create a CXDiagnosticSet from TU;
+  // IdxCtx.handleDiagnosticSet(Set);
 }
 
 static void clang_indexTranslationUnit_Impl(void *UserData) {
@@ -568,6 +550,19 @@
   return 0;
 }
 
+const CXIdxIBOutletCollectionAttrInfo *
+clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *AInfo) {
+  if (!AInfo)
+    return 0;
+
+  const AttrInfo *DI = static_cast<const AttrInfo *>(AInfo);
+  if (const IBOutletCollectionInfo *
+        IBInfo = dyn_cast<IBOutletCollectionInfo>(DI))
+    return &IBInfo->IBCollInfo;
+
+  return 0;
+}
+
 int clang_indexSourceFile(CXIndex CIdx,
                                 CXClientData client_data,
                                 IndexerCallbacks *index_callbacks,