[libclang] Indexing API: Fix suppressing of references in macros and suppress
@class forward references.
rdar://10568080&10568103&10568119
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146496 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Index/index-suppress-refs.h b/test/Index/index-suppress-refs.h
new file mode 100644
index 0000000..2592f0f
--- /dev/null
+++ b/test/Index/index-suppress-refs.h
@@ -0,0 +1,3 @@
+
+@interface I
+@end
diff --git a/test/Index/index-suppress-refs.m b/test/Index/index-suppress-refs.m
new file mode 100644
index 0000000..49abf50
--- /dev/null
+++ b/test/Index/index-suppress-refs.m
@@ -0,0 +1,29 @@
+
+#include "index-suppress-refs.h"
+
+#define TYPEDEF(x) typedef int x
+TYPEDEF(MyInt);
+
+MyInt gx;
+
+@class I;
+
+@interface I(cat)
+-(I*)meth;
+@end
+
+@class I;
+
+// RUN: env CINDEXTEST_SUPPRESSREFS=1 c-index-test -index-file %s | FileCheck %s
+// CHECK: [indexDeclaration]: kind: objc-class | name: I
+// CHECK-NEXT: <ObjCContainerInfo>: kind: interface
+// CHECK-NEXT: [indexDeclaration]: kind: typedef | name: MyInt
+// CHECK-NEXT: [indexDeclaration]: kind: variable | name: gx
+// CHECK-NEXT: [indexDeclaration]: kind: objc-class | name: I
+// CHECK-NEXT: <ObjCContainerInfo>: kind: forward-ref
+// CHECK-NEXT: [indexDeclaration]: kind: objc-category | name: cat
+// CHECK-NEXT: <ObjCContainerInfo>: kind: interface
+// CHECK-NEXT: <ObjCCategoryInfo>: class: kind: objc-class | name: I
+// CHECK-NEXT: [indexDeclaration]: kind: objc-instance-method | name: meth
+// CHECK-NOT: [indexEntityReference]: kind: objc-class | name: I
+// CHECK-NOT: [indexDeclaration]: kind: objc-class | name: I
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 1370e21..fdc88a0 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -1580,6 +1580,10 @@
printf("<null loc>");
return;
}
+ if (!file) {
+ printf("<no idxfile>");
+ return;
+ }
filename = clang_getFileName((CXFile)file);
cname = clang_getCString(filename);
end = cname + strlen(cname);
@@ -1694,9 +1698,9 @@
printf("%s: kind: %s%s", cb, getEntityKindString(info->kind),
getEntityTemplateKindString(info->templateKind));
- printf(" | lang: %s", getEntityLanguageString(info->lang));
printf(" | name: %s", name);
printf(" | USR: %s", info->USR);
+ printf(" | lang: %s", getEntityLanguageString(info->lang));
}
static void printBaseClassInfo(CXClientData client_data,
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index b95d22d..66e552c 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -228,7 +228,8 @@
if (!DInfo.EntInfo.USR || Loc.isInvalid())
return false;
- markEntityOccurrenceInFile(D, Loc);
+ if (suppressRefs())
+ markEntityOccurrenceInFile(D, Loc);
DInfo.entityInfo = &DInfo.EntInfo;
DInfo.cursor = Cursor;
@@ -304,6 +305,12 @@
SourceLocation Loc = Ref->getLocation();
bool isRedeclaration = IFaceD->getLocation() != Loc;
+ // For @class forward declarations, suppress them the same way as references.
+ if (suppressRefs()) {
+ if (markEntityOccurrenceInFile(IFaceD, Loc))
+ return false; // already occurred.
+ }
+
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration,
/*isImplementation=*/false);
return handleObjCContainer(IFaceD, Loc,
@@ -373,6 +380,9 @@
: D->getCategoryNameLoc();
getEntityInfo(IFaceD, ClassEntity, SA);
+ if (suppressRefs())
+ markEntityOccurrenceInFile(IFaceD, ClassLoc);
+
CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
if (IFaceD) {
CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
@@ -583,10 +593,13 @@
bool IndexingContext::markEntityOccurrenceInFile(const NamedDecl *D,
SourceLocation Loc) {
+ if (!D || Loc.isInvalid())
+ return true;
+
SourceManager &SM = Ctx->getSourceManager();
D = getEntityDecl(D);
- std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
+ std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SM.getFileLoc(Loc));
FileID FID = LocInfo.first;
if (FID.isInvalid())
return true;