[cfe-commits] r64385 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/Analysis/CFRefCount.cpp lib/CodeGen/CGObjCMac.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprObjC.cpp lib/Sema/SemaOverload.cpp

Steve Naroff snaroff at apple.com
Thu Feb 12 09:52:19 PST 2009


Author: snaroff
Date: Thu Feb 12 11:52:19 2009
New Revision: 64385

URL: http://llvm.org/viewvc/llvm-project?rev=64385&view=rev
Log:
Several cleanups:
- rename isObjCIdType/isObjCClassType -> isObjCIdStructType/isObjCClassStructType. The previous name didn't do what you would expect.
- add back isObjCIdType/isObjCClassType to do what you would expect. Not currently used, however many of the isObjCIdStructType/isObjCClassStructType clients could be converted over time.
- move static Sema function areComparableObjCInterfaces to ASTContext (renamed to areComparableObjCPointerTypes, since it now operates on pointer types).

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Feb 12 11:52:19 2009
@@ -541,11 +541,17 @@
   bool typesAreBlockCompatible(QualType lhs, QualType rhs);
   
   bool isObjCIdType(QualType T) const {
+    return T == ObjCIdType;
+  }
+  bool isObjCIdStructType(QualType T) const {
     if (!IdStructType) // ObjC isn't enabled
       return false;
     return T->getAsStructureType() == IdStructType;
   }
   bool isObjCClassType(QualType T) const {
+    return T == ObjCClassType;
+  }
+  bool isObjCClassStructType(QualType T) const {
     if (!ClassStructType) // ObjC isn't enabled
       return false;
     return T->getAsStructureType() == ClassStructType;
@@ -558,6 +564,7 @@
   // Check the safety of assignment from LHS to RHS
   bool canAssignObjCInterfaces(const ObjCInterfaceType *LHS, 
                                const ObjCInterfaceType *RHS);
+  bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
 
   // Functions for calculating composite types
   QualType mergeTypes(QualType, QualType);

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Feb 12 11:52:19 2009
@@ -2046,7 +2046,7 @@
         S.replace(S.end()-2, S.end(), replace);
       }
     }
-    if (isObjCIdType(PointeeTy)) {
+    if (isObjCIdStructType(PointeeTy)) {
       S += '@';
       return;
     }
@@ -2076,7 +2076,7 @@
         S += '"';
       }
       return;
-    } else if (isObjCClassType(PointeeTy)) {
+    } else if (isObjCClassStructType(PointeeTy)) {
       S += '#';
       return;
     } else if (isObjCSelType(PointeeTy)) {
@@ -2411,6 +2411,29 @@
   return false;
 }
 
+bool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) {
+  // get the "pointed to" types
+  const PointerType *LHSPT = LHS->getAsPointerType();
+  const PointerType *RHSPT = RHS->getAsPointerType();
+  
+  if (!LHSPT || !RHSPT)
+    return false;
+    
+  QualType lhptee = LHSPT->getPointeeType();
+  QualType rhptee = RHSPT->getPointeeType();
+  const ObjCInterfaceType* LHSIface = lhptee->getAsObjCInterfaceType();
+  const ObjCInterfaceType* RHSIface = rhptee->getAsObjCInterfaceType();
+  // ID acts sort of like void* for ObjC interfaces
+  if (LHSIface && isObjCIdStructType(rhptee))
+    return true;
+  if (RHSIface && isObjCIdStructType(lhptee))
+    return true;
+  if (!LHSIface || !RHSIface)
+    return false;
+  return canAssignObjCInterfaces(LHSIface, RHSIface) ||
+         canAssignObjCInterfaces(RHSIface, LHSIface);
+}
+
 /// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, 
 /// both shall have the identically qualified version of a compatible type.
 /// C99 6.2.7p1: Two types have compatible types if their types are the 
@@ -2552,7 +2575,7 @@
     if (LHS->isObjCQualifiedIdType()) {
       if (const PointerType *PT = RHS->getAsPointerType()) {
         QualType pType = PT->getPointeeType();
-        if (isObjCIdType(pType))
+        if (isObjCIdStructType(pType))
           return LHS;
         // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true).
         // Unfortunately, this API is part of Sema (which we don't have access
@@ -2565,7 +2588,7 @@
     if (RHS->isObjCQualifiedIdType()) {
       if (const PointerType *PT = LHS->getAsPointerType()) {
         QualType pType = PT->getPointeeType();
-        if (isObjCIdType(pType))
+        if (isObjCIdStructType(pType))
           return RHS;
         // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true).
         // Unfortunately, this API is part of Sema (which we don't have access
@@ -2662,8 +2685,8 @@
     return mergeFunctionTypes(LHS, RHS);
   case Type::Tagged:
     // FIXME: Why are these compatible?
-    if (isObjCIdType(LHS) && isObjCClassType(RHS)) return LHS;
-    if (isObjCClassType(LHS) && isObjCIdType(RHS)) return LHS;
+    if (isObjCIdStructType(LHS) && isObjCClassStructType(RHS)) return LHS;
+    if (isObjCClassStructType(LHS) && isObjCIdStructType(RHS)) return LHS;
     return QualType();
   case Type::Builtin:
     // Only exactly equal builtin types are compatible, which is tested above.

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=64385&r1=64384&r2=64385&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Thu Feb 12 11:52:19 2009
@@ -1449,7 +1449,7 @@
   
   ObjCMessageExpr* ME = dyn_cast<ObjCMessageExpr>(RetE);
   
-  if (!ME || !Ctx.isObjCIdType(PT->getPointeeType()))
+  if (!ME || !Ctx.isObjCIdStructType(PT->getPointeeType()))
     return RetTy;
   
   ObjCInterfaceDecl* D = ME->getClassInfo().first;  

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=64385&r1=64384&r2=64385&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Feb 12 11:52:19 2009
@@ -1970,7 +1970,7 @@
         // catch(id e) always matches. 
         // FIXME: For the time being we also match id<X>; this should
         // be rejected by Sema instead.
-        if ((PT && CGF.getContext().isObjCIdType(PT->getPointeeType())) ||
+        if ((PT && CGF.getContext().isObjCIdStructType(PT->getPointeeType())) ||
             VD->getType()->isObjCQualifiedIdType())
           AllMatched = true;
       }

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 12 11:52:19 2009
@@ -2256,9 +2256,9 @@
         } else if (LHSIface && RHSIface &&
                    Context.canAssignObjCInterfaces(RHSIface, LHSIface)) {
           compositeType = rexT;
-        } else if (Context.isObjCIdType(lhptee) || 
-                   Context.isObjCIdType(rhptee)) { 
-          // FIXME: This code looks wrong, because isObjCIdType checks
+        } else if (Context.isObjCIdStructType(lhptee) || 
+                   Context.isObjCIdStructType(rhptee)) { 
+          // FIXME: This code looks wrong, because isObjCIdStructType checks
           // the struct but getObjCIdType returns the pointer to
           // struct. This is horrible and should be fixed.
           compositeType = Context.getObjCIdType();
@@ -2412,9 +2412,9 @@
     return ConvTy;
 
   // ID acts sort of like void* for ObjC interfaces
-  if (LHSIface && Context.isObjCIdType(rhptee))
+  if (LHSIface && Context.isObjCIdStructType(rhptee))
     return ConvTy;
-  if (RHSIface && Context.isObjCIdType(lhptee))
+  if (RHSIface && Context.isObjCIdStructType(lhptee))
     return ConvTy;
 
   // C99 6.5.16.1p1 (constraint 3): both operands are pointers to qualified or 
@@ -2903,21 +2903,6 @@
   return lex->getType();
 }
 
-static bool areComparableObjCInterfaces(QualType LHS, QualType RHS,
-                                        ASTContext& Context) {
-  const ObjCInterfaceType* LHSIface = LHS->getAsObjCInterfaceType();
-  const ObjCInterfaceType* RHSIface = RHS->getAsObjCInterfaceType();
-  // ID acts sort of like void* for ObjC interfaces
-  if (LHSIface && Context.isObjCIdType(RHS))
-    return true;
-  if (RHSIface && Context.isObjCIdType(LHS))
-    return true;
-  if (!LHSIface || !RHSIface)
-    return false;
-  return Context.canAssignObjCInterfaces(LHSIface, RHSIface) ||
-         Context.canAssignObjCInterfaces(RHSIface, LHSIface);
-}
-
 // C99 6.5.8
 QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
                                     bool isRelational) {
@@ -2977,7 +2962,7 @@
         !LCanPointeeTy->isVoidType() && !RCanPointeeTy->isVoidType() &&
         !Context.typesAreCompatible(LCanPointeeTy.getUnqualifiedType(),
                                     RCanPointeeTy.getUnqualifiedType()) &&
-        !areComparableObjCInterfaces(LCanPointeeTy, RCanPointeeTy, Context)) {
+        !Context.areComparableObjCPointerTypes(lType, rType)) {
       Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
         << lType << rType << lex->getSourceRange() << rex->getSourceRange();
     }

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=64385&r1=64384&r2=64385&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Feb 12 11:52:19 2009
@@ -485,11 +485,11 @@
   // Allow id<P..> and an 'id' or void* type in all cases.
   if (const PointerType *PT = lhs->getAsPointerType()) {
     QualType PointeeTy = PT->getPointeeType();
-    if (Context.isObjCIdType(PointeeTy) || PointeeTy->isVoidType())
+    if (Context.isObjCIdStructType(PointeeTy) || PointeeTy->isVoidType())
       return true;
   } else if (const PointerType *PT = rhs->getAsPointerType()) {
     QualType PointeeTy = PT->getPointeeType();
-    if (Context.isObjCIdType(PointeeTy) || PointeeTy->isVoidType())
+    if (Context.isObjCIdStructType(PointeeTy) || PointeeTy->isVoidType())
       return true;
   }
   

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=64385&r1=64384&r2=64385&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Feb 12 11:52:19 2009
@@ -1019,8 +1019,8 @@
 
   // Objective C++: We're able to convert between "id" and a pointer
   // to any interface (in both directions).
-  if ((FromIface && Context.isObjCIdType(ToPointeeType))
-      || (ToIface && Context.isObjCIdType(FromPointeeType))) {
+  if ((FromIface && Context.isObjCIdStructType(ToPointeeType))
+      || (ToIface && Context.isObjCIdStructType(FromPointeeType))) {
     ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, 
                                                        ToPointeeType,
                                                        ToType, Context);
@@ -1029,10 +1029,10 @@
 
   // Objective C++: Allow conversions between the Objective-C "id" and
   // "Class", in either direction.
-  if ((Context.isObjCIdType(FromPointeeType) && 
-       Context.isObjCClassType(ToPointeeType)) ||
-      (Context.isObjCClassType(FromPointeeType) &&
-       Context.isObjCIdType(ToPointeeType))) {
+  if ((Context.isObjCIdStructType(FromPointeeType) && 
+       Context.isObjCClassStructType(ToPointeeType)) ||
+      (Context.isObjCClassStructType(FromPointeeType) &&
+       Context.isObjCIdStructType(ToPointeeType))) {
     ConvertedType = ToType;
     return true;
   }
@@ -1131,10 +1131,10 @@
       // Objective-C++ conversions are always okay.
       // FIXME: We should have a different class of conversions for
       // the Objective-C++ implicit conversions.
-      if (Context.isObjCIdType(FromPointeeType) || 
-          Context.isObjCIdType(ToPointeeType) ||
-          Context.isObjCClassType(FromPointeeType) ||
-          Context.isObjCClassType(ToPointeeType))
+      if (Context.isObjCIdStructType(FromPointeeType) || 
+          Context.isObjCIdStructType(ToPointeeType) ||
+          Context.isObjCClassStructType(FromPointeeType) ||
+          Context.isObjCClassStructType(ToPointeeType))
         return false;
 
       if (FromPointeeType->isRecordType() &&





More information about the cfe-commits mailing list