[cfe-commits] r45276 - in /cfe/trunk: AST/ASTContext.cpp Sema/SemaExpr.cpp include/clang/AST/ASTContext.h

Fariborz Jahanian fjahanian at apple.com
Thu Dec 20 16:33:59 PST 2007


Author: fjahanian
Date: Thu Dec 20 18:33:59 2007
New Revision: 45276

URL: http://llvm.org/viewvc/llvm-project?rev=45276&view=rev
Log:
More objective-c type analysis. This time involving objective types
of conforming protocols (or not).

Modified:
    cfe/trunk/AST/ASTContext.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/ASTContext.h

Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=45276&r1=45275&r2=45276&view=diff

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Thu Dec 20 18:33:59 2007
@@ -1278,10 +1278,25 @@
   return true;
 }
 
+/// 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;
+}
+
 /// ObjcQualifiedIdTypesAreCompatible - Compares two types, at least
-/// one of which is a protocol qualified 'id' type.
+/// 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) {
+                                                   QualType rhs,
+                                                   bool compare) {
   // match id<P..> with an 'id' type in all cases.
   if (const PointerType *PT = lhs->getAsPointerType()) {
     QualType PointeeTy = PT->getPointeeType();
@@ -1339,7 +1354,8 @@
       }
       for (unsigned j = 0; j < numRhsProtocols; j++) {
         ObjcProtocolDecl *rhsProto = rhsProtoList[j];
-        if (lhsProto == rhsProto) {
+        if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
+            compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto)) {
           match = true;
           break;
         }
@@ -1385,7 +1401,8 @@
       ObjcProtocolDecl *lhsProto = lhsProtoList[i];
       for (unsigned j = 0; j < rhsQID->getNumProtocols(); j++) {
         ObjcProtocolDecl *rhsProto = rhsQID->getProtocols(j);
-        if (lhsProto == rhsProto) {
+        if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
+          compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto)) {
           match = true;
           break;
         }

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=45276&r1=45275&r2=45276&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Thu Dec 20 18:33:59 2007
@@ -1400,7 +1400,7 @@
     return Context.IntTy;
   }
   if ((lType->isObjcQualifiedIdType() || rType->isObjcQualifiedIdType())
-      && Context.ObjcQualifiedIdTypesAreCompatible(lType, rType)) {
+      && Context.ObjcQualifiedIdTypesAreCompatible(lType, rType, true)) {
     promoteExprToType(rex, lType); 
     return Context.IntTy;
   }

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=45276&r1=45275&r2=45276&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Dec 20 18:33:59 2007
@@ -297,7 +297,7 @@
   /// Objective-C specific type checking.
   bool interfaceTypesAreCompatible(QualType, QualType);
   bool QualifiedInterfaceTypesAreCompatible(QualType, QualType);
-  bool ObjcQualifiedIdTypesAreCompatible(QualType, QualType);
+  bool ObjcQualifiedIdTypesAreCompatible(QualType, QualType, bool = false);
   bool objcTypesAreCompatible(QualType, QualType);
   bool isObjcIdType(QualType T) const {
     if (!IdStructType) // ObjC isn't enabled





More information about the cfe-commits mailing list