diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 056abd2059c65a3e908193aeae16fad98017437c (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /lib/AST/Expr.cpp | |
parent | cc73504950eb7b5dff2dded9bedd67bc36d64641 (diff) | |
download | FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'lib/AST/Expr.cpp')
-rw-r--r-- | lib/AST/Expr.cpp | 299 |
1 files changed, 202 insertions, 97 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 24361ef..f3a2e05 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -48,6 +48,75 @@ const CXXRecordDecl *Expr::getBestDynamicClassType() const { return cast<CXXRecordDecl>(D); } +const Expr * +Expr::skipRValueSubobjectAdjustments( + SmallVectorImpl<SubobjectAdjustment> &Adjustments) const { + const Expr *E = this; + while (true) { + E = E->IgnoreParens(); + + if (const CastExpr *CE = dyn_cast<CastExpr>(E)) { + if ((CE->getCastKind() == CK_DerivedToBase || + CE->getCastKind() == CK_UncheckedDerivedToBase) && + E->getType()->isRecordType()) { + E = CE->getSubExpr(); + CXXRecordDecl *Derived + = cast<CXXRecordDecl>(E->getType()->getAs<RecordType>()->getDecl()); + Adjustments.push_back(SubobjectAdjustment(CE, Derived)); + continue; + } + + if (CE->getCastKind() == CK_NoOp) { + E = CE->getSubExpr(); + continue; + } + } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { + if (!ME->isArrow() && ME->getBase()->isRValue()) { + assert(ME->getBase()->getType()->isRecordType()); + if (FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) { + E = ME->getBase(); + Adjustments.push_back(SubobjectAdjustment(Field)); + continue; + } + } + } else if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { + if (BO->isPtrMemOp()) { + assert(BO->getRHS()->isRValue()); + E = BO->getLHS(); + const MemberPointerType *MPT = + BO->getRHS()->getType()->getAs<MemberPointerType>(); + Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); + } + } + + // Nothing changed. + break; + } + return E; +} + +const Expr * +Expr::findMaterializedTemporary(const MaterializeTemporaryExpr *&MTE) const { + const Expr *E = this; + // Look through single-element init lists that claim to be lvalues. They're + // just syntactic wrappers in this case. + if (const InitListExpr *ILE = dyn_cast<InitListExpr>(E)) { + if (ILE->getNumInits() == 1 && ILE->isGLValue()) + E = ILE->getInit(0); + } + + // Look through expressions for materialized temporaries (for now). + if (const MaterializeTemporaryExpr *M + = dyn_cast<MaterializeTemporaryExpr>(E)) { + MTE = M; + E = M->GetTemporaryExpr(); + } + + if (const CXXDefaultArgExpr *DAE = dyn_cast<CXXDefaultArgExpr>(E)) + E = DAE->getExpr(); + return E; +} + /// isKnownToHaveBooleanValue - Return true if this is an integer expression /// that is known to return 0 or 1. This happens for _Bool/bool expressions /// but also int expressions which are produced by things like comparisons in @@ -784,19 +853,19 @@ void StringLiteral::setString(ASTContext &C, StringRef Str, switch(CharByteWidth) { case 1: { char *AStrData = new (C) char[Length]; - std::memcpy(AStrData,Str.data(),Str.size()); + std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asChar = AStrData; break; } case 2: { uint16_t *AStrData = new (C) uint16_t[Length]; - std::memcpy(AStrData,Str.data(),Str.size()); + std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asUInt16 = AStrData; break; } case 4: { uint32_t *AStrData = new (C) uint32_t[Length]; - std::memcpy(AStrData,Str.data(),Str.size()); + std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asUInt32 = AStrData; break; } @@ -869,7 +938,7 @@ getLocationOfByte(unsigned ByteNo, const SourceManager &SM, /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it /// corresponds to, e.g. "sizeof" or "[pre]++". -const char *UnaryOperator::getOpcodeStr(Opcode Op) { +StringRef UnaryOperator::getOpcodeStr(Opcode Op) { switch (Op) { case UO_PostInc: return "++"; case UO_PostDec: return "--"; @@ -923,18 +992,18 @@ OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { //===----------------------------------------------------------------------===// CallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, - Expr **args, unsigned numargs, QualType t, ExprValueKind VK, + ArrayRef<Expr*> args, QualType t, ExprValueKind VK, SourceLocation rparenloc) : Expr(SC, t, VK, OK_Ordinary, fn->isTypeDependent(), fn->isValueDependent(), fn->isInstantiationDependent(), fn->containsUnexpandedParameterPack()), - NumArgs(numargs) { + NumArgs(args.size()) { - SubExprs = new (C) Stmt*[numargs+PREARGS_START+NumPreArgs]; + SubExprs = new (C) Stmt*[args.size()+PREARGS_START+NumPreArgs]; SubExprs[FN] = fn; - for (unsigned i = 0; i != numargs; ++i) { + for (unsigned i = 0; i != args.size(); ++i) { if (args[i]->isTypeDependent()) ExprBits.TypeDependent = true; if (args[i]->isValueDependent()) @@ -951,18 +1020,18 @@ CallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, RParenLoc = rparenloc; } -CallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, +CallExpr::CallExpr(ASTContext& C, Expr *fn, ArrayRef<Expr*> args, QualType t, ExprValueKind VK, SourceLocation rparenloc) : Expr(CallExprClass, t, VK, OK_Ordinary, fn->isTypeDependent(), fn->isValueDependent(), fn->isInstantiationDependent(), fn->containsUnexpandedParameterPack()), - NumArgs(numargs) { + NumArgs(args.size()) { - SubExprs = new (C) Stmt*[numargs+PREARGS_START]; + SubExprs = new (C) Stmt*[args.size()+PREARGS_START]; SubExprs[FN] = fn; - for (unsigned i = 0; i != numargs; ++i) { + for (unsigned i = 0; i != args.size(); ++i) { if (args[i]->isTypeDependent()) ExprBits.TypeDependent = true; if (args[i]->isValueDependent()) @@ -1123,15 +1192,15 @@ SourceLocation CallExpr::getLocEnd() const { OffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, - OffsetOfNode* compsPtr, unsigned numComps, - Expr** exprsPtr, unsigned numExprs, + ArrayRef<OffsetOfNode> comps, + ArrayRef<Expr*> exprs, SourceLocation RParenLoc) { void *Mem = C.Allocate(sizeof(OffsetOfExpr) + - sizeof(OffsetOfNode) * numComps + - sizeof(Expr*) * numExprs); + sizeof(OffsetOfNode) * comps.size() + + sizeof(Expr*) * exprs.size()); - return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, - exprsPtr, numExprs, RParenLoc); + return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs, + RParenLoc); } OffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, @@ -1144,8 +1213,7 @@ OffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, OffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, - OffsetOfNode* compsPtr, unsigned numComps, - Expr** exprsPtr, unsigned numExprs, + ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, SourceLocation RParenLoc) : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, /*TypeDependent=*/false, @@ -1153,19 +1221,19 @@ OffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, tsi->getType()->isInstantiationDependentType(), tsi->getType()->containsUnexpandedParameterPack()), OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), - NumComps(numComps), NumExprs(numExprs) + NumComps(comps.size()), NumExprs(exprs.size()) { - for(unsigned i = 0; i < numComps; ++i) { - setComponent(i, compsPtr[i]); + for (unsigned i = 0; i != comps.size(); ++i) { + setComponent(i, comps[i]); } - for(unsigned i = 0; i < numExprs; ++i) { - if (exprsPtr[i]->isTypeDependent() || exprsPtr[i]->isValueDependent()) + for (unsigned i = 0; i != exprs.size(); ++i) { + if (exprs[i]->isTypeDependent() || exprs[i]->isValueDependent()) ExprBits.ValueDependent = true; - if (exprsPtr[i]->containsUnexpandedParameterPack()) + if (exprs[i]->containsUnexpandedParameterPack()) ExprBits.ContainsUnexpandedParameterPack = true; - setIndexExpr(i, exprsPtr[i]); + setIndexExpr(i, exprs[i]); } } @@ -1259,9 +1327,12 @@ SourceLocation MemberExpr::getLocStart() const { return MemberLoc; } SourceLocation MemberExpr::getLocEnd() const { + SourceLocation EndLoc = getMemberNameInfo().getEndLoc(); if (hasExplicitTemplateArgs()) - return getRAngleLoc(); - return getMemberNameInfo().getEndLoc(); + EndLoc = getRAngleLoc(); + else if (EndLoc.isInvalid()) + EndLoc = getBase()->getLocEnd(); + return EndLoc; } void CastExpr::CheckCastConsistency() const { @@ -1311,12 +1382,16 @@ void CastExpr::CheckCastConsistency() const { assert(getType()->isBlockPointerType()); assert(getSubExpr()->getType()->isBlockPointerType()); goto CheckNoBasePath; - + + case CK_FunctionToPointerDecay: + assert(getType()->isPointerType()); + assert(getSubExpr()->getType()->isFunctionType()); + goto CheckNoBasePath; + // These should not have an inheritance path. case CK_Dynamic: case CK_ToUnion: case CK_ArrayToPointerDecay: - case CK_FunctionToPointerDecay: case CK_NullToMemberPointer: case CK_NullToPointer: case CK_ConstructorConversion: @@ -1357,6 +1432,7 @@ void CastExpr::CheckCastConsistency() const { case CK_IntegralComplexToBoolean: case CK_LValueBitCast: // -> bool& case CK_UserDefinedConversion: // operator bool() + case CK_BuiltinFnToFnPtr: CheckNoBasePath: assert(path_empty() && "Cast kind should not have a base path!"); break; @@ -1469,6 +1545,8 @@ const char *CastExpr::getCastKindName() const { return "NonAtomicToAtomic"; case CK_CopyAndAutoreleaseBlockObject: return "CopyAndAutoreleaseBlockObject"; + case CK_BuiltinFnToFnPtr: + return "BuiltinFnToFnPtr"; } llvm_unreachable("Unhandled cast kind!"); @@ -1564,7 +1642,7 @@ CStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it /// corresponds to, e.g. "<<=". -const char *BinaryOperator::getOpcodeStr(Opcode Op) { +StringRef BinaryOperator::getOpcodeStr(Opcode Op) { switch (Op) { case BO_PtrMemD: return ".*"; case BO_PtrMemI: return "->*"; @@ -1666,16 +1744,15 @@ OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { } InitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, - Expr **initExprs, unsigned numInits, - SourceLocation rbraceloc) + ArrayRef<Expr*> initExprs, SourceLocation rbraceloc) : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, false, false), - InitExprs(C, numInits), - LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0) + InitExprs(C, initExprs.size()), + LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(0, true) { sawArrayRangeDesignator(false); setInitializesStdInitializerList(false); - for (unsigned I = 0; I != numInits; ++I) { + for (unsigned I = 0; I != initExprs.size(); ++I) { if (initExprs[I]->isTypeDependent()) ExprBits.TypeDependent = true; if (initExprs[I]->isValueDependent()) @@ -1686,7 +1763,7 @@ InitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, ExprBits.ContainsUnexpandedParameterPack = true; } - InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); + InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); } void InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { @@ -1723,15 +1800,15 @@ void InitListExpr::setArrayFiller(Expr *filler) { bool InitListExpr::isStringLiteralInit() const { if (getNumInits() != 1) return false; - const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(getType()); - if (!CAT || !CAT->getElementType()->isIntegerType()) + const ArrayType *AT = getType()->getAsArrayTypeUnsafe(); + if (!AT || !AT->getElementType()->isIntegerType()) return false; - const Expr *Init = getInit(0)->IgnoreParenImpCasts(); + const Expr *Init = getInit(0)->IgnoreParens(); return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); } SourceRange InitListExpr::getSourceRange() const { - if (SyntacticForm) + if (InitListExpr *SyntacticForm = getSyntacticForm()) return SyntacticForm->getSourceRange(); SourceLocation Beg = LBraceLoc, End = RBraceLoc; if (Beg.isInvalid()) { @@ -1945,6 +2022,11 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, return false; } + // If we don't know precisely what we're looking at, let's not warn. + case UnresolvedLookupExprClass: + case CXXUnresolvedConstructExprClass: + return false; + case CXXTemporaryObjectExprClass: case CXXConstructExprClass: return false; @@ -2014,6 +2096,7 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, R1 = getSourceRange(); return true; } + case CXXFunctionalCastExprClass: case CStyleCastExprClass: { // Ignore an explicit cast to void unless the operand is a non-trivial // volatile lvalue. @@ -2032,6 +2115,10 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, return false; } + // Ignore casts within macro expansions. + if (getExprLoc().isMacroID()) + return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); + // If this is a cast to a constructor conversion, check the operand. // Otherwise, the result of the cast is unused. if (CE->getCastKind() == CK_ConstructorConversion) @@ -2641,6 +2728,7 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const { case UnresolvedMemberExprClass: case PackExpansionExprClass: case SubstNonTypeTemplateParmPackExprClass: + case FunctionParmPackExprClass: llvm_unreachable("shouldn't see dependent / unresolved nodes here"); case DeclRefExprClass: @@ -2995,6 +3083,24 @@ const ObjCPropertyRefExpr *Expr::getObjCProperty() const { return cast<ObjCPropertyRefExpr>(E); } +bool Expr::isObjCSelfExpr() const { + const Expr *E = IgnoreParenImpCasts(); + + const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E); + if (!DRE) + return false; + + const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl()); + if (!Param) + return false; + + const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext()); + if (!M) + return false; + + return M->getSelfDecl() == Param; +} + FieldDecl *Expr::getBitField() { Expr *E = this->IgnoreParens(); @@ -3339,33 +3445,29 @@ Selector ObjCMessageExpr::getSelector() const { return Selector(SelectorOrMethod); } -ObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { +QualType ObjCMessageExpr::getReceiverType() const { switch (getReceiverKind()) { case Instance: - if (const ObjCObjectPointerType *Ptr - = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) - return Ptr->getInterfaceDecl(); - break; - + return getInstanceReceiver()->getType(); case Class: - if (const ObjCObjectType *Ty - = getClassReceiver()->getAs<ObjCObjectType>()) - return Ty->getInterface(); - break; - + return getClassReceiver(); case SuperInstance: - if (const ObjCObjectPointerType *Ptr - = getSuperType()->getAs<ObjCObjectPointerType>()) - return Ptr->getInterfaceDecl(); - break; - case SuperClass: - if (const ObjCObjectType *Iface - = getSuperType()->getAs<ObjCObjectType>()) - return Iface->getInterface(); - break; + return getSuperType(); } + llvm_unreachable("unexpected receiver kind"); +} + +ObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { + QualType T = getReceiverType(); + + if (const ObjCObjectPointerType *Ptr = T->getAs<ObjCObjectPointerType>()) + return Ptr->getInterfaceDecl(); + + if (const ObjCObjectType *Ty = T->getAs<ObjCObjectType>()) + return Ty->getInterface(); + return 0; } @@ -3386,17 +3488,17 @@ bool ChooseExpr::isConditionTrue(const ASTContext &C) const { return getCond()->EvaluateKnownConstInt(C) != 0; } -ShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, +ShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, ArrayRef<Expr*> args, QualType Type, SourceLocation BLoc, SourceLocation RP) : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, Type->isDependentType(), Type->isDependentType(), Type->isInstantiationDependentType(), Type->containsUnexpandedParameterPack()), - BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) + BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) { - SubExprs = new (C) Stmt*[nexpr]; - for (unsigned i = 0; i < nexpr; i++) { + SubExprs = new (C) Stmt*[args.size()]; + for (unsigned i = 0; i != args.size(); i++) { if (args[i]->isTypeDependent()) ExprBits.TypeDependent = true; if (args[i]->isValueDependent()) @@ -3421,8 +3523,9 @@ void ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, - TypeSourceInfo **AssocTypes, Expr **AssocExprs, - unsigned NumAssocs, SourceLocation DefaultLoc, + ArrayRef<TypeSourceInfo*> AssocTypes, + ArrayRef<Expr*> AssocExprs, + SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex) @@ -3434,19 +3537,21 @@ GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, AssocExprs[ResultIndex]->isValueDependent(), AssocExprs[ResultIndex]->isInstantiationDependent(), ContainsUnexpandedParameterPack), - AssocTypes(new (Context) TypeSourceInfo*[NumAssocs]), - SubExprs(new (Context) Stmt*[END_EXPR+NumAssocs]), NumAssocs(NumAssocs), - ResultIndex(ResultIndex), GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), - RParenLoc(RParenLoc) { + AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), + SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), + NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex), + GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { SubExprs[CONTROLLING] = ControllingExpr; - std::copy(AssocTypes, AssocTypes+NumAssocs, this->AssocTypes); - std::copy(AssocExprs, AssocExprs+NumAssocs, SubExprs+END_EXPR); + assert(AssocTypes.size() == AssocExprs.size()); + std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); + std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); } GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, - TypeSourceInfo **AssocTypes, Expr **AssocExprs, - unsigned NumAssocs, SourceLocation DefaultLoc, + ArrayRef<TypeSourceInfo*> AssocTypes, + ArrayRef<Expr*> AssocExprs, + SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack) : Expr(GenericSelectionExprClass, @@ -3457,13 +3562,14 @@ GenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, /*isValueDependent=*/true, /*isInstantiationDependent=*/true, ContainsUnexpandedParameterPack), - AssocTypes(new (Context) TypeSourceInfo*[NumAssocs]), - SubExprs(new (Context) Stmt*[END_EXPR+NumAssocs]), NumAssocs(NumAssocs), - ResultIndex(-1U), GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), - RParenLoc(RParenLoc) { + AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), + SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), + NumAssocs(AssocExprs.size()), ResultIndex(-1U), GenericLoc(GenericLoc), + DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { SubExprs[CONTROLLING] = ControllingExpr; - std::copy(AssocTypes, AssocTypes+NumAssocs, this->AssocTypes); - std::copy(AssocExprs, AssocExprs+NumAssocs, SubExprs+END_EXPR); + assert(AssocTypes.size() == AssocExprs.size()); + std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); + std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); } //===----------------------------------------------------------------------===// @@ -3483,8 +3589,7 @@ DesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, const Designator *Designators, SourceLocation EqualOrColonLoc, bool GNUSyntax, - Expr **IndexExprs, - unsigned NumIndexExprs, + ArrayRef<Expr*> IndexExprs, Expr *Init) : Expr(DesignatedInitExprClass, Ty, Init->getValueKind(), Init->getObjectKind(), @@ -3492,7 +3597,7 @@ DesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, Init->isInstantiationDependent(), Init->containsUnexpandedParameterPack()), EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), - NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { + NumDesignators(NumDesignators), NumSubExprs(IndexExprs.size() + 1) { this->Designators = new (C) Designator[NumDesignators]; // Record the initializer itself. @@ -3542,20 +3647,20 @@ DesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, } } - assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); + assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions"); } DesignatedInitExpr * DesignatedInitExpr::Create(ASTContext &C, Designator *Designators, unsigned NumDesignators, - Expr **IndexExprs, unsigned NumIndexExprs, + ArrayRef<Expr*> IndexExprs, SourceLocation ColonOrEqualLoc, bool UsesColonSyntax, Expr *Init) { void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + - sizeof(Stmt *) * (NumIndexExprs + 1), 8); + sizeof(Stmt *) * (IndexExprs.size() + 1), 8); return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, ColonOrEqualLoc, UsesColonSyntax, - IndexExprs, NumIndexExprs, Init); + IndexExprs, Init); } DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, @@ -3651,13 +3756,13 @@ void DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, } ParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, - Expr **exprs, unsigned nexprs, + ArrayRef<Expr*> exprs, SourceLocation rparenloc) : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, false, false), - NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { - Exprs = new (C) Stmt*[nexprs]; - for (unsigned i = 0; i != nexprs; ++i) { + NumExprs(exprs.size()), LParenLoc(lparenloc), RParenLoc(rparenloc) { + Exprs = new (C) Stmt*[exprs.size()]; + for (unsigned i = 0; i != exprs.size(); ++i) { if (exprs[i]->isTypeDependent()) ExprBits.TypeDependent = true; if (exprs[i]->isValueDependent()) @@ -3902,14 +4007,14 @@ ObjCSubscriptRefExpr *ObjCSubscriptRefExpr::Create(ASTContext &C, getMethod, setMethod, RB); } -AtomicExpr::AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, +AtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, QualType t, AtomicOp op, SourceLocation RP) : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, false, false, false, false), - NumSubExprs(nexpr), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) + NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) { - assert(nexpr == getNumSubExprs(op) && "wrong number of subexpressions"); - for (unsigned i = 0; i < nexpr; i++) { + assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions"); + for (unsigned i = 0; i != args.size(); i++) { if (args[i]->isTypeDependent()) ExprBits.TypeDependent = true; if (args[i]->isValueDependent()) |