]> granicus.if.org Git - clang/commitdiff
Refactor objective-c pointer assignment compatibility logic. No
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 8 Dec 2009 18:24:49 +0000 (18:24 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 8 Dec 2009 18:24:49 +0000 (18:24 +0000)
intended functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90865 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp

index 46a87cff3ff68491d9449581776d112084cd73b6..a7eb0c6d8855d7841ad1791947a532980e7a6645 100644 (file)
@@ -3553,6 +3553,9 @@ public:
   AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
                                                    QualType rhsType);
 
+  AssignConvertType CheckObjCPointerTypesForAssignment(QualType lhsType,
+                                                       QualType rhsType);
+
   // Helper function for CheckAssignmentConstraints involving two
   // block pointer types.
   AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
index 776ea71f291d96a3c01717b97a9f0ebb94538ec8..4920206b25931cdad662a94139bd3846c9a34303 100644 (file)
@@ -4310,6 +4310,29 @@ Sema::CheckBlockPointerTypesForAssignment(QualType lhsType,
   return ConvTy;
 }
 
+/// CheckObjCPointerTypesForAssignment - Compares two objective-c pointer types
+/// for assignment compatibility.
+Sema::AssignConvertType
+Sema::CheckObjCPointerTypesForAssignment(QualType lhsType, QualType rhsType) {
+  if (lhsType->isObjCBuiltinType() || rhsType->isObjCBuiltinType())
+    return Compatible;
+  QualType lhptee = 
+  lhsType->getAs<ObjCObjectPointerType>()->getPointeeType();
+  QualType rhptee = 
+  rhsType->getAs<ObjCObjectPointerType>()->getPointeeType();
+  // make sure we operate on the canonical type
+  lhptee = Context.getCanonicalType(lhptee);
+  rhptee = Context.getCanonicalType(rhptee);
+  if (!lhptee.isAtLeastAsQualifiedAs(rhptee))
+    return CompatiblePointerDiscardsQualifiers;
+  
+  if (Context.typesAreCompatible(lhsType, rhsType))
+    return Compatible;
+  if (lhsType->isObjCQualifiedIdType() || rhsType->isObjCQualifiedIdType())
+    return IncompatibleObjCQualifiedId;
+  return IncompatiblePointer;  
+}
+
 /// CheckAssignmentConstraints (C99 6.5.16) - This routine currently
 /// has code to accommodate several GCC extensions when type checking
 /// pointers. Here are some objectionable examples that GCC considers warnings:
@@ -4432,23 +4455,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
       return IncompatiblePointer;
     }
     if (rhsType->isObjCObjectPointerType()) {
-      if (lhsType->isObjCBuiltinType() || rhsType->isObjCBuiltinType())
-        return Compatible;
-      QualType lhptee = 
-        lhsType->getAs<ObjCObjectPointerType>()->getPointeeType();
-      QualType rhptee = 
-        rhsType->getAs<ObjCObjectPointerType>()->getPointeeType();
-      // make sure we operate on the canonical type
-      lhptee = Context.getCanonicalType(lhptee);
-      rhptee = Context.getCanonicalType(rhptee);
-      if (!lhptee.isAtLeastAsQualifiedAs(rhptee))
-        return CompatiblePointerDiscardsQualifiers;
-      
-      if (Context.typesAreCompatible(lhsType, rhsType))
-        return Compatible;
-      if (lhsType->isObjCQualifiedIdType() || rhsType->isObjCQualifiedIdType())
-        return IncompatibleObjCQualifiedId;
-      return IncompatiblePointer;
+      return CheckObjCPointerTypesForAssignment(lhsType, rhsType);
     }
     if (const PointerType *RHSPT = rhsType->getAs<PointerType>()) {
       if (RHSPT->getPointeeType()->isVoidType())