]> granicus.if.org Git - clang/commitdiff
[index] libclang: Make sure to treat forward ObjC protocols as ObjCProtocolRef declar...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 9 Mar 2016 02:12:46 +0000 (02:12 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 9 Mar 2016 02:12:46 +0000 (02:12 +0000)
rdar://25035376

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262985 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Index/IndexDecl.cpp
test/Index/index-refs.m
tools/libclang/CXIndexDataConsumer.cpp

index af438f368435d82fa3a41a7a5ece48419c4a3cc5..5f5c49a2e3345b17099ef3e412302f8738634071 100644 (file)
@@ -227,8 +227,8 @@ public:
       TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D));
       TRY_TO(IndexCtx.indexDeclContext(D));
     } else {
-      return IndexCtx.handleReference(D, D->getLocation(), nullptr, nullptr,
-                                      SymbolRoleSet());
+      return IndexCtx.handleReference(D, D->getLocation(), nullptr,
+                                      D->getDeclContext(), SymbolRoleSet());
     }
     return true;
   }
@@ -239,8 +239,8 @@ public:
       TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D));
       TRY_TO(IndexCtx.indexDeclContext(D));
     } else {
-      return IndexCtx.handleReference(D, D->getLocation(), nullptr, nullptr,
-                                      SymbolRoleSet());
+      return IndexCtx.handleReference(D, D->getLocation(), nullptr,
+                                      D->getDeclContext(), SymbolRoleSet());
     }
     return true;
   }
index f25013b882f6e914dc6978dbd9e55a155e1d9d5a..457712bcbc7ec3a16b0440edaf223df0a6f9f317 100644 (file)
@@ -21,7 +21,12 @@ void foo2() {
   [I clsMeth];
 }
 
+@protocol ForwardProt;
+
 // RUN: c-index-test -index-file %s | FileCheck %s
 // CHECK: [indexEntityReference]: kind: objc-protocol | name: Prot | {{.*}} | loc: 12:27
 // CHECK: [indexEntityReference]: kind: struct | name: FooS | {{.*}} | loc: 13:18
 // CHECK: [indexEntityReference]: kind: objc-class | name: I | {{.*}} | loc: 21:4
+
+// CHECK: [indexDeclaration]: kind: objc-protocol | name: ForwardProt | {{.*}} | loc: 24:11
+// CHECK-NEXT: <ObjCContainerInfo>: kind: forward-ref
index 322725ec654d4b79322701835c6a3e44fa233844..4f89e43fd7b0b068bcdbe56d7f4e367b17e95e84 100644 (file)
@@ -171,6 +171,14 @@ bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
         return true;
       }
     }
+    if (auto *ObjCPD = dyn_cast_or_null<ObjCProtocolDecl>(ASTNode.OrigD)) {
+      if (!ObjCPD->isThisDeclarationADefinition() &&
+          ObjCPD->getLocation() == Loc) {
+        // The libclang API treats this as ObjCProtocolRef declaration.
+        IndexingDeclVisitor(*this, Loc, nullptr).Visit(ObjCPD);
+        return true;
+      }
+    }
 
     CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct;
     if (Roles & (unsigned)SymbolRole::Implicit) {