[PATCH] D111260: [clang] Visit enum base specifiers in libIndex

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 6 13:08:42 PDT 2021


kadircet updated this revision to Diff 377654.
kadircet added a comment.

- Improve tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111260/new/

https://reviews.llvm.org/D111260

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexDecl.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===================================================================
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -377,6 +377,21 @@
                              Not(HasRole(SymbolRole::RelationBaseOf)))));
 }
 
+TEST(IndexTest, EnumBase) {
+  std::string Code = R"cpp(
+    typedef int MyTypedef;
+    enum Foo : MyTypedef;
+    enum Foo : MyTypedef {};
+  )cpp";
+  auto Index = std::make_shared<Indexer>();
+  tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code);
+  EXPECT_THAT(
+      Index->Symbols,
+      AllOf(Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
+                           WrittenAt(Position(3, 16)))),
+            Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
+                           WrittenAt(Position(4, 16))))));
+}
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/lib/Index/IndexDecl.cpp
===================================================================
--- clang/lib/Index/IndexDecl.cpp
+++ clang/lib/Index/IndexDecl.cpp
@@ -8,6 +8,7 @@
 
 #include "IndexingContext.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/Index/IndexDataConsumer.h"
 
@@ -372,6 +373,15 @@
     return true;
   }
 
+  bool VisitEnumDecl(const EnumDecl *ED) {
+    TRY_TO(VisitTagDecl(ED));
+    // Indexing for enumdecl itself is handled inside TagDecl, we just want to
+    // visit integer-base here, which is different than other TagDecl bases.
+    if (auto *TSI = ED->getIntegerTypeSourceInfo())
+      IndexCtx.indexTypeSourceInfo(TSI, ED, ED, /*isBase=*/true);
+    return true;
+  }
+
   bool handleReferencedProtocols(const ObjCProtocolList &ProtList,
                                  const ObjCContainerDecl *ContD,
                                  SourceLocation SuperLoc) {
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1966,6 +1966,20 @@
           [[f^oo]](s);
         }
       )cpp",
+
+      // Enum base
+      R"cpp(
+        typedef int $def[[MyTypeD^ef]];
+        enum MyEnum : [[MyTy^peDef]] { };
+      )cpp",
+      R"cpp(
+        typedef int $def[[MyType^Def]];
+        enum MyEnum : [[MyTypeD^ef]];
+      )cpp",
+      R"cpp(
+        using $def[[MyTypeD^ef]] = int;
+        enum MyEnum : [[MyTy^peDef]] { };
+      )cpp",
   };
   for (const char *Test : Tests)
     checkFindRefs(Test);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111260.377654.patch
Type: text/x-patch
Size: 2649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211006/ef0ffe5d/attachment-0001.bin>


More information about the cfe-commits mailing list