[cfe-commits] r78132 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/AST/ExprCXX.cpp lib/Sema/SemaDeclCXX.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Aug 4 17:26:11 PDT 2009
Author: fjahanian
Date: Tue Aug 4 19:26:10 2009
New Revision: 78132
URL: http://llvm.org/viewvc/llvm-project?rev=78132&view=rev
Log:
Support for use of default argument in constructors.
work in progress.
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=78132&r1=78131&r2=78132&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Aug 4 19:26:10 2009
@@ -511,6 +511,12 @@
unsigned getNumArgs() const { return NumArgs; }
+ /// setArg - Set the specified argument.
+ void setArg(unsigned Arg, Expr *ArgExpr) {
+ assert(Arg < NumArgs && "Arg access out of range!");
+ Args[Arg] = ArgExpr;
+ }
+
virtual SourceRange getSourceRange() const { return SourceRange(); }
static bool classof(const Stmt *T) {
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=78132&r1=78131&r2=78132&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Tue Aug 4 19:26:10 2009
@@ -395,9 +395,13 @@
(T->isDependentType() ||
CallExpr::hasAnyValueDependentArguments(args, numargs))),
Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) {
+ // leave room for default arguments;
+ FunctionDecl *FDecl = cast<FunctionDecl>(D);
+ unsigned NumArgsInProto = FDecl->param_size();
+ NumArgs += (NumArgsInProto - numargs);
if (NumArgs > 0) {
Args = new (C) Stmt*[NumArgs];
- for (unsigned i = 0; i < NumArgs; ++i)
+ for (unsigned i = 0; i < numargs; ++i)
Args[i] = args[i];
}
}
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=78132&r1=78131&r2=78132&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Aug 4 19:26:10 2009
@@ -2360,8 +2360,29 @@
CXXConstructorDecl *Constructor,
QualType DeclInitType,
Expr **Exprs, unsigned NumExprs) {
- Expr *Temp = CXXConstructExpr::Create(Context, DeclInitType, Constructor,
- false, Exprs, NumExprs);
+ CXXConstructExpr *Temp = CXXConstructExpr::Create(Context, DeclInitType,
+ Constructor,
+ false, Exprs, NumExprs);
+ // default arguments must be added to constructor call expression.
+ FunctionDecl *FDecl = cast<FunctionDecl>(Constructor);
+ unsigned NumArgsInProto = FDecl->param_size();
+ for (unsigned j = NumExprs; j != NumArgsInProto; j++) {
+ Expr *DefaultExpr = FDecl->getParamDecl(j)->getDefaultArg();
+
+ // If the default expression creates temporaries, we need to
+ // push them to the current stack of expression temporaries so they'll
+ // be properly destroyed.
+ if (CXXExprWithTemporaries *E
+ = dyn_cast_or_null<CXXExprWithTemporaries>(DefaultExpr)) {
+ assert(!E->shouldDestroyTemporaries() &&
+ "Can't destroy temporaries in a default argument expr!");
+ for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I)
+ ExprTemporaries.push_back(E->getTemporary(I));
+ }
+ Expr *Arg = new (Context) CXXDefaultArgExpr(FDecl->getParamDecl(j));
+ Temp->setArg(j, Arg);
+ }
+
MarkDeclarationReferenced(VD->getLocation(), Constructor);
VD->setInit(Context, Temp);
}
More information about the cfe-commits
mailing list