diff options
author | Fangrui Song <maskray@google.com> | 2018-02-12 17:42:09 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2018-02-12 17:42:09 +0000 |
commit | 31b97194e65a55b75f10155c7216f0cf9124573e (patch) | |
tree | ee3bb710b3cd8cd4deb7301518f462222fe32693 /clang/tools | |
parent | b0a17edff7f8873a33e304077b7528e2ed09e36b (diff) | |
download | bcm5719-llvm-31b97194e65a55b75f10155c7216f0cf9124573e.tar.gz bcm5719-llvm-31b97194e65a55b75f10155c7216f0cf9124573e.zip |
[libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo
Summary:
CXIdxEntityRefInfo contains the member `CXIdxEntityRefKind kind;` to
differentiate implicit and direct calls. However, there are more roles
defined in SymbolRole. Among them, `Read/Write` are probably the most
useful ones as they can be used to differentiate Read/Write occurrences
of a symbol for document highlight in a text document.
See `export namespace DocumentHighlightKind`
on https://microsoft.github.io/language-server-protocol/specification
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D42895
llvm-svn: 324914
Diffstat (limited to 'clang/tools')
-rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 27 | ||||
-rw-r--r-- | clang/tools/libclang/CXIndexDataConsumer.cpp | 19 | ||||
-rw-r--r-- | clang/tools/libclang/CXIndexDataConsumer.h | 6 |
3 files changed, 43 insertions, 9 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 61e42b26ee4..c134d4e5c5c 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -3326,6 +3326,27 @@ static void printProtocolList(const CXIdxObjCProtocolRefListInfo *ProtoInfo, } } +static void printSymbolRole(CXSymbolRole role) { + if (role & CXSymbolRole_Declaration) + printf(" decl"); + if (role & CXSymbolRole_Definition) + printf(" def"); + if (role & CXSymbolRole_Reference) + printf(" ref"); + if (role & CXSymbolRole_Read) + printf(" read"); + if (role & CXSymbolRole_Write) + printf(" write"); + if (role & CXSymbolRole_Call) + printf(" call"); + if (role & CXSymbolRole_Dynamic) + printf(" dyn"); + if (role & CXSymbolRole_AddressOf) + printf(" addr"); + if (role & CXSymbolRole_Implicit) + printf(" implicit"); +} + static void index_diagnostic(CXClientData client_data, CXDiagnosticSet diagSet, void *reserved) { CXString str; @@ -3544,9 +3565,11 @@ static void index_indexEntityReference(CXClientData client_data, printCXIndexContainer(info->container); printf(" | refkind: "); switch (info->kind) { - case CXIdxEntityRef_Direct: printf("direct"); break; - case CXIdxEntityRef_Implicit: printf("implicit"); break; + case CXIdxEntityRef_Direct: printf("direct"); break; + case CXIdxEntityRef_Implicit: printf("implicit"); break; } + printf(" | role:"); + printSymbolRole(info->role); printf("\n"); } diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp index 0db6f0c1f07..ba1e92f5457 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.cpp +++ b/clang/tools/libclang/CXIndexDataConsumer.cpp @@ -148,6 +148,11 @@ public: return true; } }; + +CXSymbolRole getSymbolRole(SymbolRoleSet Role) { + // CXSymbolRole mirrors low 9 bits of clang::index::SymbolRole. + return CXSymbolRole(static_cast<uint32_t>(Role) & ((1 << 9) - 1)); +} } bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D, @@ -184,6 +189,7 @@ bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D, if (Roles & (unsigned)SymbolRole::Implicit) { Kind = CXIdxEntityRef_Implicit; } + CXSymbolRole CXRole = getSymbolRole(Roles); CXCursor Cursor; if (ASTNode.OrigE) { @@ -202,7 +208,7 @@ bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D, } handleReference(ND, Loc, Cursor, dyn_cast_or_null<NamedDecl>(ASTNode.Parent), - ASTNode.ContainerDC, ASTNode.OrigE, Kind); + ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole); } else { const DeclContext *LexicalDC = ASTNode.ContainerDC; @@ -889,13 +895,14 @@ bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc const NamedDecl *Parent, const DeclContext *DC, const Expr *E, - CXIdxEntityRefKind Kind) { + CXIdxEntityRefKind Kind, + CXSymbolRole Role) { if (!D || !DC) return false; CXCursor Cursor = E ? MakeCXCursor(E, cast<Decl>(DC), CXTU) : getRefCursor(D, Loc); - return handleReference(D, Loc, Cursor, Parent, DC, E, Kind); + return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role); } bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc, @@ -903,7 +910,8 @@ bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc const NamedDecl *Parent, const DeclContext *DC, const Expr *E, - CXIdxEntityRefKind Kind) { + CXIdxEntityRefKind Kind, + CXSymbolRole Role) { if (!CB.indexEntityReference) return false; @@ -939,7 +947,8 @@ bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc getIndexLoc(Loc), &RefEntity, Parent ? &ParentEntity : nullptr, - &Container }; + &Container, + Role }; CB.indexEntityReference(ClientData, &Info); return true; } diff --git a/clang/tools/libclang/CXIndexDataConsumer.h b/clang/tools/libclang/CXIndexDataConsumer.h index a54baadd077..e3c726ec67e 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.h +++ b/clang/tools/libclang/CXIndexDataConsumer.h @@ -436,13 +436,15 @@ public: const NamedDecl *Parent, const DeclContext *DC, const Expr *E = nullptr, - CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct); + CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct, + CXSymbolRole Role = CXSymbolRole_None); bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, const Expr *E = nullptr, - CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct); + CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct, + CXSymbolRole Role = CXSymbolRole_None); bool isNotFromSourceFile(SourceLocation Loc) const; |