Add libclang support for class template partial specializations,
including a cursor kind, visitation, and USRs.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112629 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 919962c..ae53c16 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -290,6 +290,8 @@
   bool VisitTranslationUnitDecl(TranslationUnitDecl *D);
   bool VisitTypedefDecl(TypedefDecl *D);
   bool VisitTagDecl(TagDecl *D);
+  bool VisitClassTemplatePartialSpecializationDecl(
+                                     ClassTemplatePartialSpecializationDecl *D);
   bool VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
   bool VisitEnumConstantDecl(EnumConstantDecl *D);
   bool VisitDeclaratorDecl(DeclaratorDecl *DD);
@@ -600,6 +602,22 @@
   return VisitDeclContext(D);
 }
 
+bool CursorVisitor::VisitClassTemplatePartialSpecializationDecl(
+                                   ClassTemplatePartialSpecializationDecl *D) {
+  // FIXME: Visit the "outer" template parameter lists on the TagDecl
+  // before visiting these template parameters.
+  if (VisitTemplateParameters(D->getTemplateParameters()))
+    return true;
+
+  // Visit the partial specialization arguments.
+  const TemplateArgumentLoc *TemplateArgs = D->getTemplateArgsAsWritten();
+  for (unsigned I = 0, N = D->getNumTemplateArgsAsWritten(); I != N; ++I)
+    if (VisitTemplateArgumentLoc(TemplateArgs[I]))
+      return true;
+  
+  return VisitCXXRecordDecl(D);
+}
+
 bool CursorVisitor::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   // FIXME: Visit default argument
   return false;
@@ -2144,6 +2162,8 @@
     return createCXString("FunctionTemplate");
   case CXCursor_ClassTemplate:
     return createCXString("ClassTemplate");
+  case CXCursor_ClassTemplatePartialSpecialization:
+    return createCXString("ClassTemplatePartialSpecialization");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp
index b397f1e..6705076 100644
--- a/tools/libclang/CIndexUSRs.cpp
+++ b/tools/libclang/CIndexUSRs.cpp
@@ -366,21 +366,33 @@
   D = D->getCanonicalDecl();
   VisitDeclContext(D->getDeclContext());
 
-  bool IsTemplate = false;
-  if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D))
+  bool AlreadyStarted = false;
+  if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) {
     if (ClassTemplateDecl *ClassTmpl = CXXRecord->getDescribedClassTemplate()) {
-      IsTemplate = true;
+      AlreadyStarted = true;
       
       switch (D->getTagKind()) {
-        case TTK_Struct: Out << "@ST"; break;
-        case TTK_Class:  Out << "@CT"; break;
-        case TTK_Union:  Out << "@UT"; break;
-        case TTK_Enum: llvm_unreachable("enum template");
+      case TTK_Struct: Out << "@ST"; break;
+      case TTK_Class:  Out << "@CT"; break;
+      case TTK_Union:  Out << "@UT"; break;
+      case TTK_Enum: llvm_unreachable("enum template"); break;
       }
       VisitTemplateParameterList(ClassTmpl->getTemplateParameters());
+    } else if (ClassTemplatePartialSpecializationDecl *PartialSpec
+                = dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) {
+      AlreadyStarted = true;
+      
+      switch (D->getTagKind()) {
+      case TTK_Struct: Out << "@SP"; break;
+      case TTK_Class:  Out << "@CP"; break;
+      case TTK_Union:  Out << "@UP"; break;
+      case TTK_Enum: llvm_unreachable("enum partial specialization"); break;
+      }      
+      VisitTemplateParameterList(PartialSpec->getTemplateParameters());
     }
+  }
   
-  if (!IsTemplate) {
+  if (!AlreadyStarted) {
     switch (D->getTagKind()) {
       case TTK_Struct: Out << "@S"; break;
       case TTK_Class:  Out << "@C"; break;
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index 283c388..691ccd5 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -65,6 +65,8 @@
     case Decl::TemplateTemplateParm:return CXCursor_TemplateTemplateParameter;
     case Decl::FunctionTemplate:   return CXCursor_FunctionTemplate;
     case Decl::ClassTemplate:      return CXCursor_ClassTemplate;
+    case Decl::ClassTemplatePartialSpecialization:
+      return CXCursor_ClassTemplatePartialSpecialization;
       
     default:
       if (TagDecl *TD = dyn_cast<TagDecl>(D)) {