[libclang] Simplify the indexing API.

Cut down the number of callbacks to more generic ones. Clients can check
an enum to find out what kind of declaration it is and they can call functions
to get more specific information than the generic provided info.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144343 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/IndexDecl.cpp b/tools/libclang/IndexDecl.cpp
index 5cf9f80..5087355 100644
--- a/tools/libclang/IndexDecl.cpp
+++ b/tools/libclang/IndexDecl.cpp
@@ -29,9 +29,9 @@
     if (D->isThisDeclarationADefinition()) {
       const Stmt *Body = D->getBody();
       if (Body) {
-        IndexCtx.invokeStartedStatementBody(D, D);
+        IndexCtx.startContainer(D, /*isBody=*/true);
         IndexCtx.indexBody(Body, D);
-        IndexCtx.invokeEndedContainer(D);
+        IndexCtx.endContainer(D);
       }
     }
     return true;
@@ -68,15 +68,7 @@
   }
 
   bool VisitObjCClassDecl(ObjCClassDecl *D) {
-    ObjCClassDecl::ObjCClassRef *Ref = D->getForwardDecl();
-    if (Ref->getInterface()->getLocation() == Ref->getLocation()) {
-      IndexCtx.handleObjCInterface(Ref->getInterface());
-    } else {
-      IndexCtx.handleReference(Ref->getInterface(),
-                               Ref->getLocation(),
-                               0,
-                               Ref->getInterface()->getDeclContext());
-    }
+    IndexCtx.handleObjCClass(D);
     return true;
   }
 
@@ -87,74 +79,71 @@
       SourceLocation Loc = *LI;
       ObjCProtocolDecl *PD = *I;
 
-      if (PD->getLocation() == Loc) {
-        IndexCtx.handleObjCProtocol(PD);
-      } else {
-        IndexCtx.handleReference(PD, Loc, 0, PD->getDeclContext());
-      }
+      bool isRedeclaration = PD->getLocation() != Loc;
+      IndexCtx.handleObjCForwardProtocol(PD, Loc, isRedeclaration);
     }
     return true;
   }
 
   bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
-    // Only definitions are handled here.
+    // Forward decls are handled at VisitObjCClassDecl.
     if (D->isForwardDecl())
       return true;
 
-    if (!D->isInitiallyForwardDecl())
-      IndexCtx.handleObjCInterface(D);
+    IndexCtx.handleObjCInterface(D);
 
     IndexCtx.indexTUDeclsInObjCContainer();
-    IndexCtx.invokeStartedObjCContainer(D);
+    IndexCtx.startContainer(D);
     IndexCtx.defineObjCInterface(D);
     IndexCtx.indexDeclContext(D);
-    IndexCtx.invokeEndedContainer(D);
+    IndexCtx.endContainer(D);
     return true;
   }
 
   bool VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
-    // Only definitions are handled here.
+    // Forward decls are handled at VisitObjCForwardProtocolDecl.
     if (D->isForwardDecl())
       return true;
 
-    if (!D->isInitiallyForwardDecl())
-      IndexCtx.handleObjCProtocol(D);
+    IndexCtx.handleObjCProtocol(D);
 
     IndexCtx.indexTUDeclsInObjCContainer();
-    IndexCtx.invokeStartedObjCContainer(D);
+    IndexCtx.startContainer(D);
     IndexCtx.indexDeclContext(D);
-    IndexCtx.invokeEndedContainer(D);
+    IndexCtx.endContainer(D);
     return true;
   }
 
   bool VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
-    ObjCInterfaceDecl *Class = D->getClassInterface();
-    if (Class->isImplicitInterfaceDecl())
-      IndexCtx.handleObjCInterface(Class);
+    IndexCtx.handleObjCImplementation(D);
 
     IndexCtx.indexTUDeclsInObjCContainer();
-    IndexCtx.invokeStartedObjCContainer(D);
+    IndexCtx.startContainer(D);
     IndexCtx.indexDeclContext(D);
-    IndexCtx.invokeEndedContainer(D);
+    IndexCtx.endContainer(D);
     return true;
   }
 
   bool VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
-    if (!D->IsClassExtension())
-      IndexCtx.handleObjCCategory(D);
+    IndexCtx.handleObjCCategory(D);
 
     IndexCtx.indexTUDeclsInObjCContainer();
-    IndexCtx.invokeStartedObjCContainer(D);
+    IndexCtx.startContainer(D);
     IndexCtx.indexDeclContext(D);
-    IndexCtx.invokeEndedContainer(D);
+    IndexCtx.endContainer(D);
     return true;
   }
 
   bool VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
+    if (D->getCategoryDecl()->getLocation().isInvalid())
+      return true;
+
+    IndexCtx.handleObjCCategoryImpl(D);
+
     IndexCtx.indexTUDeclsInObjCContainer();
-    IndexCtx.invokeStartedObjCContainer(D);
+    IndexCtx.startContainer(D);
     IndexCtx.indexDeclContext(D);
-    IndexCtx.invokeEndedContainer(D);
+    IndexCtx.endContainer(D);
     return true;
   }
 
@@ -168,9 +157,9 @@
     if (D->isThisDeclarationADefinition()) {
       const Stmt *Body = D->getBody();
       if (Body) {
-        IndexCtx.invokeStartedStatementBody(D, D);
+        IndexCtx.startContainer(D, /*isBody=*/true);
         IndexCtx.indexBody(Body, D);
-        IndexCtx.invokeEndedContainer(D);
+        IndexCtx.endContainer(D);
       }
     }
     return true;