summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-07 05:53:18 +0000
committerChris Lattner <sabre@nondot.org>2008-04-07 05:53:18 +0000
commit90bef90ad40d2e4e82e1762a1e947a5578c1208e (patch)
tree0286c7d53401d43f143e46cb8a6c3b734b6dd922 /clang/lib/AST/ASTContext.cpp
parent856d8f5b58061364339ddfed603bdadd89d24bcb (diff)
downloadbcm5719-llvm-90bef90ad40d2e4e82e1762a1e947a5578c1208e.tar.gz
bcm5719-llvm-90bef90ad40d2e4e82e1762a1e947a5578c1208e.zip
futher simplify compatibility testing of objc interface types.
llvm-svn: 49318
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
-rw-r--r--clang/lib/AST/ASTContext.cpp45
1 files changed, 20 insertions, 25 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a7315256c4..c7d93404015 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1442,29 +1442,18 @@ bool ASTContext::builtinTypesAreCompatible(QualType lhs, QualType rhs) {
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 @@ bool ASTContext::typesAreCompatible(QualType LHS_NC, QualType RHS_NC) {
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()) {
OpenPOWER on IntegriCloud