From 1de05d8796ac8a7603446bf5f1840e015bf3a06a Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 26 Nov 2018 15:24:48 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347558 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Index/USRGeneration.h | 8 ++++++++ lib/Index/USRGeneration.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/clang/Index/USRGeneration.h b/include/clang/Index/USRGeneration.h index 0bb7123674..f1389ecc95 100644 --- a/include/clang/Index/USRGeneration.h +++ b/include/clang/Index/USRGeneration.h @@ -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 MacroDefinitionRecord *MD, bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc, const SourceManager &SM, SmallVectorImpl &Buf); +/// Generates a USR for a type. +/// +/// \return true on error, false on success. +bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl &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 Module *Mod, raw_ostream &OS); /// \returns true on error, false on success. bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS); + } // namespace index } // namespace clang diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index b75aa25217..2c3c186702 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -1105,6 +1105,17 @@ bool clang::index::generateUSRForMacro(StringRef MacroName, SourceLocation Loc, return false; } +bool clang::index::generateUSRForType(QualType T, ASTContext &Ctx, + SmallVectorImpl &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) -- 2.40.0