aboutsummaryrefslogtreecommitdiff
path: root/tools/CIndex/CIndexUSRs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/CIndex/CIndexUSRs.cpp')
-rw-r--r--tools/CIndex/CIndexUSRs.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/tools/CIndex/CIndexUSRs.cpp b/tools/CIndex/CIndexUSRs.cpp
index b52b9da921..c8933fa000 100644
--- a/tools/CIndex/CIndexUSRs.cpp
+++ b/tools/CIndex/CIndexUSRs.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "CIndexer.h"
+#include "CXCursor.h"
#include "clang/AST/DeclVisitor.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
@@ -184,6 +185,23 @@ void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
Out << "typedef@" << D->getName();
}
+// FIXME: This is a skeleton implementation. It will be overhauled.
+static CXString ConstructUSR(Decl *D) {
+ llvm::SmallString<1024> StrBuf;
+ {
+ llvm::raw_svector_ostream Out(StrBuf);
+ USRGenerator UG(Out);
+ UG.Visit(static_cast<Decl*>(D));
+ }
+
+ if (StrBuf.empty())
+ return CIndexer::createCXString(NULL);
+
+ // Return a copy of the string that must be disposed by the caller.
+ return CIndexer::createCXString(StrBuf.c_str(), true);
+}
+
+
extern "C" {
/// clang_getDeclaration() maps from a CXEntity to the matching CXDecl (if any)
@@ -198,22 +216,13 @@ CXEntity clang_getEntityFromDecl(CXIndex CIdx, CXDecl CE) {
return MakeEntity(CIdx, Entity::get(D, GetProgram(CIdx)));
return NullCXEntity();
}
-
-// FIXME: This is a skeleton implementation. It will be overhauled.
-CXString clang_getDeclUSR(CXDecl D) {
- assert(D && "Null CXDecl passed to clang_getDeclUSR()");
- llvm::SmallString<1024> StrBuf;
- {
- llvm::raw_svector_ostream Out(StrBuf);
- USRGenerator UG(Out);
- UG.Visit(static_cast<Decl*>(D));
- }
-
- if (StrBuf.empty())
- return CIndexer::createCXString(NULL);
- // Return a copy of the string that must be disposed by the caller.
- return CIndexer::createCXString(StrBuf.c_str(), true);
-}
+CXString clang_getCursorUSR(CXCursor C) {
+ if (Decl *D = cxcursor::getCursorDecl(C))
+ return ConstructUSR(D);
+
+
+ return CIndexer::createCXString(NULL);
+}
} // end extern "C"