[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies
Christian Kandeler via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 8 08:45:49 PDT 2023
ckandeler created this revision.
ckandeler added a reviewer: ilya-biryukov.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added projects: clang, clang-tools-extra.
It's valuable to have document highlights for labels and be able to find
references to them.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150124
Files:
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/lib/Index/IndexBody.cpp
Index: clang/lib/Index/IndexBody.cpp
===================================================================
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -144,6 +144,23 @@
Parent, ParentDC, Roles, Relations, E);
}
+ bool VisitGotoStmt(GotoStmt *S) {
+ if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+ return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
+ ParentDC,
+ unsigned(SymbolRole::NameReference));
+ }
+ return true;
+ }
+
+ bool VisitLabelStmt(LabelStmt *S) {
+ if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+ return IndexCtx.handleReference(S->getDecl(), S->getIdentLoc(), Parent,
+ ParentDC, {});
+ }
+ return true;
+ }
+
bool VisitMemberExpr(MemberExpr *E) {
SourceLocation Loc = E->getMemberLoc();
if (Loc.isInvalid())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -127,6 +127,13 @@
[Foo [[x]]:2 [[^y]]:4];
}
)cpp",
+ R"cpp( // Label
+ int main() {
+ goto [[^theLabel]];
+ [[theLabel]]:
+ return 1;
+ }
+ )cpp",
};
for (const char *Test : Tests) {
Annotations T(Test);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150124.520401.patch
Type: text/x-patch
Size: 1510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230508/8a7ef280/attachment.bin>
More information about the cfe-commits
mailing list