From 31b97194e65a55b75f10155c7216f0cf9124573e Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 12 Feb 2018 17:42:09 +0000 Subject: [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 --- clang/tools/libclang/CXIndexDataConsumer.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'clang/tools/libclang/CXIndexDataConsumer.cpp') 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(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(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(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; } -- cgit v1.2.3