diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-12-13 18:47:35 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-12-13 18:47:35 +0000 |
commit | c2be04eaec94e20fc825fb98b713112d9d82562f (patch) | |
tree | 0f572a5f7483e0f2e2a1df7487f9dd5b18ff6c67 | |
parent | 7cb210100dedc2ebd0910cf270c794480a728be2 (diff) |
[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
-rw-r--r-- | test/Index/index-suppress-refs.h | 3 | ||||
-rw-r--r-- | test/Index/index-suppress-refs.m | 29 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 6 | ||||
-rw-r--r-- | tools/libclang/IndexingContext.cpp | 17 |
4 files changed, 52 insertions, 3 deletions
diff --git a/test/Index/index-suppress-refs.h b/test/Index/index-suppress-refs.h new file mode 100644 index 0000000000..2592f0fe4d --- /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 0000000000..49abf50af2 --- /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 1370e21c81..fdc88a015e 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1580,6 +1580,10 @@ static void printCXIndexLoc(CXIdxLoc loc) { 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 @@ static void printEntityInfo(const char *cb, 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 b95d22d010..66e552c8f4 100644 --- a/tools/libclang/IndexingContext.cpp +++ b/tools/libclang/IndexingContext.cpp @@ -228,7 +228,8 @@ bool IndexingContext::handleDecl(const NamedDecl *D, 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 @@ bool IndexingContext::handleObjCClass(const ObjCClassDecl *D) { 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 @@ bool IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) { : 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::handleCXXRecordDecl(const CXXRecordDecl *RD, 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; |