summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-11-26 15:24:48 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-11-26 15:24:48 +0000
commita622484fa64e03a45832a95cda1ba61d512244a0 (patch)
tree24ed89528c481045ba34c8496d0b0dd8a1330d82
parentd31220e0de0d8924e7c1f54d08d4515cfabb1aeb (diff)
downloadbcm5719-llvm-a622484fa64e03a45832a95cda1ba61d512244a0.tar.gz
bcm5719-llvm-a622484fa64e03a45832a95cda1ba61d512244a0.zip
[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 llvm-svn: 347558
-rw-r--r--clang/include/clang/Index/USRGeneration.h8
-rw-r--r--clang/lib/Index/USRGeneration.cpp11
2 files changed, 19 insertions, 0 deletions
diff --git a/clang/include/clang/Index/USRGeneration.h b/clang/include/clang/Index/USRGeneration.h
index 0bb71236743..f1389ecc959 100644
--- a/clang/include/clang/Index/USRGeneration.h
+++ b/clang/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<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 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/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index b75aa252175..2c3c1867028 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/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<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)
OpenPOWER on IntegriCloud