r347558 - [Index] Expose USR generation for types

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 26 07:24:49 PST 2018


Author: ibiryukov
Date: Mon Nov 26 07:24:48 2018
New Revision: 347558

URL: http://llvm.org/viewvc/llvm-project?rev=347558&view=rev
Log:
[Index] Expose USR generation for types

Summary: Used in clangd.

Reviewers: sammccall, ioeric

Reviewed By: sammccall

Subscribers: kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D52275

Modified:
    cfe/trunk/include/clang/Index/USRGeneration.h
    cfe/trunk/lib/Index/USRGeneration.cpp

Modified: cfe/trunk/include/clang/Index/USRGeneration.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/USRGeneration.h?rev=347558&r1=347557&r2=347558&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/USRGeneration.h (original)
+++ cfe/trunk/include/clang/Index/USRGeneration.h Mon Nov 26 07:24:48 2018
@@ -14,11 +14,13 @@
 #include "llvm/ADT/StringRef.h"
 
 namespace clang {
+class ASTContext;
 class Decl;
 class MacroDefinitionRecord;
 class Module;
 class SourceLocation;
 class SourceManager;
+class QualType;
 
 namespace index {
 
@@ -71,6 +73,11 @@ bool generateUSRForMacro(const MacroDefi
 bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
                          const SourceManager &SM, SmallVectorImpl<char> &Buf);
 
+/// Generates a USR for a type.
+///
+/// \return true on error, false on success.
+bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl<char> &Buf);
+
 /// Generate a USR for a module, including the USR prefix.
 /// \returns true on error, false on success.
 bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS);
@@ -87,6 +94,7 @@ bool generateUSRFragmentForModule(const
 /// \returns true on error, false on success.
 bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS);
 
+
 } // namespace index
 } // namespace clang
 

Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=347558&r1=347557&r2=347558&view=diff
==============================================================================
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Mon Nov 26 07:24:48 2018
@@ -1105,6 +1105,17 @@ bool clang::index::generateUSRForMacro(S
   return false;
 }
 
+bool clang::index::generateUSRForType(QualType T, ASTContext &Ctx,
+                                      SmallVectorImpl<char> &Buf) {
+  if (T.isNull())
+    return true;
+  T = T.getCanonicalType();
+
+  USRGenerator UG(&Ctx, Buf);
+  UG.VisitType(T);
+  return UG.ignoreResults();
+}
+
 bool clang::index::generateFullUSRForModule(const Module *Mod,
                                             raw_ostream &OS) {
   if (!Mod->Parent)




More information about the cfe-commits mailing list