clean up some logic in objc type handling.  Specifically, make it so that
there are QualType::getAsObjc* type methods, and make isa<ObjCInterfaceType>
return true for ObjCQualifiedInterfaceType's.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49300 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 2658048..12eb5a1 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1427,17 +1427,18 @@
     return true;
   else if (isObjCIdType(lhs) && rhs->isObjCInterfaceType())
     return true;
-  if (ObjCInterfaceType *lhsIT = 
-      dyn_cast<ObjCInterfaceType>(lhs.getCanonicalType().getTypePtr())) {
-    ObjCQualifiedInterfaceType *rhsQI = 
-      dyn_cast<ObjCQualifiedInterfaceType>(rhs.getCanonicalType().getTypePtr());
-    return rhsQI && (lhsIT->getDecl() == rhsQI->getDecl());
+  
+  if (const ObjCInterfaceType *lhsIT = lhs->getAsObjCInterfaceType()) {
+    const ObjCQualifiedInterfaceType *rhsQI =
+      rhs->getAsObjCQualifiedInterfaceType();
+    if (!isa<ObjCQualifiedInterfaceType>(lhsIT))
+      return rhsQI && (lhsIT->getDecl() == rhsQI->getDecl());
   }
-  else if (ObjCInterfaceType *rhsIT = 
-           dyn_cast<ObjCInterfaceType>(rhs.getCanonicalType().getTypePtr())) {
-    ObjCQualifiedInterfaceType *lhsQI = 
-    dyn_cast<ObjCQualifiedInterfaceType>(lhs.getCanonicalType().getTypePtr());
-    return lhsQI && (rhsIT->getDecl() == lhsQI->getDecl());
+  if (const ObjCInterfaceType *rhsIT = rhs->getAsObjCInterfaceType()) {
+    const ObjCQualifiedInterfaceType *lhsQI = 
+      lhs->getAsObjCQualifiedInterfaceType();
+    if (!isa<ObjCQualifiedInterfaceType>(rhsIT))
+      return lhsQI && (rhsIT->getDecl() == lhsQI->getDecl());
   }
   return false;
 }
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 01f90ba..16f54ca 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -428,6 +428,46 @@
   return getDesugaredType()->getAsOCUVectorType();
 }
 
+const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
+  // Are we directly an ObjCInterface type?
+  if (const ObjCInterfaceType *VTy = dyn_cast<ObjCInterfaceType>(this))
+    return VTy;
+  
+  // If the canonical form of this type isn't the right kind, reject it.
+  if (!isa<ObjCInterfaceType>(CanonicalType)) {  
+    // Look through type qualifiers
+    if (isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()))
+      return CanonicalType.getUnqualifiedType()->getAsObjCInterfaceType();
+    return 0;
+  }
+  
+  // If this is a typedef for an objc interface type, strip the typedef off
+  // without losing all typedef information.
+  return getDesugaredType()->getAsObjCInterfaceType();
+}
+
+const ObjCQualifiedInterfaceType *
+Type::getAsObjCQualifiedInterfaceType() const {
+  // Are we directly an ObjCQualifiedInterfaceType?
+  if (const ObjCQualifiedInterfaceType *VTy =
+         dyn_cast<ObjCQualifiedInterfaceType>(this))
+    return VTy;
+  
+  // If the canonical form of this type isn't the right kind, reject it.
+  if (!isa<ObjCQualifiedInterfaceType>(CanonicalType)) {  
+    // Look through type qualifiers
+    if (isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()))
+      return CanonicalType.getUnqualifiedType()->
+         getAsObjCQualifiedInterfaceType();
+    return 0;
+  }
+  
+  // If this is a typedef for an objc qual interface type, strip the typedef off
+  // without losing all typedef information.
+  return getDesugaredType()->getAsObjCQualifiedInterfaceType();
+}
+
+
 bool Type::isIntegerType() const {
   if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
     return BT->getKind() >= BuiltinType::Bool &&