Clean up the CXXConstructExpr constructor, add Arg getters.

llvm-svn: 81178
This commit is contained in:
Anders Carlsson 2009-09-08 01:23:37 +00:00
parent 4ad0b4c544
commit 6d5de59d09
2 changed files with 24 additions and 7 deletions

View File

@ -517,6 +517,16 @@ public:
unsigned getNumArgs() const { return NumArgs; }
/// getArg - Return the specified argument.
Expr *getArg(unsigned Arg) {
assert(Arg < NumArgs && "Arg access out of range!");
return cast<Expr>(Args[Arg]);
}
const Expr *getArg(unsigned Arg) const {
assert(Arg < NumArgs && "Arg access out of range!");
return cast<Expr>(Args[Arg]);
}
/// setArg - Set the specified argument.
void setArg(unsigned Arg, Expr *ArgExpr) {
assert(Arg < NumArgs && "Arg access out of range!");

View File

@ -396,15 +396,22 @@ CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
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)
const FunctionProtoType *FTy =
cast<FunctionDecl>(D)->getType()->getAsFunctionProtoType();
unsigned NumArgsInProto = FTy->getNumArgs();
unsigned NumArgsToAllocate = FTy->isVariadic() ? NumArgs : NumArgsInProto;
if (NumArgsToAllocate) {
Args = new (C) Stmt*[NumArgsToAllocate];
for (unsigned i = 0; i != NumArgs; ++i)
Args[i] = args[i];
for (unsigned i = numargs; i < NumArgs; ++i)
// Set default arguments to 0.
for (unsigned i = NumArgs; i != NumArgsToAllocate; ++i)
Args[i] = 0;
NumArgs = NumArgsToAllocate;
}
}