Eliminate usage of ObjCSuperExpr used for
'super' as receiver of property or a setter/getter
methods. //rdar: //8525788

llvm-svn: 116483
diff --git a/clang/lib/Rewrite/RewriteObjC.cpp b/clang/lib/Rewrite/RewriteObjC.cpp
index 339b7d1..8532bc7 100644
--- a/clang/lib/Rewrite/RewriteObjC.cpp
+++ b/clang/lib/Rewrite/RewriteObjC.cpp
@@ -1209,6 +1209,9 @@
   QualType Ty;
   Selector Sel;
   Stmt *Receiver;
+  bool Super = false;
+  QualType SuperTy;
+  SourceLocation SuperLocation;
   // Synthesize a ObjCMessageExpr from a ObjCPropertyRefExpr or ObjCImplicitSetterGetterRefExpr.
   // This allows us to reuse all the fun and games in SynthMessageExpr().
   if (ObjCPropertyRefExpr *PropRefExpr = dyn_cast<ObjCPropertyRefExpr>(BinOp->getLHS())) {
@@ -1216,14 +1219,26 @@
     OMD = PDecl->getSetterMethodDecl();
     Ty = PDecl->getType();
     Sel = PDecl->getSetterName();
-    Receiver = PropRefExpr->getBase();
+    Super = PropRefExpr->isSuperReceiver();
+    if (!Super)
+      Receiver = PropRefExpr->getBase();
+    else {
+      SuperTy = PropRefExpr->getSuperType();
+      SuperLocation = PropRefExpr->getSuperLocation();
+    }
   }
   else if (ObjCImplicitSetterGetterRefExpr *ImplicitRefExpr = 
            dyn_cast<ObjCImplicitSetterGetterRefExpr>(BinOp->getLHS())) {
     OMD = ImplicitRefExpr->getSetterMethod();
     Sel = OMD->getSelector();
     Ty = ImplicitRefExpr->getType();
-    Receiver = ImplicitRefExpr->getBase();
+    Super = ImplicitRefExpr->isSuperReceiver();
+    if (!Super)
+      Receiver = ImplicitRefExpr->getBase();
+    else {
+      SuperTy = ImplicitRefExpr->getSuperType();
+      SuperLocation = ImplicitRefExpr->getSuperLocation();
+    }
   }
   
   assert(OMD && "RewritePropertyOrImplicitSetter - null OMD");
@@ -1236,13 +1251,13 @@
       Receiver = PropGetters[Exp];
   
   ObjCMessageExpr *MsgExpr;
-  if (isa<ObjCSuperExpr>(Receiver))
+  if (Super)
     MsgExpr = ObjCMessageExpr::Create(*Context, 
                                       Ty.getNonReferenceType(),
                                       /*FIXME?*/SourceLocation(),
-                                      Receiver->getLocStart(),
+                                      SuperLocation,
                                       /*IsInstanceSuper=*/true,
-                                      cast<Expr>(Receiver)->getType(),
+                                      SuperTy,
                                       Sel, OMD,
                                       &ExprVec[0], 1,
                                       /*FIXME:*/SourceLocation());
@@ -1272,20 +1287,35 @@
   ObjCMethodDecl *OMD = 0;
   QualType Ty;
   Selector Sel;
+  bool Super = false;
+  QualType SuperTy;
+  SourceLocation SuperLocation;
   if (ObjCPropertyRefExpr *PropRefExpr = 
         dyn_cast<ObjCPropertyRefExpr>(PropOrGetterRefExpr)) {
     ObjCPropertyDecl *PDecl = PropRefExpr->getProperty();
     OMD = PDecl->getGetterMethodDecl();
-    Receiver = PropRefExpr->getBase();
     Ty = PDecl->getType();
     Sel = PDecl->getGetterName();
+    Super = PropRefExpr->isSuperReceiver();
+    if (!Super)
+      Receiver = PropRefExpr->getBase();
+    else {
+      SuperTy = PropRefExpr->getSuperType();
+      SuperLocation = PropRefExpr->getSuperLocation();
+    }
   }
   else if (ObjCImplicitSetterGetterRefExpr *ImplicitRefExpr = 
             dyn_cast<ObjCImplicitSetterGetterRefExpr>(PropOrGetterRefExpr)) {
     OMD = ImplicitRefExpr->getGetterMethod();
-    Receiver = ImplicitRefExpr->getBase();
     Sel = OMD->getSelector();
     Ty = ImplicitRefExpr->getType();
+    Super = ImplicitRefExpr->isSuperReceiver();
+    if (!Super)
+      Receiver = ImplicitRefExpr->getBase();
+    else {
+      SuperTy = ImplicitRefExpr->getSuperType();
+      SuperLocation = ImplicitRefExpr->getSuperLocation();
+    }
   }
   
   assert (OMD && "RewritePropertyOrImplicitGetter - OMD is null");
@@ -1296,13 +1326,13 @@
       Receiver = PropGetters[Exp];
   
   ObjCMessageExpr *MsgExpr;
-  if (isa<ObjCSuperExpr>(Receiver))
+  if (Super)
     MsgExpr = ObjCMessageExpr::Create(*Context, 
                                       Ty.getNonReferenceType(),
-                                      /*FIXME:*/SourceLocation(),
-                                      Receiver->getLocStart(),
+                                      /*FIXME?*/SourceLocation(),
+                                      SuperLocation,
                                       /*IsInstanceSuper=*/true,
-                                      cast<Expr>(Receiver)->getType(),
+                                      SuperTy,
                                       Sel, OMD,
                                       0, 0, 
                                       /*FIXME:*/SourceLocation());