From aca19be8731fc31cff68702de0dc7f30ce908979 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 18 Oct 2011 15:50:50 +0000 Subject: [PATCH] [libclang] Index implicit property references. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142355 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang-c/Index.h | 6 ++++++ tools/c-index-test/c-index-test.c | 5 +++++ tools/libclang/IndexBody.cpp | 15 +++++++++++++++ tools/libclang/IndexingContext.cpp | 6 ++++-- tools/libclang/IndexingContext.h | 3 ++- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index d45830ef91..e8e37a3d0b 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -4051,12 +4051,18 @@ typedef struct { CXIdxLoc endLoc; } CXIdxEndContainerInfo; +typedef enum { + CXIdxEntityRef_Direct = 1, + CXIdxEntityRef_ImplicitProperty = 2 +} CXIdxEntityRefKind; + typedef struct { CXCursor cursor; CXIdxLoc loc; CXIdxEntity referencedEntity; CXIdxEntity parentEntity; CXIdxContainer container; + CXIdxEntityRefKind kind; } CXIdxEntityRefInfo; typedef struct { diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index fb83d20cbe..5adffbd2a8 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1920,6 +1920,11 @@ static void index_indexEntityReference(CXClientData client_data, printCXIndexEntity(info->parentEntity); printf(" | container: "); printCXIndexContainer(info->container); + printf(" | kind: "); + switch (info->kind) { + case CXIdxEntityRef_Direct: printf("direct"); break; + case CXIdxEntityRef_ImplicitProperty: printf("implicit prop"); break; + } printf("\n"); } diff --git a/tools/libclang/IndexBody.cpp b/tools/libclang/IndexBody.cpp index b2ffb99267..769a1c7ae8 100644 --- a/tools/libclang/IndexBody.cpp +++ b/tools/libclang/IndexBody.cpp @@ -69,6 +69,21 @@ public: IndexCtx.handleReference(MD, E->getSelectorStartLoc(), 0, ParentDC, E); return true; } + + bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { + if (E->isImplicitProperty()) { + if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter()) + IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E, + CXIdxEntityRef_ImplicitProperty); + if (ObjCMethodDecl *MD = E->getImplicitPropertySetter()) + IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E, + CXIdxEntityRef_ImplicitProperty); + } else { + IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(), 0, + ParentDC, E); + } + return true; + } }; } // anonymous namespace diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp index 8a41856032..f295582b53 100644 --- a/tools/libclang/IndexingContext.cpp +++ b/tools/libclang/IndexingContext.cpp @@ -388,7 +388,8 @@ void IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) { void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, - const Expr *E) { + const Expr *E, + CXIdxEntityRefKind Kind) { if (Loc.isInvalid()) return; if (!CB.indexEntityReference) @@ -402,7 +403,8 @@ void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, getIndexLoc(Loc), getIndexEntity(D), getIndexEntity(Parent), - getIndexContainerForDC(DC) }; + getIndexContainerForDC(DC), + Kind }; CB.indexEntityReference(ClientData, &Info); } diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h index 710568058f..d69f1c8eaa 100644 --- a/tools/libclang/IndexingContext.h +++ b/tools/libclang/IndexingContext.h @@ -132,7 +132,8 @@ public: void handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, - const Expr *E = 0); + const Expr *E = 0, + CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct); void invokeStartedTagTypeDefinition(const TagDecl *D); -- 2.40.0