Introduce a special cursor kind for the translation unit, to serve as
the root of the conceptual cursor hierarchy (just like we do with
declarations). This will be used when we get to unify
clang_loadTranslationUnit() and clang_loadDeclaration() into something
more generally useful.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93954 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 032dd12..8dfaa4c 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -565,6 +565,11 @@
                                   true);
 }
 
+CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
+  CXCursor Result = { CXCursor_TranslationUnit, { TU, 0, 0 } };
+  return Result;
+}
+
 void clang_loadTranslationUnit(CXTranslationUnit CTUnit,
                                CXTranslationUnitIterator callback,
                                CXClientData CData) {
@@ -803,6 +808,9 @@
 extern "C" {
 CXString clang_getCursorSpelling(CXCursor C) {
   assert(getCursorDecl(C) && "CXCursor has null decl");
+  if (clang_isTranslationUnit(C.kind))
+    return clang_getTranslationUnitSpelling(C.data[0]);
+
   if (clang_isReference(C.kind)) {
     switch (C.kind) {
     case CXCursor_ObjCSuperClassRef: {
@@ -867,6 +875,7 @@
   case CXCursor_InvalidFile: return "InvalidFile";
   case CXCursor_NoDeclFound: return "NoDeclFound";
   case CXCursor_NotImplemented: return "NotImplemented";
+  case CXCursor_TranslationUnit: return "TranslationUnit";
   }
   
   llvm_unreachable("Unhandled CXCursorKind");
@@ -947,6 +956,10 @@
   return K >= CXCursor_FirstStmt && K <= CXCursor_LastStmt;
 }
 
+unsigned clang_isTranslationUnit(enum CXCursorKind K) {
+  return K == CXCursor_TranslationUnit;
+}
+
 CXCursorKind clang_getCursorKind(CXCursor C) {
   return C.kind;
 }