aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-07 05:30:13 +0000
committerChris Lattner <sabre@nondot.org>2008-04-07 05:30:13 +0000
commiteca7be6b7ebd93682eeaab2c71d59f2995dacdcc (patch)
tree146cdf9150eb701dade31b5987d174a86d632040 /lib/AST/ASTContext.cpp
parent821a01baa2968dd27720c631a6722ec60686ce27 (diff)
move ObjCQualifiedIdTypesAreCompatible out of ASTContext into Sema.
While it is similar to the other compatibility predicates in ASTContext, it is not used by them and is different. In addition, greatly simplify ObjCQualifiedIdTypesAreCompatible and fix some canonical type bugs. Also, simplify my Type::getAsObjC* methods. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49313 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r--lib/AST/ASTContext.cpp176
1 files changed, 0 insertions, 176 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 65c4e0567f..439a99c4b2 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1507,182 +1507,6 @@ areCompatObjCQualInterfaces(const ObjCQualifiedInterfaceType *LHS,
return false;
}
-/// ProtocolCompatibleWithProtocol - return 'true' if 'lProto' is in the
-/// inheritance hierarchy of 'rProto'.
-static bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
- ObjCProtocolDecl *rProto) {
- if (lProto == rProto)
- return true;
- ObjCProtocolDecl** RefPDecl = rProto->getReferencedProtocols();
- for (unsigned i = 0; i < rProto->getNumReferencedProtocols(); i++)
- if (ProtocolCompatibleWithProtocol(lProto, RefPDecl[i]))
- return true;
- return false;
-}
-
-/// ClassImplementsProtocol - Checks that 'lProto' protocol
-/// has been implemented in IDecl class, its super class or categories (if
-/// lookupCategory is true).
-static bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
- ObjCInterfaceDecl *IDecl,
- bool lookupCategory) {
-
- // 1st, look up the class.
- ObjCProtocolDecl **protoList = IDecl->getReferencedProtocols();
- for (unsigned i = 0; i < IDecl->getNumIntfRefProtocols(); i++) {
- if (ProtocolCompatibleWithProtocol(lProto, protoList[i]))
- return true;
- }
-
- // 2nd, look up the category.
- if (lookupCategory)
- for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
- CDecl = CDecl->getNextClassCategory()) {
- protoList = CDecl->getReferencedProtocols();
- for (unsigned i = 0; i < CDecl->getNumReferencedProtocols(); i++) {
- if (ProtocolCompatibleWithProtocol(lProto, protoList[i]))
- return true;
- }
- }
-
- // 3rd, look up the super class(s)
- if (IDecl->getSuperClass())
- return
- ClassImplementsProtocol(lProto, IDecl->getSuperClass(), lookupCategory);
-
- return false;
-}
-
-/// ObjCQualifiedIdTypesAreCompatible - Compares two types, at least
-/// one of which is a protocol qualified 'id' type. When 'compare'
-/// is true it is for comparison; when false, for assignment/initialization.
-bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs,
- QualType rhs,
- bool compare) {
- // match id<P..> with an 'id' type in all cases.
- if (const PointerType *PT = lhs->getAsPointerType()) {
- QualType PointeeTy = PT->getPointeeType();
- if (isObjCIdType(PointeeTy) || PointeeTy->isVoidType())
- return true;
- } else if (const PointerType *PT = rhs->getAsPointerType()) {
- QualType PointeeTy = PT->getPointeeType();
- if (isObjCIdType(PointeeTy) || PointeeTy->isVoidType())
- return true;
- }
-
- ObjCQualifiedInterfaceType *lhsQI = 0;
- ObjCQualifiedInterfaceType *rhsQI = 0;
- ObjCInterfaceDecl *lhsID = 0;
- ObjCInterfaceDecl *rhsID = 0;
- ObjCQualifiedIdType *lhsQID = dyn_cast<ObjCQualifiedIdType>(lhs);
- ObjCQualifiedIdType *rhsQID = dyn_cast<ObjCQualifiedIdType>(rhs);
-
- if (lhsQID) {
- if (!rhsQID && rhs->getTypeClass() == Type::Pointer) {
- QualType rtype =
- cast<PointerType>(rhs.getCanonicalType())->getPointeeType();
- rhsQI =
- dyn_cast<ObjCQualifiedInterfaceType>(
- rtype.getCanonicalType().getTypePtr());
- if (!rhsQI) {
- ObjCInterfaceType *IT = dyn_cast<ObjCInterfaceType>(
- rtype.getCanonicalType().getTypePtr());
- if (IT)
- rhsID = IT->getDecl();
- }
- }
- if (!rhsQI && !rhsQID && !rhsID)
- return false;
-
- ObjCQualifiedIdType::qual_iterator RHSProtoI, RHSProtoE;
- if (rhsQI) {
- RHSProtoI = rhsQI->qual_begin();
- RHSProtoE = rhsQI->qual_end();
- } else if (rhsQID) {
- RHSProtoI = rhsQID->qual_begin();
- RHSProtoE = rhsQID->qual_end();
- }
-
- for (unsigned i =0; i < lhsQID->getNumProtocols(); i++) {
- ObjCProtocolDecl *lhsProto = lhsQID->getProtocols(i);
- bool match = false;
-
- // when comparing an id<P> on lhs with a static type on rhs,
- // see if static class implements all of id's protocols, directly or
- // through its super class and categories.
- if (rhsID) {
- if (ClassImplementsProtocol(lhsProto, rhsID, true))
- match = true;
- } else {
- for (; RHSProtoI != RHSProtoE; ++RHSProtoI) {
- ObjCProtocolDecl *rhsProto = *RHSProtoI;
- if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
- compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto)) {
- match = true;
- break;
- }
- }
- }
- if (!match)
- return false;
- }
- }
- else if (rhsQID) {
- if (!lhsQID && lhs->getTypeClass() == Type::Pointer) {
- QualType ltype =
- cast<PointerType>(lhs.getCanonicalType())->getPointeeType();
- lhsQI =
- dyn_cast<ObjCQualifiedInterfaceType>(
- ltype.getCanonicalType().getTypePtr());
- if (!lhsQI) {
- ObjCInterfaceType *IT = dyn_cast<ObjCInterfaceType>(
- ltype.getCanonicalType().getTypePtr());
- if (IT)
- lhsID = IT->getDecl();
- }
- }
- if (!lhsQI && !lhsQID && !lhsID)
- return false;
-
- ObjCQualifiedIdType::qual_iterator LHSProtoI, LHSProtoE;
- if (lhsQI) {
- LHSProtoI = lhsQI->qual_begin();
- LHSProtoE = lhsQI->qual_end();
- } else if (lhsQID) {
- LHSProtoI = lhsQID->qual_begin();
- LHSProtoE = lhsQID->qual_end();
- }
-
- bool match = false;
- // for static type vs. qualified 'id' type, check that class implements
- // one of 'id's protocols.
- if (lhsID) {
- for (unsigned j = 0; j < rhsQID->getNumProtocols(); j++) {
- ObjCProtocolDecl *rhsProto = rhsQID->getProtocols(j);
- if (ClassImplementsProtocol(rhsProto, lhsID, compare)) {
- match = true;
- break;
- }
- }
- } else {
- for (; LHSProtoI != LHSProtoE; ++LHSProtoI) {
- match = false;
- ObjCProtocolDecl *lhsProto = *LHSProtoI;
- for (unsigned j = 0; j < rhsQID->getNumProtocols(); j++) {
- ObjCProtocolDecl *rhsProto = rhsQID->getProtocols(j);
- if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
- compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto)) {
- match = true;
- break;
- }
- }
- }
- }
- if (!match)
- return false;
- }
- return true;
-}
bool ASTContext::vectorTypesAreCompatible(QualType lhs, QualType rhs) {
const VectorType *lVector = lhs->getAsVectorType();