summaryrefslogtreecommitdiffstats
path: root/clang/tools/libclang/CXIndexDataConsumer.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2018-02-12 17:42:09 +0000
committerFangrui Song <maskray@google.com>2018-02-12 17:42:09 +0000
commit31b97194e65a55b75f10155c7216f0cf9124573e (patch)
treeee3bb710b3cd8cd4deb7301518f462222fe32693 /clang/tools/libclang/CXIndexDataConsumer.cpp
parentb0a17edff7f8873a33e304077b7528e2ed09e36b (diff)
downloadbcm5719-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/libclang/CXIndexDataConsumer.cpp')
-rw-r--r--clang/tools/libclang/CXIndexDataConsumer.cpp19
1 files changed, 14 insertions, 5 deletions
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;
}
OpenPOWER on IntegriCloud