Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -1,4 +1,4 @@ -//===--- Expr.cpp - Expression AST Node Implementation --------------------===// +//===--- Expr.cpp - Expression AST Node Implementation ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -34,6 +34,7 @@ #include "llvm/Support/raw_ostream.h" #include #include + using namespace clang; const CXXRecordDecl *Expr::getBestDynamicClassType() const { @@ -46,7 +47,7 @@ if (DerivedType->isDependentType()) return nullptr; - const RecordType *Ty = DerivedType->castAs(); + const auto *Ty = DerivedType->castAs(); Decl *D = Ty->getDecl(); return cast(D); } @@ -58,12 +59,12 @@ while (true) { E = E->IgnoreParens(); - if (const CastExpr *CE = dyn_cast(E)) { + if (const auto *CE = dyn_cast(E)) { if ((CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_UncheckedDerivedToBase) && E->getType()->isRecordType()) { E = CE->getSubExpr(); - CXXRecordDecl *Derived + auto *Derived = cast(E->getType()->getAs()->getDecl()); Adjustments.push_back(SubobjectAdjustment(CE, Derived)); continue; @@ -73,7 +74,7 @@ E = CE->getSubExpr(); continue; } - } else if (const MemberExpr *ME = dyn_cast(E)) { + } else if (const auto *ME = dyn_cast(E)) { if (!ME->isArrow()) { assert(ME->getBase()->getType()->isRecordType()); if (FieldDecl *Field = dyn_cast(ME->getMemberDecl())) { @@ -84,7 +85,7 @@ } } } - } else if (const BinaryOperator *BO = dyn_cast(E)) { + } else if (const auto *BO = dyn_cast(E)) { if (BO->isPtrMemOp()) { assert(BO->getRHS()->isRValue()); E = BO->getLHS(); @@ -117,7 +118,7 @@ // If this is a non-scalar-integer type, we don't care enough to try. if (!E->getType()->isIntegralOrEnumerationType()) return false; - if (const UnaryOperator *UO = dyn_cast(E)) { + if (const auto *UO = dyn_cast(E)) { switch (UO->getOpcode()) { case UO_Plus: return UO->getSubExpr()->isKnownToHaveBooleanValue(); @@ -130,10 +131,10 @@ // Only look through implicit casts. If the user writes // '(int) (a && b)' treat it as an arbitrary int. - if (const ImplicitCastExpr *CE = dyn_cast(E)) + if (const auto *CE = dyn_cast(E)) return CE->getSubExpr()->isKnownToHaveBooleanValue(); - if (const BinaryOperator *BO = dyn_cast(E)) { + if (const auto *BO = dyn_cast(E)) { switch (BO->getOpcode()) { default: return false; case BO_LT: // Relational operators. @@ -159,7 +160,7 @@ } } - if (const ConditionalOperator *CO = dyn_cast(E)) + if (const auto *CO = dyn_cast(E)) return CO->getTrueExpr()->isKnownToHaveBooleanValue() && CO->getFalseExpr()->isKnownToHaveBooleanValue(); @@ -188,7 +189,7 @@ SourceLocation (Expr::*v)() const) { return static_cast(expr)->getLocStart(); } -} +} // anonymous namespace SourceLocation Expr::getExprLoc() const { switch (getStmtClass()) { @@ -266,7 +267,7 @@ // (VD) - FIXME: Missing from the standard: // - an entity with reference type and is initialized with an // expression that is value-dependent [C++11] - if (VarDecl *Var = dyn_cast(D)) { + if (const auto *Var = dyn_cast(D)) { if ((Ctx.getLangOpts().CPlusPlus11 ? Var->getType()->isLiteralType(Ctx) : Var->getType()->isIntegralOrEnumerationType()) && @@ -484,16 +485,16 @@ ASTContext &Context = CurrentDecl->getASTContext(); if (IT == PredefinedExpr::FuncDName) { - if (const NamedDecl *ND = dyn_cast(CurrentDecl)) { + if (const auto *ND = dyn_cast(CurrentDecl)) { std::unique_ptr MC; MC.reset(Context.createMangleContext()); if (MC->shouldMangleDeclName(ND)) { SmallString<256> Buffer; llvm::raw_svector_ostream Out(Buffer); - if (const CXXConstructorDecl *CD = dyn_cast(ND)) + if (const auto *CD = dyn_cast(ND)) MC->mangleCXXCtor(CD, Ctor_Base, Out); - else if (const CXXDestructorDecl *DD = dyn_cast(ND)) + else if (const auto *DD = dyn_cast(ND)) MC->mangleCXXDtor(DD, Dtor_Base, Out); else MC->mangleName(ND, Out); @@ -522,14 +523,14 @@ MC->mangleBlock(DC, BD, Out); return Out.str(); } - if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) { + if (const auto *FD = dyn_cast(CurrentDecl)) { if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual && IT != FuncSig) return FD->getNameAsString(); SmallString<256> Name; llvm::raw_svector_ostream Out(Name); - if (const CXXMethodDecl *MD = dyn_cast(FD)) { + if (const auto *MD = dyn_cast(FD)) { if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) Out << "virtual "; if (MD->isStatic()) @@ -576,8 +577,8 @@ } POut << ")"; - if (const CXXMethodDecl *MD = dyn_cast(FD)) { - const FunctionType *FT = MD->getType()->castAs(); + if (const auto *MD = dyn_cast(FD)) { + const auto *FT = MD->getType()->castAs(); if (FT->isConst()) POut << " const"; if (FT->isVolatile()) @@ -593,8 +594,7 @@ SpecsTy Specs; const DeclContext *Ctx = FD->getDeclContext(); while (Ctx && isa(Ctx)) { - const ClassTemplateSpecializationDecl *Spec - = dyn_cast(Ctx); + const auto *Spec = dyn_cast(Ctx); if (Spec && !Spec->isExplicitSpecialization()) Specs.push_back(Spec); Ctx = Ctx->getParent(); @@ -661,7 +661,7 @@ return Name.str().str(); } - if (const CapturedDecl *CD = dyn_cast(CurrentDecl)) { + if (const auto *CD = dyn_cast(CurrentDecl)) { for (const DeclContext *DC = CD->getParent(); DC; DC = DC->getParent()) // Skip to its enclosing function or method, but not its enclosing // CapturedDecl. @@ -671,7 +671,7 @@ } llvm_unreachable("CapturedDecl not inside a function or method"); } - if (const ObjCMethodDecl *MD = dyn_cast(CurrentDecl)) { + if (const auto *MD = dyn_cast(CurrentDecl)) { SmallString<256> Name; llvm::raw_svector_ostream Out(Name); Out << (MD->isInstanceMethod() ? '-' : '+'); @@ -682,8 +682,7 @@ if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) Out << *ID; - if (const ObjCCategoryImplDecl *CID = - dyn_cast(MD->getDeclContext())) + if (const auto *CID = dyn_cast(MD->getDeclContext())) Out << '(' << *CID << ')'; Out << ' '; @@ -846,7 +845,7 @@ void *Mem = C.Allocate(sizeof(StringLiteral)+ sizeof(SourceLocation)*(NumStrs-1), llvm::alignOf()); - StringLiteral *SL = new (Mem) StringLiteral(Ty); + auto *SL = new (Mem) StringLiteral(Ty); // OPTIMIZE: could allocate this appended to the StringLiteral. SL->setString(C,Str,Kind,Pascal); @@ -864,7 +863,7 @@ void *Mem = C.Allocate(sizeof(StringLiteral)+ sizeof(SourceLocation)*(NumStrs-1), llvm::alignOf()); - StringLiteral *SL = new (Mem) StringLiteral(QualType()); + auto *SL = new (Mem) StringLiteral(QualType()); SL->CharByteWidth = 0; SL->Length = 0; SL->NumConcatenated = NumStrs; @@ -978,19 +977,19 @@ switch(CharByteWidth) { case 1: { - char *AStrData = new (C) char[Length]; + auto *AStrData = new (C) char[Length]; std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asChar = AStrData; break; } case 2: { - uint16_t *AStrData = new (C) uint16_t[Length]; + auto *AStrData = new (C) uint16_t[Length]; std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asUInt16 = AStrData; break; } case 4: { - uint32_t *AStrData = new (C) uint32_t[Length]; + auto *AStrData = new (C) uint32_t[Length]; std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asUInt32 = AStrData; break; @@ -1060,8 +1059,6 @@ } } - - /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it /// corresponds to, e.g. "sizeof" or "[pre]++". StringRef UnaryOperator::getOpcodeStr(Opcode Op) { @@ -1115,7 +1112,6 @@ } } - //===----------------------------------------------------------------------===// // Postfix Operators. //===----------------------------------------------------------------------===// @@ -1168,22 +1164,21 @@ Decl *CallExpr::getCalleeDecl() { Expr *CEE = getCallee()->IgnoreParenImpCasts(); - while (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(CEE)) { + while (auto *NTTP = dyn_cast(CEE)) { CEE = NTTP->getReplacement()->IgnoreParenCasts(); } // If we're calling a dereference, look at the pointer instead. - if (BinaryOperator *BO = dyn_cast(CEE)) { + if (auto *BO = dyn_cast(CEE)) { if (BO->isPtrMemOp()) CEE = BO->getRHS()->IgnoreParenCasts(); - } else if (UnaryOperator *UO = dyn_cast(CEE)) { + } else if (auto *UO = dyn_cast(CEE)) { if (UO->getOpcode() == UO_Deref) CEE = UO->getSubExpr()->IgnoreParenCasts(); } - if (DeclRefExpr *DRE = dyn_cast(CEE)) + if (auto *DRE = dyn_cast(CEE)) return DRE->getDecl(); - if (MemberExpr *ME = dyn_cast(CEE)) + if (auto *ME = dyn_cast(CEE)) return ME->getMemberDecl(); return nullptr; @@ -1208,7 +1203,7 @@ // Otherwise, we are growing the # arguments. New an bigger argument array. unsigned NumPreArgs = getNumPreArgs(); - Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; + auto **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; // Copy over args. for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) NewSubExprs[i] = SubExprs[i]; @@ -1228,15 +1223,15 @@ // All simple function calls (e.g. func()) are implicitly cast to pointer to // function. As a result, we try and obtain the DeclRefExpr from the // ImplicitCastExpr. - const ImplicitCastExpr *ICE = dyn_cast(getCallee()); + const auto *ICE = dyn_cast(getCallee()); if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). return 0; - const DeclRefExpr *DRE = dyn_cast(ICE->getSubExpr()); + const auto *DRE = dyn_cast(ICE->getSubExpr()); if (!DRE) return 0; - const FunctionDecl *FDecl = dyn_cast(DRE->getDecl()); + const auto *FDecl = dyn_cast(DRE->getDecl()); if (!FDecl) return 0; @@ -1267,7 +1262,7 @@ CalleeType = Expr::findBoundMemberType(Callee); } - const FunctionType *FnType = CalleeType->castAs(); + const auto *FnType = CalleeType->castAs(); return FnType->getReturnType(); } @@ -1404,7 +1399,7 @@ Size += ASTTemplateKWAndArgsInfo::sizeFor(0); void *Mem = C.Allocate(Size, llvm::alignOf()); - MemberExpr *E = new (Mem) + auto *E = new (Mem) MemberExpr(base, isarrow, OperatorLoc, memberdecl, nameinfo, ty, vk, ok); if (hasQualOrFound) { @@ -1702,12 +1697,11 @@ SubExpr = E->getSubExpr(); // Skip through reference binding to temporary. - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(SubExpr)) + if (auto *Materialize = dyn_cast(SubExpr)) SubExpr = Materialize->GetTemporaryExpr(); // Skip any temporary bindings; they're implicit. - if (CXXBindTemporaryExpr *Binder = dyn_cast(SubExpr)) + if (auto *Binder = dyn_cast(SubExpr)) SubExpr = Binder->getSubExpr(); // Conversions by constructor and conversion functions have a @@ -1749,8 +1743,7 @@ unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); - ImplicitCastExpr *E = - new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); + auto *E = new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); if (PathSize) E->setCastPath(*BasePath); return E; } @@ -1762,7 +1755,6 @@ return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); } - CStyleCastExpr *CStyleCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, @@ -1771,7 +1763,7 @@ unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); - CStyleCastExpr *E = + auto *E = new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); if (PathSize) E->setCastPath(*BasePath); return E; @@ -1925,7 +1917,7 @@ return nullptr; } - Expr *Result = cast_or_null(InitExprs[Init]); + auto *Result = cast_or_null(InitExprs[Init]); setInit(Init, expr); return Result; } @@ -1960,10 +1952,8 @@ SourceLocation Beg = LBraceLoc; if (Beg.isInvalid()) { // Find the first non-null initializer. - for (InitExprsTy::const_iterator I = InitExprs.begin(), - E = InitExprs.end(); - I != E; ++I) { - if (Stmt *S = *I) { + for (const auto &I : InitExprs) { + if (Stmt *S = I) { Beg = S->getLocStart(); break; } @@ -2008,7 +1998,6 @@ return TheBlock->getBody(); } - //===----------------------------------------------------------------------===// // Generic Expression Routines //===----------------------------------------------------------------------===// @@ -2043,7 +2032,7 @@ return cast(this)->getChosenSubExpr()-> isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); case UnaryOperatorClass: { - const UnaryOperator *UO = cast(this); + const auto *UO = cast(this); switch (UO->getOpcode()) { case UO_Plus: @@ -2077,7 +2066,7 @@ return true; } case BinaryOperatorClass: { - const BinaryOperator *BO = cast(this); + const auto *BO = cast(this); switch (BO->getOpcode()) { default: break; @@ -2086,8 +2075,7 @@ case BO_Comma: // ((foo = ), 0) is an idiom for hiding the result (and // lvalue-ness) of an assignment written in a macro. - if (IntegerLiteral *IE = - dyn_cast(BO->getRHS()->IgnoreParens())) + if (auto *IE = dyn_cast(BO->getRHS()->IgnoreParens())) if (IE->getValue() == 0) return false; return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); @@ -2116,7 +2104,7 @@ // If only one of the LHS or RHS is a warning, the operator might // be being used for control flow. Only warn if both the LHS and // RHS are warnings. - const ConditionalOperator *Exp = cast(this); + const auto *Exp = cast(this); if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) return false; if (!Exp->getLHS()) @@ -2145,7 +2133,7 @@ // warning: operators == and != are commonly typo'ed, and so warning on them // provides additional value as well. If this list is updated, // DiagnoseUnusedComparison should be as well. - const CXXOperatorCallExpr *Op = cast(this); + const auto *Op = cast(this); switch (Op->getOperator()) { default: break; @@ -2170,9 +2158,9 @@ case CXXMemberCallExprClass: case UserDefinedLiteralClass: { // If this is a direct call, get the callee. - const CallExpr *CE = cast(this); + const auto *CE = cast(this); if (const Decl *FD = CE->getCalleeDecl()) { - const FunctionDecl *Func = dyn_cast(FD); + const auto *Func = dyn_cast(FD); bool HasWarnUnusedResultAttr = Func ? Func->hasUnusedResultAttr() : FD->hasAttr(); @@ -2215,7 +2203,7 @@ } case ObjCMessageExprClass: { - const ObjCMessageExpr *ME = cast(this); + const auto *ME = cast(this); if (Ctx.getLangOpts().ObjCAutoRefCount && ME->isInstanceMessage() && !ME->getType()->isVoidType() && @@ -2243,7 +2231,7 @@ return true; case PseudoObjectExprClass: { - const PseudoObjectExpr *PO = cast(this); + const auto *PO = cast(this); // Only complain about things that have the form of a getter. if (isa(PO->getSyntacticForm()) || @@ -2264,10 +2252,10 @@ // warning. const CompoundStmt *CS = cast(this)->getSubStmt(); if (!CS->body_empty()) { - if (const Expr *E = dyn_cast(CS->body_back())) + if (const auto *E = dyn_cast(CS->body_back())) return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); - if (const LabelStmt *Label = dyn_cast(CS->body_back())) - if (const Expr *E = dyn_cast(Label->getSubStmt())) + if (const auto *Label = dyn_cast(CS->body_back())) + if (const auto *E = dyn_cast(Label->getSubStmt())) return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); } @@ -2282,12 +2270,12 @@ case CStyleCastExprClass: { // Ignore an explicit cast to void unless the operand is a non-trivial // volatile lvalue. - const CastExpr *CE = cast(this); + const auto *CE = cast(this); if (CE->getCastKind() == CK_ToVoid) { if (CE->getSubExpr()->isGLValue() && CE->getSubExpr()->getType().isVolatileQualified()) { - const DeclRefExpr *DRE = - dyn_cast(CE->getSubExpr()->IgnoreParens()); + const auto *DRE = + dyn_cast(CE->getSubExpr()->IgnoreParens()); if (!(DRE && isa(DRE->getDecl()) && cast(DRE->getDecl())->hasLocalStorage())) { return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, @@ -2303,19 +2291,18 @@ return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); WarnE = this; - if (const CXXFunctionalCastExpr *CXXCE = - dyn_cast(this)) { + if (const auto *CXXCE = dyn_cast(this)) { Loc = CXXCE->getLocStart(); R1 = CXXCE->getSubExpr()->getSourceRange(); } else { - const CStyleCastExpr *CStyleCE = cast(this); + const auto *CStyleCE = cast(this); Loc = CStyleCE->getLParenLoc(); R1 = CStyleCE->getSubExpr()->getSourceRange(); } return true; } case ImplicitCastExprClass: { - const CastExpr *ICE = cast(this); + const auto *ICE = cast(this); // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect. if (ICE->getCastKind() == CK_LValueToRValue && @@ -2366,7 +2353,7 @@ case DeclRefExprClass: { const Decl *D = cast(E)->getDecl(); - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { if (VD->hasGlobalStorage()) return true; QualType T = VD->getType(); @@ -2378,7 +2365,7 @@ return false; } case MemberExprClass: { - const MemberExpr *M = cast(E); + const auto *M = cast(E); return M->getBase()->isOBJCGCCandidate(Ctx); } case ArraySubscriptExprClass: @@ -2400,12 +2387,12 @@ // (possibly parenthesized) expr = expr->IgnoreParens(); - if (const MemberExpr *mem = dyn_cast(expr)) { + if (const auto *mem = dyn_cast(expr)) { assert(isa(mem->getMemberDecl())); return mem->getMemberDecl()->getType(); } - if (const BinaryOperator *op = dyn_cast(expr)) { + if (const auto *op = dyn_cast(expr)) { QualType type = op->getRHS()->getType()->castAs() ->getPointeeType(); assert(type->isFunctionType()); @@ -2419,23 +2406,23 @@ Expr* Expr::IgnoreParens() { Expr* E = this; while (true) { - if (ParenExpr* P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { E = P->getSubExpr(); continue; } - if (UnaryOperator* P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { if (P->getOpcode() == UO_Extension) { E = P->getSubExpr(); continue; } } - if (GenericSelectionExpr* P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { if (!P->isResultDependent()) { E = P->getResultExpr(); continue; } } - if (ChooseExpr* P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { if (!P->isConditionDependent()) { E = P->getChosenSubExpr(); continue; @@ -2451,17 +2438,15 @@ Expr *E = this; while (true) { E = E->IgnoreParens(); - if (CastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { E = P->getSubExpr(); continue; } - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(E)) { + if (auto *Materialize = dyn_cast(E)) { E = Materialize->GetTemporaryExpr(); continue; } - if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2472,17 +2457,15 @@ Expr *Expr::IgnoreCasts() { Expr *E = this; while (true) { - if (CastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { E = P->getSubExpr(); continue; } - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(E)) { + if (auto *Materialize = dyn_cast(E)) { E = Materialize->GetTemporaryExpr(); continue; } - if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2498,17 +2481,15 @@ Expr *E = this; while (true) { E = E->IgnoreParens(); - if (CastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { if (P->getCastKind() == CK_LValueToRValue) { E = P->getSubExpr(); continue; } - } else if (MaterializeTemporaryExpr *Materialize - = dyn_cast(E)) { + } else if (auto *Materialize = dyn_cast(E)) { E = Materialize->GetTemporaryExpr(); continue; - } else if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + } else if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2521,7 +2502,7 @@ Expr *E = this; while (true) { E = E->IgnoreParens(); - if (CastExpr *CE = dyn_cast(E)) { + if (auto *CE = dyn_cast(E)) { if (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_UncheckedDerivedToBase || CE->getCastKind() == CK_NoOp) { @@ -2538,17 +2519,15 @@ Expr *E = this; while (true) { E = E->IgnoreParens(); - if (ImplicitCastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { E = P->getSubExpr(); continue; } - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(E)) { + if (auto *Materialize = dyn_cast(E)) { E = Materialize->GetTemporaryExpr(); continue; } - if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2557,7 +2536,7 @@ } Expr *Expr::IgnoreConversionOperator() { - if (CXXMemberCallExpr *MCE = dyn_cast(this)) { + if (auto *MCE = dyn_cast(this)) { if (MCE->getMethodDecl() && isa(MCE->getMethodDecl())) return MCE->getImplicitObjectArgument(); } @@ -2572,7 +2551,7 @@ while (true) { E = E->IgnoreParens(); - if (CastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { // We ignore integer <-> casts that are of the same width, ptr<->ptr and // ptr<->int casts of the same width. We also ignore all identity casts. Expr *SE = P->getSubExpr(); @@ -2592,8 +2571,7 @@ } } - if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2604,10 +2582,10 @@ bool Expr::isDefaultArgument() const { const Expr *E = this; - if (const MaterializeTemporaryExpr *M = dyn_cast(E)) + if (const auto *M = dyn_cast(E)) E = M->GetTemporaryExpr(); - while (const ImplicitCastExpr *ICE = dyn_cast(E)) + while (const auto *ICE = dyn_cast(E)) E = ICE->getSubExprAsWritten(); return isa(E); @@ -2616,20 +2594,20 @@ /// \brief Skip over any no-op casts and any temporary-binding /// expressions. static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { - if (const MaterializeTemporaryExpr *M = dyn_cast(E)) + if (const auto *M = dyn_cast(E)) E = M->GetTemporaryExpr(); - while (const ImplicitCastExpr *ICE = dyn_cast(E)) { + while (const auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_NoOp) E = ICE->getSubExpr(); else break; } - while (const CXXBindTemporaryExpr *BE = dyn_cast(E)) + while (const auto *BE = dyn_cast(E)) E = BE->getSubExpr(); - while (const ImplicitCastExpr *ICE = dyn_cast(E)) { + while (const auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_NoOp) E = ICE->getSubExpr(); else @@ -2672,7 +2650,7 @@ if (isa(E)) return false; - if (const BinaryOperator *BO = dyn_cast(E)) + if (const auto *BO = dyn_cast(E)) if (BO->isPtrMemOp()) return false; @@ -2688,12 +2666,12 @@ // Strip away parentheses and casts we don't care about. while (true) { - if (const ParenExpr *Paren = dyn_cast(E)) { + if (const auto *Paren = dyn_cast(E)) { E = Paren->getSubExpr(); continue; } - if (const ImplicitCastExpr *ICE = dyn_cast(E)) { + if (const auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_NoOp || ICE->getCastKind() == CK_LValueToRValue || ICE->getCastKind() == CK_DerivedToBase || @@ -2703,15 +2681,14 @@ } } - if (const UnaryOperator* UnOp = dyn_cast(E)) { + if (const auto* UnOp = dyn_cast(E)) { if (UnOp->getOpcode() == UO_Extension) { E = UnOp->getSubExpr(); continue; } } - if (const MaterializeTemporaryExpr *M - = dyn_cast(E)) { + if (const auto *M = dyn_cast(E)) { E = M->GetTemporaryExpr(); continue; } @@ -2719,7 +2696,7 @@ break; } - if (const CXXThisExpr *This = dyn_cast(E)) + if (const auto *This = dyn_cast(E)) return This->isImplicit(); return false; @@ -2728,8 +2705,8 @@ /// hasAnyTypeDependentArguments - Determines if any of the expressions /// in Exprs is type-dependent. bool Expr::hasAnyTypeDependentArguments(ArrayRef Exprs) { - for (unsigned I = 0; I < Exprs.size(); ++I) - if (Exprs[I]->isTypeDependent()) + for (const auto *Expr : Exprs) + if (Expr->isTypeDependent()) return true; return false; @@ -2762,7 +2739,7 @@ return true; case CXXTemporaryObjectExprClass: case CXXConstructExprClass: { - const CXXConstructExpr *CE = cast(this); + const auto *CE = cast(this); if (CE->getConstructor()->isTrivial() && CE->getConstructor()->getParent()->hasTrivialDestructor()) { @@ -2784,12 +2761,12 @@ return Exp->isConstantInitializer(Ctx, false, Culprit); } case DesignatedInitUpdateExprClass: { - const DesignatedInitUpdateExpr *DIUE = cast(this); + const auto *DIUE = cast(this); return DIUE->getBase()->isConstantInitializer(Ctx, false, Culprit) && DIUE->getUpdater()->isConstantInitializer(Ctx, false, Culprit); } case InitListExprClass: { - const InitListExpr *ILE = cast(this); + const auto *ILE = cast(this); if (ILE->getType()->isArrayType()) { unsigned numInits = ILE->getNumInits(); for (unsigned i = 0; i < numInits; i++) { @@ -2851,7 +2828,7 @@ return cast(this)->getChosenSubExpr() ->isConstantInitializer(Ctx, IsForRef, Culprit); case UnaryOperatorClass: { - const UnaryOperator* Exp = cast(this); + const auto* Exp = cast(this); if (Exp->getOpcode() == UO_Extension) return Exp->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); break; @@ -2864,7 +2841,7 @@ case CXXDynamicCastExprClass: case CXXReinterpretCastExprClass: case CXXConstCastExprClass: { - const CastExpr *CE = cast(this); + const auto *CE = cast(this); // Handle misc casts we want to ignore. if (CE->getCastKind() == CK_NoOp || @@ -2918,7 +2895,7 @@ HasSideEffects = true; } }; -} +} // anonymous namespace bool Expr::HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects) const { @@ -3084,7 +3061,7 @@ case CXXDynamicCastExprClass: { // A dynamic_cast expression has side-effects if it can throw. - const CXXDynamicCastExpr *DCE = cast(this); + const auto *DCE = cast(this); if (DCE->getTypeAsWritten()->isReferenceType() && DCE->getCastKind() == CK_Dynamic) return true; @@ -3102,7 +3079,7 @@ if (!IncludePossibleEffects) break; - const CastExpr *CE = cast(this); + const auto *CE = cast(this); if (CE->getCastKind() == CK_LValueToRValue && CE->getSubExpr()->getType().isVolatileQualified()) return true; @@ -3116,7 +3093,7 @@ case CXXConstructExprClass: case CXXTemporaryObjectExprClass: { - const CXXConstructExpr *CE = cast(this); + const auto *CE = cast(this); if (!CE->getConstructor()->isTrivial() && IncludePossibleEffects) return true; // A trivial constructor does not add any side-effects of its own. Just look @@ -3125,7 +3102,7 @@ } case LambdaExprClass: { - const LambdaExpr *LE = cast(this); + const auto *LE = cast(this); for (LambdaExpr::capture_iterator I = LE->capture_begin(), E = LE->capture_end(); I != E; ++I) if (I->getCaptureKind() == LCK_ByCopy) @@ -3138,12 +3115,12 @@ case PseudoObjectExprClass: { // Only look for side-effects in the semantic form, and look past // OpaqueValueExpr bindings in that form. - const PseudoObjectExpr *PO = cast(this); + const auto *PO = cast(this); for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(), E = PO->semantics_end(); I != E; ++I) { const Expr *Subexpr = *I; - if (const OpaqueValueExpr *OVE = dyn_cast(Subexpr)) + if (const auto *OVE = dyn_cast(Subexpr)) Subexpr = OVE->getSourceExpr(); if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects)) return true; @@ -3192,8 +3169,8 @@ bool hasNonTrivialCall() const { return NonTrivial; } void VisitCallExpr(const CallExpr *E) { - if (const CXXMethodDecl *Method - = dyn_cast_or_null(E->getCalleeDecl())) { + if (const auto *Method + = dyn_cast_or_null(E->getCalleeDecl())) { if (Method->isTrivial()) { // Recurse to children of the call. Inherited::VisitStmt(E); @@ -3223,7 +3200,7 @@ NonTrivial = true; } }; -} +} // anonymous namespace bool Expr::hasNonTrivialCall(const ASTContext &Ctx) const { NonTrivialCallFinder Finder(Ctx); @@ -3256,7 +3233,7 @@ } // Strip off a cast to void*, if it exists. Except in C++. - if (const ExplicitCastExpr *CE = dyn_cast(this)) { + if (const auto *CE = dyn_cast(this)) { if (!Ctx.getLangOpts().CPlusPlus) { // Check that it is a cast to void*. if (const PointerType *PT = CE->getType()->getAs()) { @@ -3267,37 +3244,33 @@ return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); } } - } else if (const ImplicitCastExpr *ICE = dyn_cast(this)) { + } else if (const auto *ICE = dyn_cast(this)) { // Ignore the ImplicitCastExpr type entirely. return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const ParenExpr *PE = dyn_cast(this)) { + } else if (const auto *PE = dyn_cast(this)) { // Accept ((void*)0) as a null pointer constant, as many other // implementations do. return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const GenericSelectionExpr *GE = - dyn_cast(this)) { + } else if (const auto *GE = dyn_cast(this)) { if (GE->isResultDependent()) return NPCK_NotNull; return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const ChooseExpr *CE = dyn_cast(this)) { + } else if (const auto *CE = dyn_cast(this)) { if (CE->isConditionDependent()) return NPCK_NotNull; return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const CXXDefaultArgExpr *DefaultArg - = dyn_cast(this)) { + } else if (const auto *DefaultArg = dyn_cast(this)) { // See through default argument expressions. return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const CXXDefaultInitExpr *DefaultInit - = dyn_cast(this)) { + } else if (const auto *DefaultInit = dyn_cast(this)) { // See through default initializer expressions. return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC); } else if (isa(this)) { // The GNU __null extension is always a null pointer constant. return NPCK_GNUNull; - } else if (const MaterializeTemporaryExpr *M - = dyn_cast(this)) { + } else if (const auto *M = dyn_cast(this)) { return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const OpaqueValueExpr *OVE = dyn_cast(this)) { + } else if (const auto *OVE = dyn_cast(this)) { if (const Expr *Source = OVE->getSourceExpr()) return Source->isNullPointerConstant(Ctx, NPC); } @@ -3309,9 +3282,9 @@ if (const RecordType *UT = getType()->getAsUnionType()) if (!Ctx.getLangOpts().CPlusPlus11 && UT && UT->getDecl()->hasAttr()) - if (const CompoundLiteralExpr *CLE = dyn_cast(this)){ + if (const auto *CLE = dyn_cast(this)){ const Expr *InitExpr = CLE->getInitializer(); - if (const InitListExpr *ILE = dyn_cast(InitExpr)) + if (const auto *ILE = dyn_cast(InitExpr)) return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); } // This expression must be an integer type. @@ -3323,7 +3296,7 @@ // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with // value zero or a prvalue of type std::nullptr_t. // Microsoft mode permits C++98 rules reflecting MSVC behavior. - const IntegerLiteral *Lit = dyn_cast(this); + const auto *Lit = dyn_cast(this); if (Lit && !Lit->getValue()) return NPCK_ZeroLiteral; else if (!Ctx.getLangOpts().MSVCCompat || !isCXX98IntegralConstantExpr(Ctx)) @@ -3352,7 +3325,7 @@ E->getObjectKind() == OK_ObjCProperty) && "expression is not a property reference"); E = E->IgnoreParenCasts(); - if (const BinaryOperator *BO = dyn_cast(E)) { + if (const auto *BO = dyn_cast(E)) { if (BO->getOpcode() == BO_Comma) { E = BO->getRHS(); continue; @@ -3368,15 +3341,15 @@ bool Expr::isObjCSelfExpr() const { const Expr *E = IgnoreParenImpCasts(); - const DeclRefExpr *DRE = dyn_cast(E); + const auto *DRE = dyn_cast(E); if (!DRE) return false; - const ImplicitParamDecl *Param = dyn_cast(DRE->getDecl()); + const auto *Param = dyn_cast(DRE->getDecl()); if (!Param) return false; - const ObjCMethodDecl *M = dyn_cast(Param->getDeclContext()); + const auto *M = dyn_cast(Param->getDeclContext()); if (!M) return false; @@ -3386,7 +3359,7 @@ FieldDecl *Expr::getSourceBitField() { Expr *E = this->IgnoreParens(); - while (ImplicitCastExpr *ICE = dyn_cast(E)) { + while (auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_LValueToRValue || (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) E = ICE->getSubExpr()->IgnoreParens(); @@ -3394,22 +3367,22 @@ break; } - if (MemberExpr *MemRef = dyn_cast(E)) - if (FieldDecl *Field = dyn_cast(MemRef->getMemberDecl())) + if (auto *MemRef = dyn_cast(E)) + if (auto *Field = dyn_cast(MemRef->getMemberDecl())) if (Field->isBitField()) return Field; - if (ObjCIvarRefExpr *IvarRef = dyn_cast(E)) - if (FieldDecl *Ivar = dyn_cast(IvarRef->getDecl())) + if (auto *IvarRef = dyn_cast(E)) + if (auto *Ivar = dyn_cast(IvarRef->getDecl())) if (Ivar->isBitField()) return Ivar; - if (DeclRefExpr *DeclRef = dyn_cast(E)) - if (FieldDecl *Field = dyn_cast(DeclRef->getDecl())) + if (auto *DeclRef = dyn_cast(E)) + if (auto *Field = dyn_cast(DeclRef->getDecl())) if (Field->isBitField()) return Field; - if (BinaryOperator *BinOp = dyn_cast(E)) { + if (auto *BinOp = dyn_cast(E)) { if (BinOp->isAssignmentOp() && BinOp->getLHS()) return BinOp->getLHS()->getSourceBitField(); @@ -3417,7 +3390,7 @@ return BinOp->getRHS()->getSourceBitField(); } - if (UnaryOperator *UnOp = dyn_cast(E)) + if (auto *UnOp = dyn_cast(E)) if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp()) return UnOp->getSubExpr()->getSourceBitField(); @@ -3427,7 +3400,7 @@ bool Expr::refersToVectorElement() const { const Expr *E = this->IgnoreParens(); - while (const ImplicitCastExpr *ICE = dyn_cast(E)) { + while (const auto *ICE = dyn_cast(E)) { if (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp) E = ICE->getSubExpr()->IgnoreParens(); @@ -3435,7 +3408,7 @@ break; } - if (const ArraySubscriptExpr *ASE = dyn_cast(E)) + if (const auto *ASE = dyn_cast(E)) return ASE->getBase()->getType()->isVectorType(); if (isa(E)) @@ -3447,7 +3420,7 @@ bool Expr::refersToGlobalRegisterVar() const { const Expr *E = this->IgnoreParenImpCasts(); - if (const DeclRefExpr *DRE = dyn_cast(E)) + if (const auto *DRE = dyn_cast(E)) if (const auto *VD = dyn_cast(DRE->getDecl())) if (VD->getStorageClass() == SC_Register && VD->hasAttr() && !VD->isLocalVarDecl()) @@ -3711,7 +3684,7 @@ } SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { - DesignatedInitExpr *DIE = const_cast(this); + auto *DIE = const_cast(this); if (size() == 1) return DIE->getDesignator(0)->getSourceRange(); return SourceRange(DIE->getDesignator(0)->getLocStart(), @@ -3739,21 +3712,21 @@ Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) const { assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); - Stmt *const *SubExprs = reinterpret_cast(this + 1); + auto SubExprs = reinterpret_cast(this + 1); return cast(*(SubExprs + D.ArrayOrRange.Index + 1)); } Expr *DesignatedInitExpr::getArrayRangeStart(const Designator &D) const { assert(D.Kind == Designator::ArrayRangeDesignator && "Requires array range designator"); - Stmt *const *SubExprs = reinterpret_cast(this + 1); + auto SubExprs = reinterpret_cast(this + 1); return cast(*(SubExprs + D.ArrayOrRange.Index + 1)); } Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator &D) const { assert(D.Kind == Designator::ArrayRangeDesignator && "Requires array range designator"); - Stmt *const *SubExprs = reinterpret_cast(this + 1); + auto SubExprs = reinterpret_cast(this + 1); return cast(*(SubExprs + D.ArrayOrRange.Index + 2)); } @@ -3774,7 +3747,7 @@ return; } - Designator *NewDesignators + auto *NewDesignators = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; std::copy(Designators, Designators + Idx, NewDesignators); std::copy(First, Last, NewDesignators + Idx); @@ -3790,7 +3763,7 @@ OK_Ordinary, false, false, false, false) { BaseAndUpdaterExprs[0] = baseExpr; - InitListExpr *ILE = new (C) InitListExpr(C, lBraceLoc, None, rBraceLoc); + auto *ILE = new (C) InitListExpr(C, lBraceLoc, None, rBraceLoc); ILE->setType(baseExpr->getType()); BaseAndUpdaterExprs[1] = ILE; } @@ -3825,12 +3798,12 @@ } const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { - if (const ExprWithCleanups *ewc = dyn_cast(e)) + if (const auto *ewc = dyn_cast(e)) e = ewc->getSubExpr(); - if (const MaterializeTemporaryExpr *m = dyn_cast(e)) + if (const auto *m = dyn_cast(e)) e = m->GetTemporaryExpr(); e = cast(e)->getArg(0); - while (const ImplicitCastExpr *ice = dyn_cast(e)) + while (const auto *ice = dyn_cast(e)) e = ice->getSubExpr(); return cast(e); } @@ -3912,7 +3885,7 @@ // size expression of the VLA needs to be treated as an executable expression. // Why isn't this weirdness documented better in StmtIterator? if (isArgumentType()) { - if (const VariableArrayType* T = dyn_cast( + if (const auto *T = dyn_cast( getArgumentType().getTypePtr())) return child_range(child_iterator(T), child_iterator()); return child_range(child_iterator(), child_iterator()); @@ -3998,8 +3971,8 @@ ++ArraySectionCount; } auto OriginalTy = Base->getType(); - if (auto *DRE = dyn_cast(Base)) - if (auto *PVD = dyn_cast(DRE->getDecl())) + if (const auto *DRE = dyn_cast(Base)) + if (const auto *PVD = dyn_cast(DRE->getDecl())) OriginalTy = PVD->getOriginalType().getNonReferenceType(); for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) { @@ -4012,4 +3985,3 @@ } return OriginalTy; } -