[C++11] Replacing DeclStmt iterators decl_begin() and decl_end() with iterator_range decls(). Updating all of the usages of the iterators with range-based for loops.

llvm-svn: 203947
This commit is contained in:
Aaron Ballman 2014-03-14 17:01:24 +00:00
parent edc1753ba3
commit 535bbcccb1
23 changed files with 58 additions and 82 deletions

View File

@ -1935,9 +1935,8 @@ DEF_TRAVERSE_STMT(CXXCatchStmt, {
})
DEF_TRAVERSE_STMT(DeclStmt, {
for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end();
I != E; ++I) {
TRY_TO(TraverseDecl(*I));
for (auto *I : S->decls()) {
TRY_TO(TraverseDecl(I));
}
// Suppress the default iteration over children() by
// returning. Here's why: A DeclStmt looks like 'type var [=

View File

@ -1950,9 +1950,8 @@ DEF_TRAVERSE_STMT(CXXCatchStmt, {
})
DEF_TRAVERSE_STMT(DeclStmt, {
for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end();
I != E; ++I) {
TRY_TO(TraverseDecl(*I));
for (auto *I : S->decls()) {
TRY_TO(TraverseDecl(I));
}
// Suppress the default iteration over children() by
// returning. Here's why: A DeclStmt looks like 'type var [=

View File

@ -485,7 +485,13 @@ public:
typedef DeclGroupRef::iterator decl_iterator;
typedef DeclGroupRef::const_iterator const_decl_iterator;
typedef llvm::iterator_range<decl_iterator> decl_range;
typedef llvm::iterator_range<const_decl_iterator> decl_const_range;
decl_range decls() { return decl_range(decl_begin(), decl_end()); }
decl_const_range decls() const {
return decl_const_range(decl_begin(), decl_end());
}
decl_iterator decl_begin() { return DG.begin(); }
decl_iterator decl_end() { return DG.end(); }
const_decl_iterator decl_begin() const { return DG.begin(); }

View File

@ -3318,13 +3318,12 @@ static EvalStmtResult EvaluateStmt(APValue &Result, EvalInfo &Info,
case Stmt::DeclStmtClass: {
const DeclStmt *DS = cast<DeclStmt>(S);
for (DeclStmt::const_decl_iterator DclIt = DS->decl_begin(),
DclEnd = DS->decl_end(); DclIt != DclEnd; ++DclIt) {
for (const auto *DclIt : DS->decls()) {
// Each declaration initialization is its own full-expression.
// FIXME: This isn't quite right; if we're performing aggregate
// initialization, each braced subexpression is its own full-expression.
FullExpressionRAII Scope(Info);
if (!EvaluateDecl(Info, *DclIt) && !Info.keepEvaluatingAfterFailure())
if (!EvaluateDecl(Info, DclIt) && !Info.keepEvaluatingAfterFailure())
return ESR_Failed;
}
return ESR_Succeeded;

View File

@ -126,11 +126,7 @@ void StmtPrinter::PrintRawDecl(Decl *D) {
}
void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
DeclStmt::const_decl_iterator Begin = S->decl_begin(), End = S->decl_end();
SmallVector<Decl*, 2> Decls;
for ( ; Begin != End; ++Begin)
Decls.push_back(*Begin);
SmallVector<Decl*, 2> Decls(S->decls());
Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
}

View File

@ -79,9 +79,8 @@ void StmtProfiler::VisitStmt(const Stmt *S) {
void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
VisitStmt(S);
for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
D != DEnd; ++D)
VisitDecl(*D);
for (const auto *D : S->decls())
VisitDecl(D);
}
void StmtProfiler::VisitNullStmt(const NullStmt *S) {

View File

@ -961,11 +961,9 @@ LocalScope* CFGBuilder::addLocalScopeForDeclStmt(DeclStmt *DS,
if (!BuildOpts.AddImplicitDtors)
return Scope;
for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end()
; DI != DE; ++DI) {
if (VarDecl *VD = dyn_cast<VarDecl>(*DI))
for (auto *DI : DS->decls())
if (VarDecl *VD = dyn_cast<VarDecl>(DI))
Scope = addLocalScopeForVarDecl(VD, Scope);
}
return Scope;
}

View File

@ -851,11 +851,9 @@ void ConsumedStmtVisitor::VisitDeclRefExpr(const DeclRefExpr *DeclRef) {
}
void ConsumedStmtVisitor::VisitDeclStmt(const DeclStmt *DeclS) {
for (DeclStmt::const_decl_iterator DI = DeclS->decl_begin(),
DE = DeclS->decl_end(); DI != DE; ++DI) {
if (isa<VarDecl>(*DI)) VisitVarDecl(cast<VarDecl>(*DI));
}
for (const auto *DI : DeclS->decls())
if (isa<VarDecl>(DI))
VisitVarDecl(cast<VarDecl>(DI));
if (DeclS->isSingleDecl())
if (const VarDecl *Var = dyn_cast_or_null<VarDecl>(DeclS->getSingleDecl()))

View File

@ -389,9 +389,8 @@ void TransferFunctions::VisitDeclRefExpr(DeclRefExpr *DR) {
}
void TransferFunctions::VisitDeclStmt(DeclStmt *DS) {
for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE = DS->decl_end();
DI != DE; ++DI)
if (VarDecl *VD = dyn_cast<VarDecl>(*DI)) {
for (const auto *DI : DS->decls())
if (const auto *VD = dyn_cast<VarDecl>(DI)) {
if (!isAlwaysAlive(VD))
val.liveDecls = LV.DSetFact.remove(val.liveDecls, VD);
}

View File

@ -171,10 +171,9 @@ void PseudoConstantAnalysis::RunAnalysis() {
case Stmt::DeclStmtClass: {
const DeclStmt *DS = cast<DeclStmt>(Head);
// Iterate over each decl and see if any of them contain reference decls
for (DeclStmt::const_decl_iterator I = DS->decl_begin(),
E = DS->decl_end(); I != E; ++I) {
for (const auto *I : DS->decls()) {
// We only care about VarDecls
const VarDecl *VD = dyn_cast<VarDecl>(*I);
const VarDecl *VD = dyn_cast<VarDecl>(I);
if (!VD)
continue;

View File

@ -373,9 +373,8 @@ void ClassifyRefs::classify(const Expr *E, Class C) {
}
void ClassifyRefs::VisitDeclStmt(DeclStmt *DS) {
for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end();
DI != DE; ++DI) {
VarDecl *VD = dyn_cast<VarDecl>(*DI);
for (auto *DI : DS->decls()) {
VarDecl *VD = dyn_cast<VarDecl>(DI);
if (VD && isTrackedVar(VD))
if (const DeclRefExpr *DRE = getSelfInitExpr(VD))
Classification[DRE] = SelfInit;
@ -694,9 +693,8 @@ void TransferFunctions::VisitBinaryOperator(BinaryOperator *BO) {
}
void TransferFunctions::VisitDeclStmt(DeclStmt *DS) {
for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end();
DI != DE; ++DI) {
VarDecl *VD = dyn_cast<VarDecl>(*DI);
for (auto *DI : DS->decls()) {
VarDecl *VD = dyn_cast<VarDecl>(DI);
if (VD && isTrackedVar(VD)) {
if (getSelfInitExpr(VD)) {
// If the initializer consists solely of a reference to itself, we

View File

@ -1013,10 +1013,9 @@ static bool isCapturedBy(const VarDecl &var, const Expr *e) {
}
else if (DeclStmt *DS = dyn_cast<DeclStmt>((*BI))) {
// special case declarations
for (DeclStmt::decl_iterator I = DS->decl_begin(), E = DS->decl_end();
I != E; ++I) {
if (VarDecl *VD = dyn_cast<VarDecl>((*I))) {
Expr *Init = VD->getInit();
for (const auto *I : DS->decls()) {
if (const auto *VD = dyn_cast<VarDecl>((I))) {
const Expr *Init = VD->getInit();
if (Init && isCapturedBy(var, Init))
return true;
}

View File

@ -891,9 +891,8 @@ void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) {
if (HaveInsertPoint())
EmitStopPoint(&S);
for (DeclStmt::const_decl_iterator I = S.decl_begin(), E = S.decl_end();
I != E; ++I)
EmitDecl(**I);
for (const auto *I : S.decls())
EmitDecl(*I);
}
void CodeGenFunction::EmitBreakStmt(const BreakStmt &S) {

View File

@ -4753,9 +4753,7 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) {
RewriteObjCQualifiedInterfaceTypes(*DS->decl_begin());
// Blocks rewrite rules.
for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end();
DI != DE; ++DI) {
Decl *SD = *DI;
for (auto *SD : DS->decls()) {
if (ValueDecl *ND = dyn_cast<ValueDecl>(SD)) {
if (isTopLevelBlockPointerType(ND->getType()))
RewriteBlockPointerDecl(ND);

View File

@ -367,9 +367,8 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned &origParentScope)
if (DeclStmt *DS = dyn_cast<DeclStmt>(SubStmt)) {
// The decl statement creates a scope if any of the decls in it are VLAs
// or have the cleanup attribute.
for (DeclStmt::decl_iterator I = DS->decl_begin(), E = DS->decl_end();
I != E; ++I)
BuildScopeInformation(*I, ParentScope);
for (auto *I : DS->decls())
BuildScopeInformation(I, ParentScope);
continue;
}
// Disallow jumps into any part of an @try statement by pushing a scope and

View File

@ -813,9 +813,8 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const FunctionDecl *Dcl,
// C++11 [dcl.constexpr]p3 and p4:
// The definition of a constexpr function(p3) or constructor(p4) [...] shall
// contain only
for (DeclStmt::decl_iterator DclIt = DS->decl_begin(),
DclEnd = DS->decl_end(); DclIt != DclEnd; ++DclIt) {
switch ((*DclIt)->getKind()) {
for (const auto *DclIt : DS->decls()) {
switch (DclIt->getKind()) {
case Decl::StaticAssert:
case Decl::Using:
case Decl::UsingShadow:
@ -831,7 +830,7 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const FunctionDecl *Dcl,
case Decl::TypeAlias: {
// - typedef declarations and alias-declarations that do not define
// classes or enumerations,
TypedefNameDecl *TN = cast<TypedefNameDecl>(*DclIt);
const auto *TN = cast<TypedefNameDecl>(DclIt);
if (TN->getUnderlyingType()->isVariablyModifiedType()) {
// Don't allow variably-modified types in constexpr functions.
TypeLoc TL = TN->getTypeSourceInfo()->getTypeLoc();
@ -846,7 +845,7 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const FunctionDecl *Dcl,
case Decl::Enum:
case Decl::CXXRecord:
// C++1y allows types to be defined, not just declared.
if (cast<TagDecl>(*DclIt)->isThisDeclarationADefinition())
if (cast<TagDecl>(DclIt)->isThisDeclarationADefinition())
SemaRef.Diag(DS->getLocStart(),
SemaRef.getLangOpts().CPlusPlus1y
? diag::warn_cxx11_compat_constexpr_type_definition
@ -865,7 +864,7 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const FunctionDecl *Dcl,
// C++1y [dcl.constexpr]p3 allows anything except:
// a definition of a variable of non-literal type or of static or
// thread storage duration or for which no initialization is performed.
VarDecl *VD = cast<VarDecl>(*DclIt);
const auto *VD = cast<VarDecl>(DclIt);
if (VD->isThisDeclarationADefinition()) {
if (VD->isStaticLocal()) {
SemaRef.Diag(VD->getLocation(),

View File

@ -1594,14 +1594,13 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
// C99 6.8.5p3: The declaration part of a 'for' statement shall only
// declare identifiers for objects having storage class 'auto' or
// 'register'.
for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE=DS->decl_end();
DI!=DE; ++DI) {
VarDecl *VD = dyn_cast<VarDecl>(*DI);
for (auto *DI : DS->decls()) {
VarDecl *VD = dyn_cast<VarDecl>(DI);
if (VD && VD->isLocalVarDecl() && !VD->hasLocalStorage())
VD = 0;
if (VD == 0) {
Diag((*DI)->getLocation(), diag::err_non_local_variable_decl_in_for);
(*DI)->setInvalidDecl();
Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
DI->setInvalidDecl();
}
}
}

View File

@ -5684,14 +5684,12 @@ StmtResult
TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
bool DeclChanged = false;
SmallVector<Decl *, 4> Decls;
for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
D != DEnd; ++D) {
Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
*D);
for (auto *D : S->decls()) {
Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
if (!Transformed)
return StmtError();
if (Transformed != *D)
if (Transformed != D)
DeclChanged = true;
Decls.push_back(Transformed);

View File

@ -1935,9 +1935,8 @@ void CStringChecker::checkPreStmt(const DeclStmt *DS, CheckerContext &C) const {
// Record string length for char a[] = "abc";
ProgramStateRef state = C.getState();
for (DeclStmt::const_decl_iterator I = DS->decl_begin(), E = DS->decl_end();
I != E; ++I) {
const VarDecl *D = dyn_cast<VarDecl>(*I);
for (const auto *I : DS->decls()) {
const VarDecl *D = dyn_cast<VarDecl>(I);
if (!D)
continue;

View File

@ -313,10 +313,8 @@ public:
else if (const DeclStmt *DS = dyn_cast<DeclStmt>(S))
// Iterate through the decls. Warn if any initializers are complex
// expressions that are not live (never used).
for (DeclStmt::const_decl_iterator DI=DS->decl_begin(), DE=DS->decl_end();
DI != DE; ++DI) {
VarDecl *V = dyn_cast<VarDecl>(*DI);
for (const auto *DI : DS->decls()) {
const auto *V = dyn_cast<VarDecl>(DI);
if (!V)
continue;

View File

@ -145,8 +145,8 @@ static void CheckStringRefAssignedTemporary(const Decl *D, BugReporter &BR,
void StringRefCheckerVisitor::VisitDeclStmt(DeclStmt *S) {
VisitChildren(S);
for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end();I!=E; ++I)
if (VarDecl *VD = dyn_cast<VarDecl>(*I))
for (auto *I : S->decls())
if (VarDecl *VD = dyn_cast<VarDecl>(I))
VisitVarDecl(VD);
}

View File

@ -101,9 +101,8 @@ public:
}
TypeCallPair VisitDeclStmt(const DeclStmt *S) {
for (DeclStmt::const_decl_iterator I = S->decl_begin(), E = S->decl_end();
I!=E; ++I)
if (const VarDecl *VD = dyn_cast<VarDecl>(*I))
for (const auto *I : S->decls())
if (const VarDecl *VD = dyn_cast<VarDecl>(I))
if (const Expr *Init = VD->getInit())
VisitChild(VD, Init);
return TypeCallPair();

View File

@ -2072,9 +2072,8 @@ void EnqueueVisitor::VisitDependentScopeDeclRefExpr(
void EnqueueVisitor::VisitDeclStmt(const DeclStmt *S) {
unsigned size = WL.size();
bool isFirst = true;
for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
D != DEnd; ++D) {
AddDecl(*D, isFirst);
for (const auto *D : S->decls()) {
AddDecl(D, isFirst);
isFirst = false;
}
if (size == WL.size())