]> granicus.if.org Git - clang/commitdiff
objc - some refactoring of my last 'self' patch.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 19 Sep 2011 18:06:07 +0000 (18:06 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 19 Sep 2011 18:06:07 +0000 (18:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140031 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp

index 715a4bd025c9a1f8d6aa97609881589833d4f5ae..9fb0ac211f207cb1d2ae86a4fafc5b59cb808459 100644 (file)
@@ -5074,10 +5074,11 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
                               OK));
 }
 
-/// SelfInClassMethodType - convet type of 'self' in class method
+/// ConvertObjCSelfToClassRootType - convet type of 'self' in class method
 /// to pointer to root of method's class.
-static void
-SelfInClassMethodType(Sema &S, Expr *selfExpr, QualType &SelfType) {
+static QualType
+ConvertObjCSelfToClassRootType(Sema &S, Expr *selfExpr) {
+  QualType SelfType;
   if (const ObjCMethodDecl *MD = S.GetMethodIfSelfExpr(selfExpr))
     if (MD->isClassMethod()) {
       const ObjCInterfaceDecl *Root = 0;
@@ -5086,9 +5087,10 @@ SelfInClassMethodType(Sema &S, Expr *selfExpr, QualType &SelfType) {
         Root = IDecl;
       } while ((IDecl = IDecl->getSuperClass()));
       if (Root)
-        SelfType = S.Context.getObjCObjectPointerType(
-                                                   S.Context.getObjCInterfaceType(Root)); 
+        SelfType =  S.Context.getObjCObjectPointerType(
+                      S.Context.getObjCInterfaceType(Root)); 
     }
+  return SelfType;
 }
 
 // checkPointerTypesForAssignment - This is a very tricky routine (despite
@@ -5326,8 +5328,6 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS,
     return Compatible;
   }
 
-  SelfInClassMethodType(*this, RHS.get(), RHSType);
-
   // If the left-hand side is a reference type, then we are in a
   // (rare!) case where we've allowed the use of references in C,
   // e.g., as a parameter type in a built-in function. In this case,
@@ -5420,7 +5420,7 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS,
         Kind = CK_BitCast;
         return Compatible;
       }
-
+      
       Kind = CK_BitCast;
       return IncompatiblePointer;
     }
@@ -5468,6 +5468,9 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS,
 
   // Conversions to Objective-C pointers.
   if (isa<ObjCObjectPointerType>(LHSType)) {
+    QualType RHSQT = ConvertObjCSelfToClassRootType(*this, RHS.get());
+    if (!RHSQT.isNull())
+      RHSType = RHSQT;
     // A* -> B*
     if (RHSType->isObjCObjectPointerType()) {
       Kind = CK_BitCast;