[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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144942 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/IndexBody.cpp b/tools/libclang/IndexBody.cpp
index ece1ed4..60fe2cf 100644
--- a/tools/libclang/IndexBody.cpp
+++ b/tools/libclang/IndexBody.cpp
@@ -10,6 +10,7 @@
 #include "IndexingContext.h"
 
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Analysis/Support/SaveAndRestore.h"
 
 using namespace clang;
 using namespace cxindex;
@@ -19,10 +20,12 @@
 class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
   IndexingContext &IndexCtx;
   const DeclContext *ParentDC;
+  bool InPseudoObject;
 
+  typedef RecursiveASTVisitor<BodyIndexer> base;
 public:
   BodyIndexer(IndexingContext &indexCtx, const DeclContext *DC)
-    : IndexCtx(indexCtx), ParentDC(DC) { }
+    : IndexCtx(indexCtx), ParentDC(DC), InPseudoObject(false) { }
   
   bool shouldWalkTypesOfTypeLocs() const { return false; }
 
@@ -48,8 +51,13 @@
   }
 
   bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
+    if (TypeSourceInfo *Cls = E->getClassReceiverTypeInfo())
+      IndexCtx.indexTypeSourceInfo(Cls, 0, ParentDC);
+
     if (ObjCMethodDecl *MD = E->getMethodDecl())
-      IndexCtx.handleReference(MD, E->getSelectorStartLoc(), 0, ParentDC, E);
+      IndexCtx.handleReference(MD, E->getSelectorStartLoc(), 0, ParentDC, E,
+                               InPseudoObject ? CXIdxEntityRef_Implicit
+                                              : CXIdxEntityRef_Direct);
     return true;
   }
 
@@ -57,16 +65,21 @@
     if (E->isImplicitProperty()) {
       if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter())
         IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E,
-                                 CXIdxEntityRef_ImplicitProperty);
+                                 CXIdxEntityRef_Implicit);
       if (ObjCMethodDecl *MD = E->getImplicitPropertySetter())
         IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E,
-                                 CXIdxEntityRef_ImplicitProperty);
+                                 CXIdxEntityRef_Implicit);
     } else {
       IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(), 0,
                                ParentDC, E);
     }
     return true;
   }
+
+  bool TraversePseudoObjectExpr(PseudoObjectExpr *E) {
+    SaveAndRestore<bool> InPseudo(InPseudoObject, true);
+    return base::TraversePseudoObjectExpr(E);
+  }
 };
 
 } // anonymous namespace