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);


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);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to