[cfe-commits] r49318 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp
Chris Lattner
sabre at nondot.org
Sun Apr 6 22:53:18 PDT 2008
Author: lattner
Date: Mon Apr 7 00:53:18 2008
New Revision: 49318
URL: http://llvm.org/viewvc/llvm-project?rev=49318&view=rev
Log:
futher simplify compatibility testing of objc interface types.
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=49318&r1=49317&r2=49318&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Apr 7 00:53:18 2008
@@ -334,7 +334,6 @@
bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
bool builtinTypesAreCompatible(QualType, QualType);
- bool objcTypesAreCompatible(QualType, QualType);
bool isObjCIdType(QualType T) const {
if (!IdStructType) // ObjC isn't enabled
return false;
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=49318&r1=49317&r2=49318&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Apr 7 00:53:18 2008
@@ -1442,29 +1442,18 @@
return lBuiltin->getKind() == rBuiltin->getKind();
}
-/// objcTypesAreCompatible - This routine is called when two types
-/// are of different class; one is interface type or is
-/// a qualified interface type and the other type is of a different class.
-/// Example, II or II<P>.
-bool ASTContext::objcTypesAreCompatible(QualType LHS, QualType RHS) {
- // ID is compatible with all interface types.
- if (LHS->isObjCInterfaceType() && isObjCIdType(RHS))
- return true;
- else if (isObjCIdType(LHS) && RHS->isObjCInterfaceType())
- return true;
-
+/// areCompatObjCInterfaces - This routine is called when we are testing
+/// compatibility of two different [potentially qualified] ObjCInterfaceType's.
+static bool areCompatObjCInterfaces(const ObjCInterfaceType *LHS,
+ const ObjCInterfaceType *RHS) {
// II is compatible with II<P> if the base is the same. Otherwise, no two
// qualified interface types are the same.
- if (const ObjCInterfaceType *LHSIT = LHS->getAsObjCInterfaceType()) {
- if (const ObjCInterfaceType *RHSIT = RHS->getAsObjCInterfaceType()) {
- // If the base decls match and one is a qualified interface and one isn't,
- // then they are compatible.
- return LHSIT->getDecl() == RHSIT->getDecl() &&
- isa<ObjCQualifiedInterfaceType>(LHSIT) !=
- isa<ObjCQualifiedInterfaceType>(RHSIT);
- }
- }
- return false;
+ if (LHS->getDecl() != RHS->getDecl()) return false;
+
+ // If the base decls match and one is a qualified interface and one isn't,
+ // then they are compatible.
+ return isa<ObjCQualifiedInterfaceType>(LHS) !=
+ isa<ObjCQualifiedInterfaceType>(RHS);
}
/// areCompatObjCQualInterfaces - Return true if the two qualified interface
@@ -1674,10 +1663,16 @@
if (LHSClass != RHSClass) {
// For Objective-C, it is possible for two types to be compatible
// when their classes don't match (when dealing with "id"). If either type
- // is an interface, we defer to objcTypesAreCompatible().
- if (LHS->isObjCInterfaceType() || RHS->isObjCInterfaceType())
- return objcTypesAreCompatible(LHS, RHS);
-
+ // is an interface, we defer to areCompatObjCIDType().
+ if (const ObjCInterfaceType *LHSIT = LHS->getAsObjCInterfaceType()) {
+ if (const ObjCInterfaceType *RHSIT = RHS->getAsObjCInterfaceType())
+ return areCompatObjCInterfaces(LHSIT, RHSIT);
+ return isObjCIdType(RHS); // ID is compatible with all interface types.
+ }
+
+ if (RHS->isObjCInterfaceType())
+ return isObjCIdType(LHS); // ID is compatible with all interface types.
+
// C99 6.7.2.2p4: Each enumerated type shall be compatible with char,
// a signed integer type, or an unsigned integer type.
if (LHS->isEnumeralType() && RHS->isIntegralType()) {
More information about the cfe-commits
mailing list