[cfe-commits] r79970 - in /cfe/trunk/lib/Sema: Sema.h SemaDeclCXX.cpp SemaExpr.cpp

Anders Carlsson andersca at mac.com
Mon Aug 24 19:29:20 PDT 2009


Author: andersca
Date: Mon Aug 24 21:29:20 2009
New Revision: 79970

URL: http://llvm.org/viewvc/llvm-project?rev=79970&view=rev
Log:
Factor setting default arguments out into SetParamDefaultArgument.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=79970&r1=79969&r2=79970&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Aug 24 21:29:20 2009
@@ -542,6 +542,9 @@
                                                  SourceLocation EqualLoc,
                                                  SourceLocation ArgLoc);
   virtual void ActOnParamDefaultArgumentError(DeclPtrTy param);
+  bool SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg,
+                               SourceLocation EqualLoc);
+
   
   // Contains the locations of the beginning of unparsed default
   // argument locations.

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=79970&r1=79969&r2=79970&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Aug 24 21:29:20 2009
@@ -101,6 +101,34 @@
   }
 }
 
+bool
+Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg,
+                              SourceLocation EqualLoc)
+{
+  QualType ParamType = Param->getType();
+
+  Expr *Arg = (Expr *)DefaultArg.get();
+  
+  // C++ [dcl.fct.default]p5
+  //   A default argument expression is implicitly converted (clause
+  //   4) to the parameter type. The default argument expression has
+  //   the same semantic constraints as the initializer expression in
+  //   a declaration of a variable of the parameter type, using the
+  //   copy-initialization semantics (8.5).
+  if (CheckInitializerTypes(Arg, ParamType, EqualLoc, 
+                            Param->getDeclName(), /*DirectInit=*/false))
+    return false;
+
+  Arg = MaybeCreateCXXExprWithTemporaries(Arg, /*DestroyTemps=*/false);
+  
+  // Okay: add the default argument to the parameter
+  Param->setDefaultArg(Arg);
+  
+  DefaultArg.release();
+  
+  return true;
+}
+
 /// ActOnParamDefaultArgument - Check whether the default argument
 /// provided for a function parameter is well-formed. If so, attach it
 /// to the parameter declaration.
@@ -131,30 +159,7 @@
     return;
   }
   
-  // C++ [dcl.fct.default]p5
-  //   A default argument expression is implicitly converted (clause
-  //   4) to the parameter type. The default argument expression has
-  //   the same semantic constraints as the initializer expression in
-  //   a declaration of a variable of the parameter type, using the
-  //   copy-initialization semantics (8.5).
-  Expr *DefaultArgPtr = DefaultArg.get();
-  bool DefaultInitFailed = CheckInitializerTypes(DefaultArgPtr, ParamType,
-                                                 EqualLoc,
-                                                 Param->getDeclName(),
-                                                 /*DirectInit=*/false);
-  if (DefaultArgPtr != DefaultArg.get()) {
-    DefaultArg.take();
-    DefaultArg.reset(DefaultArgPtr);
-  }
-  if (DefaultInitFailed) {
-    return;
-  }
-
-  DefaultArgPtr = MaybeCreateCXXExprWithTemporaries(DefaultArg.take(),
-                                                    /*DestroyTemps=*/false);
-  
-  // Okay: add the default argument to the parameter
-  Param->setDefaultArg(DefaultArgPtr);
+  SetParamDefaultArgument(Param, move(DefaultArg), EqualLoc);
 }
 
 /// ActOnParamUnparsedDefaultArgument - We've seen a default

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=79970&r1=79969&r2=79970&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Aug 24 21:29:20 2009
@@ -2492,14 +2492,15 @@
       if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
         return true;
     } else {
-      if (FDecl->getParamDecl(i)->hasUnparsedDefaultArg()) {
+      ParmVarDecl *Param = FDecl->getParamDecl(i);
+      if (Param->hasUnparsedDefaultArg()) {
         Diag (Call->getSourceRange().getBegin(),
               diag::err_use_of_default_argument_to_function_declared_later) <<
         FDecl << cast<CXXRecordDecl>(FDecl->getDeclContext())->getDeclName();
-        Diag(UnparsedDefaultArgLocs[FDecl->getParamDecl(i)], 
+        Diag(UnparsedDefaultArgLocs[Param], 
               diag::note_default_argument_declared_here);
       } else {
-        Expr *DefaultExpr = FDecl->getParamDecl(i)->getDefaultArg();
+        Expr *DefaultExpr = Param->getDefaultArg();
         
         // If the default expression creates temporaries, we need to
         // push them to the current stack of expression temporaries so they'll
@@ -2514,7 +2515,7 @@
       }
   
       // We already type-checked the argument, so we know it works.
-      Arg = CXXDefaultArgExpr::Create(Context, FDecl->getParamDecl(i));
+      Arg = CXXDefaultArgExpr::Create(Context, Param);
     }
     
     QualType ArgType = Arg->getType();





More information about the cfe-commits mailing list