Replace clang_getDeclUSR() with clang_getCursorUSR().  Also remove printing 'contexts' from c-index-test output; it wasn't helpful and was extremely brittle.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93760 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.exports b/tools/CIndex/CIndex.exports
index a695ba2..d5f8298 100644
--- a/tools/CIndex/CIndex.exports
+++ b/tools/CIndex/CIndex.exports
@@ -21,14 +21,14 @@
 _clang_getCursorSource
 _clang_getCursorSourceFile
 _clang_getCursorSpelling
+_clang_getCursorUSR
 _clang_getDeclColumn
 _clang_getDeclExtent
-_clang_getDeclLine
 _clang_getDeclExtent
+_clang_getDeclLine
 _clang_getDeclSource
 _clang_getDeclSourceFile
 _clang_getDeclSpelling
-_clang_getDeclUSR
 _clang_getDeclaration
 _clang_getDefinitionSpellingAndExtent
 _clang_getEntityFromDecl
diff --git a/tools/CIndex/CIndexUSRs.cpp b/tools/CIndex/CIndexUSRs.cpp
index b52b9da..c8933fa 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 @@
   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 @@
     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"
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index afceafa..db95644 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -84,17 +84,11 @@
 
 static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) {
   if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
-    CXString string;
     printf("// %s: %s:%d:%d: ", FileCheckPrefix,
                                 GetCursorSource(Cursor),
                                 clang_getCursorLine(Cursor),
                                 clang_getCursorColumn(Cursor));
-    PrintCursor(Cursor);
-
-    string = clang_getDeclSpelling(Dcl);
-    printf(" [Context=%s]", clang_getCString(string));
-    clang_disposeString(string);
-    
+    PrintCursor(Cursor);    
     PrintDeclExtent(clang_getCursorDecl(Cursor));
 
     printf("\n");
@@ -105,15 +99,10 @@
                                    CXClientData Filter) {
   if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
     CXDecl D;
-    CXString string;
     printf("// %s: %s:%d:%d: ", FileCheckPrefix,
            GetCursorSource(Cursor), clang_getCursorLine(Cursor),
            clang_getCursorColumn(Cursor));
     PrintCursor(Cursor);
-    string = clang_getTranslationUnitSpelling(Unit);
-    printf(" [Context=%s]",
-          basename(clang_getCString(string)));
-    clang_disposeString(string);
     
     D = clang_getCursorDecl(Cursor);
     if (!D) {
@@ -156,13 +145,10 @@
     if (Ref.kind == CXCursor_NoDeclFound) {
       /* Nothing found here; that's fine. */
     } else if (Ref.kind != CXCursor_FunctionDecl) {
-      CXString string;
       printf("// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource(Ref),
              curLine, curColumn);
       PrintCursor(Ref);
-      string = clang_getDeclSpelling(Ref.data[0]);
-      printf(" [Context:%s]\n", clang_getCString(string));
-      clang_disposeString(string);
+      printf("\n");
     }
     startBuf++;
   }
@@ -174,13 +160,13 @@
 
 static void USRDeclVisitor(CXDecl D, CXCursor C, CXClientData Filter) {
   if (!Filter || (C.kind == *(enum CXCursorKind *)Filter)) {
-    CXString USR = clang_getDeclUSR(C.data[0]);
+    CXString USR = clang_getCursorUSR(C);
     if (!USR.Spelling) {
       clang_disposeString(USR);
       return;
     }
     printf("// %s: %s %s", FileCheckPrefix, GetCursorSource(C), USR.Spelling);
-    PrintDeclExtent(C.data[0]);
+    PrintDeclExtent(clang_getCursorDecl(C));
     printf("\n");
     clang_disposeString(USR);
   }