Extend C++ usrs to include type mangling for tag decl arguments, indicating whether a method
is static, and mangling in the qualifers of the method.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103289 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp
index 2a9d0c7..9b489a8 100644
--- a/tools/libclang/CIndexUSRs.cpp
+++ b/tools/libclang/CIndexUSRs.cpp
@@ -171,6 +171,13 @@
   }
   if (D->isVariadic())
     Out << '.';
+  Out << '#';
+  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
+    if (MD->isStatic())
+      Out << 'S';
+    if (unsigned quals = MD->getTypeQualifiers())
+      Out << (char)('0' + quals);
+  }
 }
 
 void USRGenerator::VisitNamedDecl(NamedDecl *D) {
@@ -372,15 +379,20 @@
   // This method mangles in USR information for types.  It can possibly
   // just reuse the naming-mangling logic used by codegen, although the
   // requirements for USRs might not be the same.
+  ASTContext &Ctx = AU->getASTContext();
+
   do {
-    T = T.getTypePtr()->getCanonicalTypeInternal();
+    T = Ctx.getCanonicalType(T);
     Qualifiers Q = T.getQualifiers();
+    unsigned qVal = 0;
     if (Q.hasConst())
-      Out << '1';
+      qVal |= 0x1;
     if (Q.hasVolatile())
-      Out << '2';
+      qVal |= 0x2;
     if (Q.hasRestrict())
-      Out << '3';
+      qVal |= 0x4;
+    if(qVal)
+      Out << ((char) ('0' + qVal));
 
     // Mangle in ObjC GC qualifiers?
 
@@ -477,6 +489,11 @@
       T = CT->getElementType();
       continue;
     }
+    if (const TagType *TT = T->getAs<TagType>()) {
+      Out << '$';
+      VisitTagDecl(TT->getDecl());
+      return;
+    }
 
     // Unhandled type.
     Out << ' ';