[clang] f1c159c - [Format, Sema] Use range-based for loops with llvm::reverse (NFC)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 17 08:52:45 PST 2021
Author: Kazu Hirata
Date: 2021-11-17T08:52:35-08:00
New Revision: f1c159cc908d23a381500c68ccabcd84bb6355c8
URL: https://github.com/llvm/llvm-project/commit/f1c159cc908d23a381500c68ccabcd84bb6355c8
DIFF: https://github.com/llvm/llvm-project/commit/f1c159cc908d23a381500c68ccabcd84bb6355c8.diff
LOG: [Format, Sema] Use range-based for loops with llvm::reverse (NFC)
Added:
Modified:
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaInit.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp
index a9cfb4a247f0..8075756cca03 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -506,11 +506,11 @@ void FormatTokenLexer::tryParseJSRegexLiteral() {
return;
FormatToken *Prev = nullptr;
- for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
+ for (FormatToken *FT : llvm::drop_begin(llvm::reverse(Tokens))) {
// NB: Because previous pointers are not initialized yet, this cannot use
// Token.getPreviousNonComment.
- if ((*I)->isNot(tok::comment)) {
- Prev = *I;
+ if (FT->isNot(tok::comment)) {
+ Prev = FT;
break;
}
}
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index ace3d25ca460..3897241cb858 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2322,11 +2322,9 @@ class ExpressionParser {
void TokenAnnotator::setCommentLineLevels(
SmallVectorImpl<AnnotatedLine *> &Lines) {
const AnnotatedLine *NextNonCommentLine = nullptr;
- for (SmallVectorImpl<AnnotatedLine *>::reverse_iterator I = Lines.rbegin(),
- E = Lines.rend();
- I != E; ++I) {
+ for (AnnotatedLine *AL : llvm::reverse(Lines)) {
bool CommentLine = true;
- for (const FormatToken *Tok = (*I)->First; Tok; Tok = Tok->Next) {
+ for (const FormatToken *Tok = AL->First; Tok; Tok = Tok->Next) {
if (!Tok->is(tok::comment)) {
CommentLine = false;
break;
@@ -2338,21 +2336,21 @@ void TokenAnnotator::setCommentLineLevels(
if (NextNonCommentLine && CommentLine &&
NextNonCommentLine->First->NewlinesBefore <= 1 &&
NextNonCommentLine->First->OriginalColumn ==
- (*I)->First->OriginalColumn) {
+ AL->First->OriginalColumn) {
// Align comments for preprocessor lines with the # in column 0 if
// preprocessor lines are not indented. Otherwise, align with the next
// line.
- (*I)->Level =
+ AL->Level =
(Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
(NextNonCommentLine->Type == LT_PreprocessorDirective ||
NextNonCommentLine->Type == LT_ImportStatement))
? 0
: NextNonCommentLine->Level;
} else {
- NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr;
+ NextNonCommentLine = AL->First->isNot(tok::r_brace) ? AL : nullptr;
}
- setCommentLineLevels((*I)->Children);
+ setCommentLineLevels(AL->Children);
}
}
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 796590c26d3f..8544a4fccf4c 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1112,10 +1112,8 @@ namespace {
continue; // Case label is preceded with a normal label, good.
if (!ReachableBlocks.count(P)) {
- for (CFGBlock::const_reverse_iterator ElemIt = P->rbegin(),
- ElemEnd = P->rend();
- ElemIt != ElemEnd; ++ElemIt) {
- if (Optional<CFGStmt> CS = ElemIt->getAs<CFGStmt>()) {
+ for (const CFGElement &Elem : llvm::reverse(*P)) {
+ if (Optional<CFGStmt> CS = Elem.getAs<CFGStmt>()) {
if (const AttributedStmt *AS = asFallThroughAttr(CS->getStmt())) {
// Don't issue a warning for an unreachable fallthrough
// attribute in template instantiations as it may not be
@@ -1199,12 +1197,9 @@ namespace {
static const Stmt *getLastStmt(const CFGBlock &B) {
if (const Stmt *Term = B.getTerminatorStmt())
return Term;
- for (CFGBlock::const_reverse_iterator ElemIt = B.rbegin(),
- ElemEnd = B.rend();
- ElemIt != ElemEnd; ++ElemIt) {
- if (Optional<CFGStmt> CS = ElemIt->getAs<CFGStmt>())
+ for (const CFGElement &Elem : llvm::reverse(B))
+ if (Optional<CFGStmt> CS = Elem.getAs<CFGStmt>())
return CS->getStmt();
- }
// Workaround to detect a statement thrown out by CFGBuilder:
// case X: {} case Y:
// case X: ; case Y:
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3fe7303cb445..6ffd2096cbc5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16611,10 +16611,8 @@ void Sema::RefersToMemberWithReducedAlignment(
// Synthesize offset of the whole access.
CharUnits Offset;
- for (auto I = ReverseMemberChain.rbegin(); I != ReverseMemberChain.rend();
- I++) {
- Offset += Context.toCharUnitsFromBits(Context.getFieldOffset(*I));
- }
+ for (const FieldDecl *FD : llvm::reverse(ReverseMemberChain))
+ Offset += Context.toCharUnitsFromBits(Context.getFieldOffset(FD));
// Compute the CompleteObjectAlignment as the alignment of the whole chain.
CharUnits CompleteObjectAlignment = Context.getTypeAlignInChars(
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 46b41a7b0f43..20410a959cd0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3585,9 +3585,8 @@ namespace {
llvm::SmallVector<unsigned, 4> UsedFieldIndex;
// Discard the first field since it is the field decl that is being
// initialized.
- for (auto I = Fields.rbegin() + 1, E = Fields.rend(); I != E; ++I) {
- UsedFieldIndex.push_back((*I)->getFieldIndex());
- }
+ for (const FieldDecl *FD : llvm::drop_begin(llvm::reverse(Fields)))
+ UsedFieldIndex.push_back(FD->getFieldIndex());
for (auto UsedIter = UsedFieldIndex.begin(),
UsedEnd = UsedFieldIndex.end(),
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 8e435d9cb41f..119a90deb9c2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -3501,10 +3501,10 @@ void InitializationSequence::Step::Destroy() {
bool InitializationSequence::isDirectReferenceBinding() const {
// There can be some lvalue adjustments after the SK_BindReference step.
- for (auto I = Steps.rbegin(); I != Steps.rend(); ++I) {
- if (I->Kind == SK_BindReference)
+ for (const Step &S : llvm::reverse(Steps)) {
+ if (S.Kind == SK_BindReference)
return true;
- if (I->Kind == SK_BindReferenceToTemporary)
+ if (S.Kind == SK_BindReferenceToTemporary)
return false;
}
return false;
@@ -6932,10 +6932,10 @@ static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call,
return;
// Once we initialized a value with a reference, it can no longer dangle.
if (!Value) {
- for (auto It = Path.rbegin(), End = Path.rend(); It != End; ++It) {
- if (It->Kind == IndirectLocalPathEntry::GslReferenceInit)
+ for (const IndirectLocalPathEntry &PE : llvm::reverse(Path)) {
+ if (PE.Kind == IndirectLocalPathEntry::GslReferenceInit)
continue;
- if (It->Kind == IndirectLocalPathEntry::GslPointerInit)
+ if (PE.Kind == IndirectLocalPathEntry::GslPointerInit)
return;
break;
}
More information about the cfe-commits
mailing list