[PATCH] D124288: [Index] Add a USR and symbol kind for UnresolvedUsingIfExists

Ben Barham via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 22 11:40:41 PDT 2022


bnbarham created this revision.
bnbarham added reviewers: benlangmuir, arphaman, jansvoboda11.
Herald added a project: All.
bnbarham requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`UnresolvedUsingIfExists` has existed for a long time now, but it never
had a USR or symbol kind added. Add those now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124288

Files:
  clang/include/clang/Index/IndexSymbol.h
  clang/lib/Index/IndexSymbol.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/test/Index/using_if_exists.cpp


Index: clang/test/Index/using_if_exists.cpp
===================================================================
--- /dev/null
+++ clang/test/Index/using_if_exists.cpp
@@ -0,0 +1,9 @@
+// RUN: c-index-test core -print-source-symbols -- %s -target x86_64-unknown-unknown 2>&1 | FileCheck %s
+
+namespace ns {
+//  void foo();
+}
+
+using ns::foo __attribute__((using_if_exists));
+// CHECK: [[@LINE-1]]:11 | using/C++ | foo | c:@UD at foo | <no-cgname> | Decl | rel: 0
+// CHECK: [[@LINE-2]]:11 | using/using-unresolved/C++ | foo | c:using_if_exists.cpp at UUIE@foo | <no-cgname> | Ref | rel: 0
Index: clang/lib/Index/USRGeneration.cpp
===================================================================
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -103,6 +103,7 @@
   void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
   void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
   void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
+  void VisitUnresolvedUsingIfExistsDecl(const UnresolvedUsingIfExistsDecl *D);
 
   void VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
     IgnoreResults = true; // No USRs for linkage specs themselves.
@@ -1007,7 +1008,14 @@
   Out << D->getName(); // Simple name.
 }
 
-
+void USRGenerator::VisitUnresolvedUsingIfExistsDecl(
+    const UnresolvedUsingIfExistsDecl *D) {
+  if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
+    return;
+  VisitDeclContext(D->getDeclContext());
+  Out << "@UUIE@";
+  Out << D->getName();
+}
 
 //===----------------------------------------------------------------------===//
 // USR generation functions.
Index: clang/lib/Index/IndexSymbol.cpp
===================================================================
--- clang/lib/Index/IndexSymbol.cpp
+++ clang/lib/Index/IndexSymbol.cpp
@@ -334,6 +334,11 @@
       Info.Lang = SymbolLanguage::CXX;
       Info.SubKind = SymbolSubKind::UsingEnum;
       break;
+    case Decl::UnresolvedUsingIfExists:
+      Info.Kind = SymbolKind::Using;
+      Info.SubKind = SymbolSubKind::UnresolvedUsing;
+      Info.Lang = SymbolLanguage::CXX;
+      break;
     case Decl::Binding:
       Info.Kind = SymbolKind::Variable;
       Info.Lang = SymbolLanguage::CXX;
@@ -549,6 +554,8 @@
   case SymbolSubKind::UsingValue: return "using-value";
   case SymbolSubKind::UsingEnum:
     return "using-enum";
+  case SymbolSubKind::UnresolvedUsing:
+    return "using-unresolved";
   }
   llvm_unreachable("invalid symbol subkind");
 }
Index: clang/include/clang/Index/IndexSymbol.h
===================================================================
--- clang/include/clang/Index/IndexSymbol.h
+++ clang/include/clang/Index/IndexSymbol.h
@@ -76,6 +76,7 @@
   UsingTypename,
   UsingValue,
   UsingEnum,
+  UnresolvedUsing,
 };
 
 typedef uint16_t SymbolPropertySet;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124288.424554.patch
Type: text/x-patch
Size: 2879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220422/7d610bd4/attachment-0001.bin>


More information about the cfe-commits mailing list