r273522 - Use ranges to concisely express iteration
David Majnemer via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 22 17:15:05 PDT 2016
Author: majnemer
Date: Wed Jun 22 19:15:04 2016
New Revision: 273522
URL: http://llvm.org/viewvc/llvm-project?rev=273522&view=rev
Log:
Use ranges to concisely express iteration
No functional change is intended, this should just clean things up a
little.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Index/IndexBody.cpp
cfe/trunk/lib/Sema/ScopeInfo.cpp
cfe/trunk/lib/Sema/SemaAttr.cpp
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Jun 22 19:15:04 2016
@@ -3970,11 +3970,10 @@ private:
/// expression.
Designator *Designators;
-
- DesignatedInitExpr(const ASTContext &C, QualType Ty, unsigned NumDesignators,
- const Designator *Designators,
+ DesignatedInitExpr(const ASTContext &C, QualType Ty,
+ llvm::ArrayRef<Designator> Designators,
SourceLocation EqualOrColonLoc, bool GNUSyntax,
- ArrayRef<Expr*> IndexExprs, Expr *Init);
+ ArrayRef<Expr *> IndexExprs, Expr *Init);
explicit DesignatedInitExpr(unsigned NumSubExprs)
: Expr(DesignatedInitExprClass, EmptyShell()),
@@ -4134,8 +4133,7 @@ public:
};
static DesignatedInitExpr *Create(const ASTContext &C,
- Designator *Designators,
- unsigned NumDesignators,
+ llvm::ArrayRef<Designator> Designators,
ArrayRef<Expr*> IndexExprs,
SourceLocation EqualOrColonLoc,
bool GNUSyntax, Expr *Init);
@@ -4147,48 +4145,15 @@ public:
unsigned size() const { return NumDesignators; }
// Iterator access to the designators.
- typedef Designator *designators_iterator;
- designators_iterator designators_begin() { return Designators; }
- designators_iterator designators_end() {
- return Designators + NumDesignators;
- }
-
- typedef const Designator *const_designators_iterator;
- const_designators_iterator designators_begin() const { return Designators; }
- const_designators_iterator designators_end() const {
- return Designators + NumDesignators;
+ llvm::MutableArrayRef<Designator> designators() {
+ return {Designators, NumDesignators};
}
- typedef llvm::iterator_range<designators_iterator> designators_range;
- designators_range designators() {
- return designators_range(designators_begin(), designators_end());
- }
-
- typedef llvm::iterator_range<const_designators_iterator>
- designators_const_range;
- designators_const_range designators() const {
- return designators_const_range(designators_begin(), designators_end());
- }
-
- typedef std::reverse_iterator<designators_iterator>
- reverse_designators_iterator;
- reverse_designators_iterator designators_rbegin() {
- return reverse_designators_iterator(designators_end());
- }
- reverse_designators_iterator designators_rend() {
- return reverse_designators_iterator(designators_begin());
- }
-
- typedef std::reverse_iterator<const_designators_iterator>
- const_reverse_designators_iterator;
- const_reverse_designators_iterator designators_rbegin() const {
- return const_reverse_designators_iterator(designators_end());
- }
- const_reverse_designators_iterator designators_rend() const {
- return const_reverse_designators_iterator(designators_begin());
+ llvm::ArrayRef<Designator> designators() const {
+ return {Designators, NumDesignators};
}
- Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
+ Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
void setDesignators(const ASTContext &C, const Designator *Desigs,
unsigned NumDesigs);
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Jun 22 19:15:04 2016
@@ -5430,19 +5430,17 @@ Expr *ASTNodeImporter::VisitDesignatedIn
}
SmallVector<Designator, 4> Designators(DIE->size());
- std::transform(DIE->designators_begin(), DIE->designators_end(),
- Designators.begin(),
- [this](const Designator &D) -> Designator {
- return ImportDesignator(D);
- });
+ llvm::transform(DIE->designators(), Designators.begin(),
+ [this](const Designator &D) -> Designator {
+ return ImportDesignator(D);
+ });
- for (auto I = DIE->designators_begin(), E = DIE->designators_end(); I != E;
- ++I)
- if (I->isFieldDesignator() && !I->getFieldName())
+ for (const Designator &D : DIE->designators())
+ if (D.isFieldDesignator() && !D.getFieldName())
return nullptr;
return DesignatedInitExpr::Create(
- Importer.getToContext(), Designators.data(), Designators.size(),
+ Importer.getToContext(), Designators,
IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()),
DIE->usesGNUSyntax(), Init);
}
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Jun 22 19:15:04 2016
@@ -1422,16 +1422,15 @@ void NamedDecl::printQualifiedName(raw_o
Ctx = Ctx->getParent();
}
- for (ContextsTy::reverse_iterator I = Contexts.rbegin(), E = Contexts.rend();
- I != E; ++I) {
- if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(*I)) {
+ for (const DeclContext *DC : reverse(Contexts)) {
+ if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
OS << Spec->getName();
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
TemplateSpecializationType::PrintTemplateArgumentList(OS,
TemplateArgs.data(),
TemplateArgs.size(),
P);
- } else if (const auto *ND = dyn_cast<NamespaceDecl>(*I)) {
+ } else if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) {
if (P.SuppressUnwrittenScope &&
(ND->isAnonymousNamespace() || ND->isInline()))
continue;
@@ -1441,12 +1440,12 @@ void NamedDecl::printQualifiedName(raw_o
}
else
OS << *ND;
- } else if (const auto *RD = dyn_cast<RecordDecl>(*I)) {
+ } else if (const auto *RD = dyn_cast<RecordDecl>(DC)) {
if (!RD->getIdentifier())
OS << "(anonymous " << RD->getKindName() << ')';
else
OS << *RD;
- } else if (const auto *FD = dyn_cast<FunctionDecl>(*I)) {
+ } else if (const auto *FD = dyn_cast<FunctionDecl>(DC)) {
const FunctionProtoType *FT = nullptr;
if (FD->hasWrittenPrototype())
FT = dyn_cast<FunctionProtoType>(FD->getType()->castAs<FunctionType>());
@@ -1467,7 +1466,7 @@ void NamedDecl::printQualifiedName(raw_o
}
}
OS << ')';
- } else if (const auto *ED = dyn_cast<EnumDecl>(*I)) {
+ } else if (const auto *ED = dyn_cast<EnumDecl>(DC)) {
// C++ [dcl.enum]p10: Each enum-name and each unscoped
// enumerator is declared in the scope that immediately contains
// the enum-specifier. Each scoped enumerator is declared in the
@@ -1477,7 +1476,7 @@ void NamedDecl::printQualifiedName(raw_o
else
continue;
} else {
- OS << *cast<NamedDecl>(*I);
+ OS << *cast<NamedDecl>(DC);
}
OS << "::";
}
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Jun 22 19:15:04 2016
@@ -3510,8 +3510,7 @@ IdentifierInfo *DesignatedInitExpr::Desi
}
DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty,
- unsigned NumDesignators,
- const Designator *Designators,
+ llvm::ArrayRef<Designator> Designators,
SourceLocation EqualOrColonLoc,
bool GNUSyntax,
ArrayRef<Expr*> IndexExprs,
@@ -3522,7 +3521,7 @@ DesignatedInitExpr::DesignatedInitExpr(c
Init->isInstantiationDependent(),
Init->containsUnexpandedParameterPack()),
EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
- NumDesignators(NumDesignators), NumSubExprs(IndexExprs.size() + 1) {
+ NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) {
this->Designators = new (C) Designator[NumDesignators];
// Record the initializer itself.
@@ -3576,14 +3575,14 @@ DesignatedInitExpr::DesignatedInitExpr(c
}
DesignatedInitExpr *
-DesignatedInitExpr::Create(const ASTContext &C, Designator *Designators,
- unsigned NumDesignators,
+DesignatedInitExpr::Create(const ASTContext &C,
+ llvm::ArrayRef<Designator> Designators,
ArrayRef<Expr*> IndexExprs,
SourceLocation ColonOrEqualLoc,
bool UsesColonSyntax, Expr *Init) {
void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1),
llvm::alignOf<DesignatedInitExpr>());
- return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators,
+ return new (Mem) DesignatedInitExpr(C, C.VoidTy, Designators,
ColonOrEqualLoc, UsesColonSyntax,
IndexExprs, Init);
}
@@ -3614,8 +3613,8 @@ SourceRange DesignatedInitExpr::getDesig
SourceLocation DesignatedInitExpr::getLocStart() const {
SourceLocation StartLoc;
- Designator &First =
- *const_cast<DesignatedInitExpr*>(this)->designators_begin();
+ auto *DIE = const_cast<DesignatedInitExpr *>(this);
+ Designator &First = *DIE->getDesignator(0);
if (First.isFieldDesignator()) {
if (GNUSyntax)
StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc);
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Wed Jun 22 19:15:04 2016
@@ -1642,26 +1642,24 @@ void StmtPrinter::VisitParenListExpr(Par
void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
bool NeedsEquals = true;
- for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
- DEnd = Node->designators_end();
- D != DEnd; ++D) {
- if (D->isFieldDesignator()) {
- if (D->getDotLoc().isInvalid()) {
- if (IdentifierInfo *II = D->getFieldName()) {
+ for (const DesignatedInitExpr::Designator &D : Node->designators()) {
+ if (D.isFieldDesignator()) {
+ if (D.getDotLoc().isInvalid()) {
+ if (IdentifierInfo *II = D.getFieldName()) {
OS << II->getName() << ":";
NeedsEquals = false;
}
} else {
- OS << "." << D->getFieldName()->getName();
+ OS << "." << D.getFieldName()->getName();
}
} else {
OS << "[";
- if (D->isArrayDesignator()) {
- PrintExpr(Node->getArrayIndex(*D));
+ if (D.isArrayDesignator()) {
+ PrintExpr(Node->getArrayIndex(D));
} else {
- PrintExpr(Node->getArrayRangeStart(*D));
+ PrintExpr(Node->getArrayRangeStart(D));
OS << " ... ";
- PrintExpr(Node->getArrayRangeEnd(*D));
+ PrintExpr(Node->getArrayRangeEnd(D));
}
OS << "]";
}
Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Wed Jun 22 19:15:04 2016
@@ -898,22 +898,20 @@ void StmtProfiler::VisitInitListExpr(con
void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
VisitExpr(S);
ID.AddBoolean(S->usesGNUSyntax());
- for (DesignatedInitExpr::const_designators_iterator D =
- S->designators_begin(), DEnd = S->designators_end();
- D != DEnd; ++D) {
- if (D->isFieldDesignator()) {
+ for (const DesignatedInitExpr::Designator &D : S->designators()) {
+ if (D.isFieldDesignator()) {
ID.AddInteger(0);
- VisitName(D->getFieldName());
+ VisitName(D.getFieldName());
continue;
}
- if (D->isArrayDesignator()) {
+ if (D.isArrayDesignator()) {
ID.AddInteger(1);
} else {
- assert(D->isArrayRangeDesignator());
+ assert(D.isArrayRangeDesignator());
ID.AddInteger(2);
}
- ID.AddInteger(D->getFirstExprIndex());
+ ID.AddInteger(D.getFirstExprIndex());
}
}
Modified: cfe/trunk/lib/Index/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexBody.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexBody.cpp (original)
+++ cfe/trunk/lib/Index/IndexBody.cpp Wed Jun 22 19:15:04 2016
@@ -147,13 +147,10 @@ public:
}
bool VisitDesignatedInitExpr(DesignatedInitExpr *E) {
- for (DesignatedInitExpr::reverse_designators_iterator
- D = E->designators_rbegin(), DEnd = E->designators_rend();
- D != DEnd; ++D) {
- if (D->isFieldDesignator())
- return IndexCtx.handleReference(D->getField(), D->getFieldLoc(),
- Parent, ParentDC, SymbolRoleSet(),
- {}, E);
+ for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) {
+ if (D.isFieldDesignator())
+ return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), Parent,
+ ParentDC, SymbolRoleSet(), {}, E);
}
return true;
}
@@ -311,11 +308,9 @@ public:
bool shouldWalkTypesOfTypeLocs() const { return false; }
bool VisitDesignatedInitExpr(DesignatedInitExpr *E) {
- for (DesignatedInitExpr::reverse_designators_iterator
- D = E->designators_rbegin(), DEnd = E->designators_rend();
- D != DEnd; ++D) {
- if (D->isFieldDesignator())
- return IndexCtx.handleReference(D->getField(), D->getFieldLoc(),
+ for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) {
+ if (D.isFieldDesignator())
+ return IndexCtx.handleReference(D.getField(), D.getFieldLoc(),
Parent, ParentDC, SymbolRoleSet(),
{}, E);
}
Modified: cfe/trunk/lib/Sema/ScopeInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ScopeInfo.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/ScopeInfo.cpp (original)
+++ cfe/trunk/lib/Sema/ScopeInfo.cpp Wed Jun 22 19:15:04 2016
@@ -215,7 +215,7 @@ void FunctionScopeInfo::markSafeWeakUse(
// Has there been a read from the object using this Expr?
FunctionScopeInfo::WeakUseVector::reverse_iterator ThisUse =
- std::find(Uses->second.rbegin(), Uses->second.rend(), WeakUseTy(E, true));
+ llvm::find(llvm::reverse(Uses->second), WeakUseTy(E, true));
if (ThisUse == Uses->second.rend())
return;
Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Wed Jun 22 19:15:04 2016
@@ -222,8 +222,9 @@ void Sema::PragmaStack<ValueType>::Act(S
else if (Action & PSK_Pop) {
if (!StackSlotLabel.empty()) {
// If we've got a label, try to find it and jump there.
- auto I = std::find_if(Stack.rbegin(), Stack.rend(),
- [&](const Slot &x) { return x.StackSlotLabel == StackSlotLabel; });
+ auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
+ return x.StackSlotLabel == StackSlotLabel;
+ });
// If we found the label so pop from there.
if (I != Stack.rend()) {
CurrentValue = I->Value;
Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Wed Jun 22 19:15:04 2016
@@ -1314,16 +1314,13 @@ TryStaticDowncast(Sema &Self, CanQualTyp
}
std::string PathDisplayStr;
std::set<unsigned> DisplayedPaths;
- for (CXXBasePaths::paths_iterator PI = Paths.begin(), PE = Paths.end();
- PI != PE; ++PI) {
- if (DisplayedPaths.insert(PI->back().SubobjectNumber).second) {
+ for (clang::CXXBasePath &Path : Paths) {
+ if (DisplayedPaths.insert(Path.back().SubobjectNumber).second) {
// We haven't displayed a path to this particular base
// class subobject yet.
PathDisplayStr += "\n ";
- for (CXXBasePath::const_reverse_iterator EI = PI->rbegin(),
- EE = PI->rend();
- EI != EE; ++EI)
- PathDisplayStr += EI->Base->getType().getAsString() + " -> ";
+ for (CXXBasePathElement &PE : llvm::reverse(Path))
+ PathDisplayStr += PE.Base->getType().getAsString() + " -> ";
PathDisplayStr += QualType(DestType).getAsString();
}
}
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Jun 22 19:15:04 2016
@@ -8770,12 +8770,11 @@ class SequenceChecker : public Evaluated
Self.ModAsSideEffect = &ModAsSideEffect;
}
~SequencedSubexpression() {
- for (auto MI = ModAsSideEffect.rbegin(), ME = ModAsSideEffect.rend();
- MI != ME; ++MI) {
- UsageInfo &U = Self.UsageMap[MI->first];
+ for (auto &M : llvm::reverse(ModAsSideEffect)) {
+ UsageInfo &U = Self.UsageMap[M.first];
auto &SideEffectUsage = U.Uses[UK_ModAsSideEffect];
- Self.addUsage(U, MI->first, SideEffectUsage.Use, UK_ModAsValue);
- SideEffectUsage = MI->second;
+ Self.addUsage(U, M.first, SideEffectUsage.Use, UK_ModAsValue);
+ SideEffectUsage = M.second;
}
Self.ModAsSideEffect = OldModAsSideEffect;
}
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jun 22 19:15:04 2016
@@ -1976,8 +1976,8 @@ static DesignatedInitExpr *CloneDesignat
SmallVector<Expr*, 4> IndexExprs(NumIndexExprs);
for (unsigned I = 0; I < NumIndexExprs; ++I)
IndexExprs[I] = DIE->getSubExpr(I + 1);
- return DesignatedInitExpr::Create(SemaRef.Context, DIE->designators_begin(),
- DIE->size(), IndexExprs,
+ return DesignatedInitExpr::Create(SemaRef.Context, DIE->designators(),
+ IndexExprs,
DIE->getEqualOrColonLoc(),
DIE->usesGNUSyntax(), DIE->getInit());
}
@@ -2837,7 +2837,7 @@ ExprResult Sema::ActOnDesignatedInitiali
DesignatedInitExpr *DIE
= DesignatedInitExpr::Create(Context,
- Designators.data(), Designators.size(),
+ Designators,
InitExpressions, Loc, GNUSyntax,
Init.getAs<Expr>());
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Jun 22 19:15:04 2016
@@ -4152,10 +4152,8 @@ TypoCorrectionConsumer::NamespaceSpecifi
// Build the list of identifiers that would be used for an absolute
// (from the global context) NestedNameSpecifier referring to the current
// context.
- for (DeclContextList::reverse_iterator C = CurContextChain.rbegin(),
- CEnd = CurContextChain.rend();
- C != CEnd; ++C) {
- if (NamespaceDecl *ND = dyn_cast_or_null<NamespaceDecl>(*C))
+ for (DeclContext *C : llvm::reverse(CurContextChain)) {
+ if (auto *ND = dyn_cast_or_null<NamespaceDecl>(C))
CurContextIdentifiers.push_back(ND->getIdentifier());
}
@@ -4183,13 +4181,11 @@ unsigned
TypoCorrectionConsumer::NamespaceSpecifierSet::buildNestedNameSpecifier(
DeclContextList &DeclChain, NestedNameSpecifier *&NNS) {
unsigned NumSpecifiers = 0;
- for (DeclContextList::reverse_iterator C = DeclChain.rbegin(),
- CEnd = DeclChain.rend();
- C != CEnd; ++C) {
- if (NamespaceDecl *ND = dyn_cast_or_null<NamespaceDecl>(*C)) {
+ for (DeclContext *C : llvm::reverse(DeclChain)) {
+ if (auto *ND = dyn_cast_or_null<NamespaceDecl>(C)) {
NNS = NestedNameSpecifier::Create(Context, NNS, ND);
++NumSpecifiers;
- } else if (RecordDecl *RD = dyn_cast_or_null<RecordDecl>(*C)) {
+ } else if (auto *RD = dyn_cast_or_null<RecordDecl>(C)) {
NNS = NestedNameSpecifier::Create(Context, NNS, RD->isTemplateDecl(),
RD->getTypeForDecl());
++NumSpecifiers;
@@ -4206,10 +4202,9 @@ void TypoCorrectionConsumer::NamespaceSp
DeclContextList FullNamespaceDeclChain(NamespaceDeclChain);
// Eliminate common elements from the two DeclContext chains.
- for (DeclContextList::reverse_iterator C = CurContextChain.rbegin(),
- CEnd = CurContextChain.rend();
- C != CEnd && !NamespaceDeclChain.empty() &&
- NamespaceDeclChain.back() == *C; ++C) {
+ for (DeclContext *C : llvm::reverse(CurContextChain)) {
+ if (NamespaceDeclChain.empty() || NamespaceDeclChain.back() != C)
+ break;
NamespaceDeclChain.pop_back();
}
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Wed Jun 22 19:15:04 2016
@@ -8780,46 +8780,44 @@ TreeTransform<Derived>::TransformDesigna
// transform the designators.
SmallVector<Expr*, 4> ArrayExprs;
bool ExprChanged = false;
- for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
- DEnd = E->designators_end();
- D != DEnd; ++D) {
- if (D->isFieldDesignator()) {
- Desig.AddDesignator(Designator::getField(D->getFieldName(),
- D->getDotLoc(),
- D->getFieldLoc()));
+ for (const DesignatedInitExpr::Designator &D : E->designators()) {
+ if (D.isFieldDesignator()) {
+ Desig.AddDesignator(Designator::getField(D.getFieldName(),
+ D.getDotLoc(),
+ D.getFieldLoc()));
continue;
}
- if (D->isArrayDesignator()) {
- ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
+ if (D.isArrayDesignator()) {
+ ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
if (Index.isInvalid())
return ExprError();
- Desig.AddDesignator(Designator::getArray(Index.get(),
- D->getLBracketLoc()));
+ Desig.AddDesignator(
+ Designator::getArray(Index.get(), D.getLBracketLoc()));
- ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
+ ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
ArrayExprs.push_back(Index.get());
continue;
}
- assert(D->isArrayRangeDesignator() && "New kind of designator?");
+ assert(D.isArrayRangeDesignator() && "New kind of designator?");
ExprResult Start
- = getDerived().TransformExpr(E->getArrayRangeStart(*D));
+ = getDerived().TransformExpr(E->getArrayRangeStart(D));
if (Start.isInvalid())
return ExprError();
- ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
+ ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
if (End.isInvalid())
return ExprError();
Desig.AddDesignator(Designator::getArrayRange(Start.get(),
End.get(),
- D->getLBracketLoc(),
- D->getEllipsisLoc()));
+ D.getLBracketLoc(),
+ D.getEllipsisLoc()));
- ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
- End.get() != E->getArrayRangeEnd(*D);
+ ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
+ End.get() != E->getArrayRangeEnd(D);
ArrayExprs.push_back(Start.get());
ArrayExprs.push_back(End.get());
Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Wed Jun 22 19:15:04 2016
@@ -749,31 +749,29 @@ void ASTStmtWriter::VisitDesignatedInitE
Record.AddStmt(E->getSubExpr(I));
Record.AddSourceLocation(E->getEqualOrColonLoc());
Record.push_back(E->usesGNUSyntax());
- for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
- DEnd = E->designators_end();
- D != DEnd; ++D) {
- if (D->isFieldDesignator()) {
- if (FieldDecl *Field = D->getField()) {
+ for (const DesignatedInitExpr::Designator &D : E->designators()) {
+ if (D.isFieldDesignator()) {
+ if (FieldDecl *Field = D.getField()) {
Record.push_back(serialization::DESIG_FIELD_DECL);
Record.AddDeclRef(Field);
} else {
Record.push_back(serialization::DESIG_FIELD_NAME);
- Record.AddIdentifierRef(D->getFieldName());
+ Record.AddIdentifierRef(D.getFieldName());
}
- Record.AddSourceLocation(D->getDotLoc());
- Record.AddSourceLocation(D->getFieldLoc());
- } else if (D->isArrayDesignator()) {
+ Record.AddSourceLocation(D.getDotLoc());
+ Record.AddSourceLocation(D.getFieldLoc());
+ } else if (D.isArrayDesignator()) {
Record.push_back(serialization::DESIG_ARRAY);
- Record.push_back(D->getFirstExprIndex());
- Record.AddSourceLocation(D->getLBracketLoc());
- Record.AddSourceLocation(D->getRBracketLoc());
+ Record.push_back(D.getFirstExprIndex());
+ Record.AddSourceLocation(D.getLBracketLoc());
+ Record.AddSourceLocation(D.getRBracketLoc());
} else {
- assert(D->isArrayRangeDesignator() && "Unknown designator");
+ assert(D.isArrayRangeDesignator() && "Unknown designator");
Record.push_back(serialization::DESIG_ARRAY_RANGE);
- Record.push_back(D->getFirstExprIndex());
- Record.AddSourceLocation(D->getLBracketLoc());
- Record.AddSourceLocation(D->getEllipsisLoc());
- Record.AddSourceLocation(D->getRBracketLoc());
+ Record.push_back(D.getFirstExprIndex());
+ Record.AddSourceLocation(D.getLBracketLoc());
+ Record.AddSourceLocation(D.getEllipsisLoc());
+ Record.AddSourceLocation(D.getRBracketLoc());
}
}
Code = serialization::EXPR_DESIGNATED_INIT;
Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Wed Jun 22 19:15:04 2016
@@ -320,11 +320,11 @@ void ModuleManager::visit(llvm::function
Queue.reserve(N);
llvm::SmallVector<unsigned, 4> UnusedIncomingEdges;
UnusedIncomingEdges.resize(size());
- for (auto M = rbegin(), MEnd = rend(); M != MEnd; ++M) {
- unsigned Size = (*M)->ImportedBy.size();
- UnusedIncomingEdges[(*M)->Index] = Size;
+ for (ModuleFile *M : llvm::reverse(*this)) {
+ unsigned Size = M->ImportedBy.size();
+ UnusedIncomingEdges[M->Index] = Size;
if (!Size)
- Queue.push_back(*M);
+ Queue.push_back(M);
}
// Traverse the graph, making sure to visit a module before visiting any
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Jun 22 19:15:04 2016
@@ -2400,21 +2400,20 @@ void EnqueueVisitor::VisitDeclStmt(const
}
void EnqueueVisitor::VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
AddStmt(E->getInit());
- for (DesignatedInitExpr::const_reverse_designators_iterator
- D = E->designators_rbegin(), DEnd = E->designators_rend();
- D != DEnd; ++D) {
- if (D->isFieldDesignator()) {
- if (FieldDecl *Field = D->getField())
- AddMemberRef(Field, D->getFieldLoc());
+ for (const DesignatedInitExpr::Designator &D :
+ llvm::reverse(E->designators())) {
+ if (D.isFieldDesignator()) {
+ if (FieldDecl *Field = D.getField())
+ AddMemberRef(Field, D.getFieldLoc());
continue;
}
- if (D->isArrayDesignator()) {
- AddStmt(E->getArrayIndex(*D));
+ if (D.isArrayDesignator()) {
+ AddStmt(E->getArrayIndex(D));
continue;
}
- assert(D->isArrayRangeDesignator() && "Unknown designator kind");
- AddStmt(E->getArrayRangeEnd(*D));
- AddStmt(E->getArrayRangeStart(*D));
+ assert(D.isArrayRangeDesignator() && "Unknown designator kind");
+ AddStmt(E->getArrayRangeEnd(D));
+ AddStmt(E->getArrayRangeStart(D));
}
}
void EnqueueVisitor::VisitExplicitCastExpr(const ExplicitCastExpr *E) {
Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=273522&r1=273521&r2=273522&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed Jun 22 19:15:04 2016
@@ -1212,7 +1212,7 @@ createArgument(const Record &Arg, String
if (!Ptr) {
// Search in reverse order so that the most-derived type is handled first.
ArrayRef<std::pair<Record*, SMRange>> Bases = Search->getSuperClasses();
- for (const auto &Base : llvm::make_range(Bases.rbegin(), Bases.rend())) {
+ for (const auto &Base : llvm::reverse(Bases)) {
if ((Ptr = createArgument(Arg, Attr, Base.first)))
break;
}
@@ -1630,7 +1630,7 @@ void EmitClangAttrClass(RecordKeeper &Re
ArrayRef<std::pair<Record *, SMRange>> Supers = R.getSuperClasses();
assert(!Supers.empty() && "Forgot to specify a superclass for the attr");
std::string SuperName;
- for (const auto &Super : llvm::make_range(Supers.rbegin(), Supers.rend())) {
+ for (const auto &Super : llvm::reverse(Supers)) {
const Record *R = Super.first;
if (R->getName() != "TargetSpecificAttr" && SuperName.empty())
SuperName = R->getName();
More information about the cfe-commits
mailing list