[cfe-commits] r146496 - in /cfe/trunk: test/Index/index-suppress-refs.h test/Index/index-suppress-refs.m tools/c-index-test/c-index-test.c tools/libclang/IndexingContext.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Dec 13 10:47:35 PST 2011
Author: akirtzidis
Date: Tue Dec 13 12:47:35 2011
New Revision: 146496
URL: http://llvm.org/viewvc/llvm-project?rev=146496&view=rev
Log:
[libclang] Indexing API: Fix suppressing of references in macros and suppress
@class forward references.
rdar://10568080&10568103&10568119
Added:
cfe/trunk/test/Index/index-suppress-refs.h
cfe/trunk/test/Index/index-suppress-refs.m
Modified:
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/IndexingContext.cpp
Added: cfe/trunk/test/Index/index-suppress-refs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-suppress-refs.h?rev=146496&view=auto
==============================================================================
--- cfe/trunk/test/Index/index-suppress-refs.h (added)
+++ cfe/trunk/test/Index/index-suppress-refs.h Tue Dec 13 12:47:35 2011
@@ -0,0 +1,3 @@
+
+ at interface I
+ at end
Added: cfe/trunk/test/Index/index-suppress-refs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-suppress-refs.m?rev=146496&view=auto
==============================================================================
--- cfe/trunk/test/Index/index-suppress-refs.m (added)
+++ cfe/trunk/test/Index/index-suppress-refs.m Tue Dec 13 12:47:35 2011
@@ -0,0 +1,29 @@
+
+#include "index-suppress-refs.h"
+
+#define TYPEDEF(x) typedef int x
+TYPEDEF(MyInt);
+
+MyInt gx;
+
+ at class I;
+
+ at interface I(cat)
+-(I*)meth;
+ at end
+
+ at 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
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=146496&r1=146495&r2=146496&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Dec 13 12:47:35 2011
@@ -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,
Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=146496&r1=146495&r2=146496&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Tue Dec 13 12:47:35 2011
@@ -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;
More information about the cfe-commits
mailing list