diff options
Diffstat (limited to 'lib/AST/ExprCXX.cpp')
-rw-r--r-- | lib/AST/ExprCXX.cpp | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index e09d88091b..718010b81e 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -45,30 +45,26 @@ SourceRange CXXScalarValueInitExpr::getSourceRange() const { // CXXNewExpr CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, - Expr **placementArgs, unsigned numPlaceArgs, - SourceRange TypeIdParens, Expr *arraySize, - CXXConstructorDecl *constructor, bool initializer, - Expr **constructorArgs, unsigned numConsArgs, - bool HadMultipleCandidates, FunctionDecl *operatorDelete, - bool usualArrayDeleteWantsSize, QualType ty, - TypeSourceInfo *AllocatedTypeInfo, - SourceLocation startLoc, SourceLocation endLoc, - SourceLocation constructorLParen, - SourceLocation constructorRParen) + bool usualArrayDeleteWantsSize, + Expr **placementArgs, unsigned numPlaceArgs, + SourceRange typeIdParens, Expr *arraySize, + InitializationStyle initializationStyle, + Expr *initializer, QualType ty, + TypeSourceInfo *allocatedTypeInfo, + SourceLocation startLoc, SourceRange directInitRange) : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, ty->isDependentType(), ty->isDependentType(), ty->isInstantiationDependentType(), ty->containsUnexpandedParameterPack()), - GlobalNew(globalNew), Initializer(initializer), - UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize), - HadMultipleCandidates(HadMultipleCandidates), - SubExprs(0), OperatorNew(operatorNew), - OperatorDelete(operatorDelete), Constructor(constructor), - AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens), - StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen), - ConstructorRParen(constructorRParen) { - AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs); + GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize), + SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete), + AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens), + StartLoc(startLoc), DirectInitRange(directInitRange) { + assert((initializer != 0 || initializationStyle == NoInit) && + "Only NoInit can have no initializer."); + StoredInitializationStyle = initializer ? initializationStyle + 1 : 0; + AllocateArgsArray(C, arraySize != 0, numPlaceArgs, initializer != 0); unsigned i = 0; if (Array) { if (arraySize->isInstantiationDependent()) @@ -80,33 +76,33 @@ CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, SubExprs[i++] = arraySize; } - for (unsigned j = 0; j < NumPlacementArgs; ++j) { - if (placementArgs[j]->isInstantiationDependent()) + if (initializer) { + if (initializer->isInstantiationDependent()) ExprBits.InstantiationDependent = true; - if (placementArgs[j]->containsUnexpandedParameterPack()) + + if (initializer->containsUnexpandedParameterPack()) ExprBits.ContainsUnexpandedParameterPack = true; - SubExprs[i++] = placementArgs[j]; + SubExprs[i++] = initializer; } - for (unsigned j = 0; j < NumConstructorArgs; ++j) { - if (constructorArgs[j]->isInstantiationDependent()) + for (unsigned j = 0; j < NumPlacementArgs; ++j) { + if (placementArgs[j]->isInstantiationDependent()) ExprBits.InstantiationDependent = true; - if (constructorArgs[j]->containsUnexpandedParameterPack()) + if (placementArgs[j]->containsUnexpandedParameterPack()) ExprBits.ContainsUnexpandedParameterPack = true; - SubExprs[i++] = constructorArgs[j]; + SubExprs[i++] = placementArgs[j]; } } void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray, - unsigned numPlaceArgs, unsigned numConsArgs){ + unsigned numPlaceArgs, bool hasInitializer){ assert(SubExprs == 0 && "SubExprs already allocated"); Array = isArray; NumPlacementArgs = numPlaceArgs; - NumConstructorArgs = numConsArgs; - - unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs; + + unsigned TotalSize = Array + hasInitializer + NumPlacementArgs; SubExprs = new (C) Stmt*[TotalSize]; } @@ -115,6 +111,17 @@ bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const { castAs<FunctionProtoType>()->isNothrow(Ctx); } +SourceLocation CXXNewExpr::getEndLoc() const { + switch (getInitializationStyle()) { + case NoInit: + return AllocatedTypeInfo->getTypeLoc().getEndLoc(); + case CallInit: + return DirectInitRange.getEnd(); + case ListInit: + return getInitializer()->getSourceRange().getEnd(); + } +} + // CXXDeleteExpr QualType CXXDeleteExpr::getDestroyedType() const { const Expr *Arg = getArgument(); |