From 78beaaae9de250e4240eaa45b52d13432cf9ef11 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Mon, 28 Apr 2014 13:01:32 +0000 Subject: [PATCH] [C++11] Converting to range-based for loops. No functional changes intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207416 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/Consumed.cpp | 73 +++++++++++++++------------------------ 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/lib/Analysis/Consumed.cpp b/lib/Analysis/Consumed.cpp index 7b6ad574b7..31823f33f0 100644 --- a/lib/Analysis/Consumed.cpp +++ b/lib/Analysis/Consumed.cpp @@ -57,11 +57,9 @@ ConsumedWarningsHandlerBase::~ConsumedWarningsHandlerBase() {} static SourceLocation getFirstStmtLoc(const CFGBlock *Block) { // Find the source location of the first statement in the block, if the block // is not empty. - for (CFGBlock::const_iterator BI = Block->begin(), BE = Block->end(); - BI != BE; ++BI) { - if (Optional CS = BI->getAs()) + for (const auto &BI : *Block) + if (Optional CS = BI.getAs()) return CS->getStmt()->getLocStart(); - } // Block is empty. // If we have one successor, return the first statement in that block @@ -1144,21 +1142,19 @@ bool ConsumedBlockInfo::isBackEdgeTarget(const CFGBlock *Block) { void ConsumedStateMap::checkParamsForReturnTypestate(SourceLocation BlameLoc, ConsumedWarningsHandlerBase &WarningsHandler) const { - for (VarMapType::const_iterator DMI = VarMap.begin(), DME = VarMap.end(); - DMI != DME; ++DMI) { - - if (isa(DMI->first)) { - const ParmVarDecl *Param = cast(DMI->first); + for (const auto &DMI : VarMap) { + if (isa(DMI.first)) { + const ParmVarDecl *Param = cast(DMI.first); const ReturnTypestateAttr *RTA = Param->getAttr(); if (!RTA) continue; ConsumedState ExpectedState = mapReturnTypestateAttrState(RTA); - if (DMI->second != ExpectedState) + if (DMI.second != ExpectedState) WarningsHandler.warnParamReturnTypestateMismatch(BlameLoc, Param->getNameAsString(), stateToString(ExpectedState), - stateToString(DMI->second)); + stateToString(DMI.second)); } } } @@ -1194,16 +1190,14 @@ void ConsumedStateMap::intersect(const ConsumedStateMap *Other) { return; } - for (VarMapType::const_iterator DMI = Other->VarMap.begin(), - DME = Other->VarMap.end(); DMI != DME; ++DMI) { - - LocalState = this->getState(DMI->first); + for (const auto &DMI : Other->VarMap) { + LocalState = this->getState(DMI.first); if (LocalState == CS_None) continue; - if (LocalState != DMI->second) - VarMap[DMI->first] = CS_Unknown; + if (LocalState != DMI.second) + VarMap[DMI.first] = CS_Unknown; } } @@ -1214,18 +1208,16 @@ void ConsumedStateMap::intersectAtLoopHead(const CFGBlock *LoopHead, ConsumedState LocalState; SourceLocation BlameLoc = getLastStmtLoc(LoopBack); - for (VarMapType::const_iterator DMI = LoopBackStates->VarMap.begin(), - DME = LoopBackStates->VarMap.end(); DMI != DME; ++DMI) { - - LocalState = this->getState(DMI->first); + for (const auto &DMI : LoopBackStates->VarMap) { + LocalState = this->getState(DMI.first); if (LocalState == CS_None) continue; - if (LocalState != DMI->second) { - VarMap[DMI->first] = CS_Unknown; - WarningsHandler.warnLoopStateMismatch( - BlameLoc, DMI->first->getNameAsString()); + if (LocalState != DMI.second) { + VarMap[DMI.first] = CS_Unknown; + WarningsHandler.warnLoopStateMismatch(BlameLoc, + DMI.first->getNameAsString()); } } } @@ -1250,13 +1242,9 @@ void ConsumedStateMap::remove(const VarDecl *Var) { } bool ConsumedStateMap::operator!=(const ConsumedStateMap *Other) const { - for (VarMapType::const_iterator DMI = Other->VarMap.begin(), - DME = Other->VarMap.end(); DMI != DME; ++DMI) { - - if (this->getState(DMI->first) != DMI->second) - return true; - } - + for (const auto &DMI : Other->VarMap) + if (this->getState(DMI.first) != DMI.second) + return true; return false; } @@ -1396,16 +1384,11 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { ConsumedStmtVisitor Visitor(AC, *this, CurrStates); // Add all trackable parameters to the state map. - for (auto PI : D->params()) { + for (const auto *PI : D->params()) Visitor.VisitParmVarDecl(PI); - } // Visit all of the function's basic blocks. - for (PostOrderCFGView::iterator I = SortedGraph->begin(), - E = SortedGraph->end(); I != E; ++I) { - - const CFGBlock *CurrBlock = *I; - + for (const auto *CurrBlock : *SortedGraph) { if (CurrStates == NULL) CurrStates = BlockInfo.getInfo(CurrBlock); @@ -1421,16 +1404,14 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { Visitor.reset(CurrStates); // Visit all of the basic block's statements. - for (CFGBlock::const_iterator BI = CurrBlock->begin(), - BE = CurrBlock->end(); BI != BE; ++BI) { - - switch (BI->getKind()) { + for (const auto &BI : *CurrBlock) { + switch (BI.getKind()) { case CFGElement::Statement: - Visitor.Visit(BI->castAs().getStmt()); + Visitor.Visit(BI.castAs().getStmt()); break; case CFGElement::TemporaryDtor: { - const CFGTemporaryDtor DTor = BI->castAs(); + const CFGTemporaryDtor &DTor = BI.castAs(); const CXXBindTemporaryExpr *BTE = DTor.getBindTemporaryExpr(); Visitor.checkCallability(PropagationInfo(BTE), @@ -1440,7 +1421,7 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { } case CFGElement::AutomaticObjectDtor: { - const CFGAutomaticObjDtor DTor = BI->castAs(); + const CFGAutomaticObjDtor &DTor = BI.castAs(); SourceLocation Loc = DTor.getTriggerStmt()->getLocEnd(); const VarDecl *Var = DTor.getVarDecl(); -- 2.40.0