]> granicus.if.org Git - clang/commitdiff
ArrayRef'ize ObjCMessageExpr
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 3 Oct 2011 06:36:45 +0000 (06:36 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 3 Oct 2011 06:36:45 +0000 (06:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140986 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprObjC.h
lib/AST/Expr.cpp
lib/Rewrite/RewriteObjC.cpp
lib/Sema/SemaExprObjC.cpp

index d141fda395d7bb09d5ddb5e63826c9c2c734a438..b8cef68a7d6d33ca1e0786c66fdf58badc708264 100644 (file)
@@ -502,7 +502,7 @@ class ObjCMessageExpr : public Expr {
                   Selector Sel, 
                   SourceLocation SelLoc,
                   ObjCMethodDecl *Method,
-                  Expr **Args, unsigned NumArgs,
+                  ArrayRef<Expr *> Args,
                   SourceLocation RBracLoc);
   ObjCMessageExpr(QualType T, ExprValueKind VK,
                   SourceLocation LBracLoc,
@@ -510,7 +510,7 @@ class ObjCMessageExpr : public Expr {
                   Selector Sel, 
                   SourceLocation SelLoc,
                   ObjCMethodDecl *Method,
-                  Expr **Args, unsigned NumArgs,
+                  ArrayRef<Expr *> Args,
                   SourceLocation RBracLoc);
   ObjCMessageExpr(QualType T, ExprValueKind VK,
                   SourceLocation LBracLoc,
@@ -518,7 +518,7 @@ class ObjCMessageExpr : public Expr {
                   Selector Sel, 
                   SourceLocation SelLoc,
                   ObjCMethodDecl *Method,
-                  Expr **Args, unsigned NumArgs,
+                  ArrayRef<Expr *> Args,
                   SourceLocation RBracLoc);
 
   /// \brief Retrieve the pointer value of the message receiver.
@@ -581,7 +581,7 @@ public:
                                  Selector Sel, 
                                  ArrayRef<SourceLocation> SelLocs,
                                  ObjCMethodDecl *Method,
-                                 Expr **Args, unsigned NumArgs,
+                                 ArrayRef<Expr *> Args,
                                  SourceLocation RBracLoc);
 
   /// \brief Create a class message send.
@@ -616,7 +616,7 @@ public:
                                  Selector Sel, 
                                  ArrayRef<SourceLocation> SelLocs,
                                  ObjCMethodDecl *Method,
-                                 Expr **Args, unsigned NumArgs,
+                                 ArrayRef<Expr *> Args,
                                  SourceLocation RBracLoc);
 
   /// \brief Create an instance message send.
@@ -651,7 +651,7 @@ public:
                                  Selector Sel, 
                                  ArrayRef<SourceLocation> SeLocs,
                                  ObjCMethodDecl *Method,
-                                 Expr **Args, unsigned NumArgs,
+                                 ArrayRef<Expr *> Args,
                                  SourceLocation RBracLoc);
 
   /// \brief Create an empty Objective-C message expression, to be
index b0f23f9717eb49dfe2ecb3156df029bccf76d0a8..f93ce72d254d6e545674a65124b8c173037d3db6 100644 (file)
@@ -2718,7 +2718,7 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
                                  Selector Sel, 
                                  SourceLocation SelLoc,
                                  ObjCMethodDecl *Method,
-                                 Expr **Args, unsigned NumArgs,
+                                 ArrayRef<Expr *> Args,
                                  SourceLocation RBracLoc)
   : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary,
          /*TypeDependent=*/false, /*ValueDependent=*/false,
@@ -2730,10 +2730,10 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
                                                        : Sel.getAsOpaquePtr())),
     SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 
 {
-  setNumArgs(NumArgs);
+  setNumArgs(Args.size());
   setReceiverPointer(SuperType.getAsOpaquePtr());
-  if (NumArgs)
-    memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
+  if (!Args.empty())
+    std::copy(Args.begin(), Args.end(), getArgs());
 }
 
 ObjCMessageExpr::ObjCMessageExpr(QualType T,
@@ -2743,7 +2743,7 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
                                  Selector Sel,
                                  SourceLocation SelLoc,
                                  ObjCMethodDecl *Method,
-                                 Expr **Args, unsigned NumArgs,
+                                 ArrayRef<Expr *> Args,
                                  SourceLocation RBracLoc)
   : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(),
          T->isDependentType(), T->isInstantiationDependentType(),
@@ -2754,10 +2754,10 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
                                                        : Sel.getAsOpaquePtr())),
     SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 
 {
-  setNumArgs(NumArgs);
+  setNumArgs(Args.size());
   setReceiverPointer(Receiver);
   Expr **MyArgs = getArgs();
-  for (unsigned I = 0; I != NumArgs; ++I) {
+  for (unsigned I = 0; I != Args.size(); ++I) {
     if (Args[I]->isTypeDependent())
       ExprBits.TypeDependent = true;
     if (Args[I]->isValueDependent())
@@ -2778,7 +2778,7 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
                                  Selector Sel, 
                                  SourceLocation SelLoc,
                                  ObjCMethodDecl *Method,
-                                 Expr **Args, unsigned NumArgs,
+                                 ArrayRef<Expr *> Args,
                                  SourceLocation RBracLoc)
   : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(),
          Receiver->isTypeDependent(),
@@ -2790,10 +2790,10 @@ ObjCMessageExpr::ObjCMessageExpr(QualType T,
                                                        : Sel.getAsOpaquePtr())),
     SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 
 {
-  setNumArgs(NumArgs);
+  setNumArgs(Args.size());
   setReceiverPointer(Receiver);
   Expr **MyArgs = getArgs();
-  for (unsigned I = 0; I != NumArgs; ++I) {
+  for (unsigned I = 0; I != Args.size(); ++I) {
     if (Args[I]->isTypeDependent())
       ExprBits.TypeDependent = true;
     if (Args[I]->isValueDependent())
@@ -2816,14 +2816,14 @@ ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
                                          Selector Sel, 
                                          ArrayRef<SourceLocation> SelLocs,
                                          ObjCMethodDecl *Method,
-                                         Expr **Args, unsigned NumArgs,
+                                         ArrayRef<Expr *> Args,
                                          SourceLocation RBracLoc) {
   unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 
-    NumArgs * sizeof(Expr *);
+    Args.size() * sizeof(Expr *);
   void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
   return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper,
                                    SuperType, Sel, SelLocs.front(), Method,
-                                   Args, NumArgs, RBracLoc);
+                                   Args, RBracLoc);
 }
 
 ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
@@ -2833,14 +2833,14 @@ ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
                                          Selector Sel, 
                                          ArrayRef<SourceLocation> SelLocs,
                                          ObjCMethodDecl *Method,
-                                         Expr **Args, unsigned NumArgs,
+                                         ArrayRef<Expr *> Args,
                                          SourceLocation RBracLoc) {
   unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 
-    NumArgs * sizeof(Expr *);
+    Args.size() * sizeof(Expr *);
   void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
   return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel,
                                    SelLocs.front(),
-                                   Method, Args, NumArgs, RBracLoc);
+                                   Method, Args, RBracLoc);
 }
 
 ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
@@ -2850,14 +2850,14 @@ ObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
                                          Selector Sel,
                                          ArrayRef<SourceLocation> SelLocs,
                                          ObjCMethodDecl *Method,
-                                         Expr **Args, unsigned NumArgs,
+                                         ArrayRef<Expr *> Args,
                                          SourceLocation RBracLoc) {
   unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 
-    NumArgs * sizeof(Expr *);
+    Args.size() * sizeof(Expr *);
   void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
   return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel,
                                    SelLocs.front(),
-                                   Method, Args, NumArgs, RBracLoc);
+                                   Method, Args, RBracLoc);
 }
 
 ObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 
index dcb3e602c05ff31a4ac2977f69538d02ed563e52..a62f4aa62298f9b344867c953662e0067a8f8ff2 100644 (file)
@@ -1316,8 +1316,6 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitSetter(BinaryOperator *BinOp, Expr *
   }
   
   assert(OMD && "RewritePropertyOrImplicitSetter - null OMD");
-  SmallVector<Expr *, 1> ExprVec;
-  ExprVec.push_back(newStmt);
 
   ObjCMessageExpr *MsgExpr;
   if (Super)
@@ -1329,7 +1327,7 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitSetter(BinaryOperator *BinOp, Expr *
                                       /*IsInstanceSuper=*/true,
                                       SuperTy,
                                       Sel, SelectorLoc, OMD,
-                                      &ExprVec[0], 1,
+                                      newStmt,
                                       /*FIXME:*/SourceLocation());
   else {
     // FIXME. Refactor this into common code with that in 
@@ -1346,7 +1344,7 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitSetter(BinaryOperator *BinOp, Expr *
                                       /*FIXME: */SourceLocation(),
                                       cast<Expr>(Receiver),
                                       Sel, SelectorLoc, OMD,
-                                      &ExprVec[0], 1,
+                                      newStmt,
                                       /*FIXME:*/SourceLocation());
   }
   Stmt *ReplacingStmt = SynthMessageExpr(MsgExpr);
@@ -1405,7 +1403,7 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitGetter(Expr *PropOrGetterRefExpr) {
                                       /*IsInstanceSuper=*/true,
                                       SuperTy,
                                       Sel, SelectorLoc, OMD,
-                                      0, 0
+                                      ArrayRef<Expr*>()
                                       PropOrGetterRefExpr->getLocEnd());
   else {
     assert (Receiver && "RewritePropertyOrImplicitGetter - Receiver is null");
@@ -1419,7 +1417,7 @@ Stmt *RewriteObjC::RewritePropertyOrImplicitGetter(Expr *PropOrGetterRefExpr) {
                                       PropOrGetterRefExpr->getLocStart(),
                                       cast<Expr>(Receiver),
                                       Sel, SelectorLoc, OMD,
-                                      0, 0
+                                      ArrayRef<Expr*>()
                                       PropOrGetterRefExpr->getLocEnd());
   }
 
index 84167fef3f7e54325c293bf3168fe190928877d3..20098b21366d805350aa7180e2413eeb9221a559 100644 (file)
@@ -27,6 +27,7 @@
 
 using namespace clang;
 using namespace sema;
+using llvm::makeArrayRef;
 
 ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
                                         Expr **strings,
@@ -1065,7 +1066,7 @@ ExprResult Sema::BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
     return Owned(ObjCMessageExpr::Create(Context, ReceiverType,
                                          VK_RValue, LBracLoc, ReceiverTypeInfo,
                                          Sel, SelectorLocs, /*Method=*/0,
-                                         Args, NumArgs, RBracLoc));
+                                         makeArrayRef(Args, NumArgs),RBracLoc));
   }
   
   // Find the class to which we are sending this message.
@@ -1127,11 +1128,13 @@ ExprResult Sema::BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
     Result = ObjCMessageExpr::Create(Context, ReturnType, VK, LBracLoc, 
                                      SuperLoc, /*IsInstanceSuper=*/false, 
                                      ReceiverType, Sel, SelectorLocs,
-                                     Method, Args, NumArgs, RBracLoc);
+                                     Method, makeArrayRef(Args, NumArgs),
+                                     RBracLoc);
   else
     Result = ObjCMessageExpr::Create(Context, ReturnType, VK, LBracLoc, 
                                      ReceiverTypeInfo, Sel, SelectorLocs,
-                                     Method, Args, NumArgs, RBracLoc);
+                                     Method, makeArrayRef(Args, NumArgs),
+                                     RBracLoc);
   return MaybeBindToTemporary(Result);
 }
 
@@ -1217,7 +1220,8 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
       return Owned(ObjCMessageExpr::Create(Context, Context.DependentTy,
                                            VK_RValue, LBracLoc, Receiver, Sel, 
                                            SelectorLocs, /*Method=*/0,
-                                           Args, NumArgs, RBracLoc));
+                                           makeArrayRef(Args, NumArgs),
+                                           RBracLoc));
     }
 
     // If necessary, apply function/array conversion to the receiver.
@@ -1501,11 +1505,11 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
     Result = ObjCMessageExpr::Create(Context, ReturnType, VK, LBracLoc,
                                      SuperLoc,  /*IsInstanceSuper=*/true,
                                      ReceiverType, Sel, SelectorLocs, Method, 
-                                     Args, NumArgs, RBracLoc);
+                                     makeArrayRef(Args, NumArgs), RBracLoc);
   else
     Result = ObjCMessageExpr::Create(Context, ReturnType, VK, LBracLoc,
                                      Receiver, Sel, SelectorLocs, Method,
-                                     Args, NumArgs, RBracLoc);
+                                     makeArrayRef(Args, NumArgs), RBracLoc);
 
   if (getLangOptions().ObjCAutoRefCount) {
     // In ARC, annotate delegate init calls.