]> granicus.if.org Git - clang/commitdiff
Refactor argument collection of constructor calls using
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 24 Nov 2009 21:37:28 +0000 (21:37 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 24 Nov 2009 21:37:28 +0000 (21:37 +0000)
the common routine.

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

lib/Sema/Sema.h
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprCXX.cpp

index 259bf25bed0eb189d9db59c9b071268537e47a41..1dda7308e023d2262d9a51d61e182a4fad127183 100644 (file)
@@ -3324,7 +3324,6 @@ public:
                               unsigned FirstProtoArg,
                               Expr **Args, unsigned NumArgs,
                               llvm::SmallVector<Expr *, 8> &AllArgs,
-                              Expr *Fn = 0,
                               VariadicCallType CallType = VariadicDoesNotApply);
 
   // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
index 58fe97a7e515d4f91238908d9ee8ea9c05b42355..797dbf5fe270a7d19e3c98dfa440c1c7b68fe5cd 100644 (file)
@@ -3645,58 +3645,22 @@ Sema::CompleteConstructorCall(CXXConstructorDecl *Constructor,
     = Constructor->getType()->getAs<FunctionProtoType>();
   assert(Proto && "Constructor without a prototype?");
   unsigned NumArgsInProto = Proto->getNumArgs();
-  unsigned NumArgsToCheck = NumArgs;
   
   // If too few arguments are available, we'll fill in the rest with defaults.
-  if (NumArgs < NumArgsInProto) {
-    NumArgsToCheck = NumArgsInProto;
+  if (NumArgs < NumArgsInProto)
     ConvertedArgs.reserve(NumArgsInProto);
-  } else {
+  else
     ConvertedArgs.reserve(NumArgs);
-    if (NumArgs > NumArgsInProto)
-      NumArgsToCheck = NumArgsInProto;
-  }
-  
-  // Convert arguments
-  for (unsigned i = 0; i != NumArgsToCheck; i++) {
-    QualType ProtoArgType = Proto->getArgType(i);
-    
-    Expr *Arg;
-    if (i < NumArgs) {
-      Arg = Args[i];
-      
-      // Pass the argument.
-      if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
-        return true;
-      
-      Args[i] = 0;
-    } else {
-      ParmVarDecl *Param = Constructor->getParamDecl(i);
-      
-      OwningExprResult DefArg = BuildCXXDefaultArgExpr(Loc, Constructor, Param);
-      if (DefArg.isInvalid())
-        return true;
-      
-      Arg = DefArg.takeAs<Expr>();
-    }
-    
-    ConvertedArgs.push_back(Arg);
-  }
-  
-  // If this is a variadic call, handle args passed through "...".
-  if (Proto->isVariadic()) {
-    // Promote the arguments (C99 6.5.2.2p7).
-    for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
-      Expr *Arg = Args[i];
-      if (DefaultVariadicArgumentPromotion(Arg, VariadicConstructor))
-        return true;
-      
-      ConvertedArgs.push_back(Arg);
-      Args[i] = 0;
-    }
-  }
-  
-  return false;
+
+  VariadicCallType CallType = 
+    Proto->isVariadic() ? VariadicConstructor : VariadicDoesNotApply;
+  llvm::SmallVector<Expr *, 8> AllArgs;
+  bool Invalid = GatherArgumentsForCall(Loc, Constructor,
+                                        Proto, 0, Args, NumArgs, AllArgs, 
+                                        CallType);
+  for (unsigned i =0, size = AllArgs.size(); i < size; i++)
+    ConvertedArgs.push_back(AllArgs[i]);
+  return Invalid;
 }
 
 /// CompareReferenceRelationship - Compare the two types T1 and T2 to
index 2a7758a677b5cd53273d7ce626ec5067256d6cfe..45a82b5c03fc03cf6e47a174f229312c8c92247d 100644 (file)
@@ -2627,7 +2627,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
   else if (isa<MemberExpr>(Fn))
     CallType = VariadicMethod;
   Invalid = GatherArgumentsForCall(Call->getSourceRange().getBegin(), FDecl,
-                                   Proto, 0, Args, NumArgs, AllArgs, Fn, CallType);
+                                   Proto, 0, Args, NumArgs, AllArgs, CallType);
   if (Invalid)
     return true;
   unsigned TotalNumArgs = AllArgs.size();
@@ -2643,7 +2643,6 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc,
                                   unsigned FirstProtoArg,
                                   Expr **Args, unsigned NumArgs,
                                   llvm::SmallVector<Expr *, 8> &AllArgs,
-                                  Expr *Fn,
                                   VariadicCallType CallType) {
   unsigned NumArgsInProto = Proto->getNumArgs();
   unsigned NumArgsToCheck = NumArgs;
index 4ad62f7311974979f61701b62e3ec8a49f6ff15f..40e5707028baaa83472ca2eaf8bf6003f06e884a 100644 (file)
@@ -411,7 +411,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
       Proto->isVariadic() ? VariadicFunction : VariadicDoesNotApply;
     bool Invalid = GatherArgumentsForCall(PlacementLParen, OperatorNew,
                                           Proto, 1, PlaceArgs, NumPlaceArgs, 
-                                          AllPlaceArgs, 0, CallType);
+                                          AllPlaceArgs, CallType);
     if (Invalid)
       return ExprError();