r203819 - [C++11] Replacing CXXRecordDecl iterators init_begin() and init_end() with iterator_range inits(). Updating all of the usages of the iterators with range-based for loops.
Aaron Ballman
aaron at aaronballman.com
Thu Mar 13 10:34:31 PDT 2014
Author: aaronballman
Date: Thu Mar 13 12:34:31 2014
New Revision: 203819
URL: http://llvm.org/viewvc/llvm-project?rev=203819&view=rev
Log:
[C++11] Replacing CXXRecordDecl iterators init_begin() and init_end() with iterator_range inits(). Updating all of the usages of the iterators with range-based for loops.
Modified:
cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/IndexDecl.cpp
Modified: cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h Thu Mar 13 12:34:31 2014
@@ -1776,10 +1776,8 @@ bool DataRecursiveASTVisitor<Derived>::T
if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
// Constructor initializers.
- for (CXXConstructorDecl::init_iterator I = Ctor->init_begin(),
- E = Ctor->init_end();
- I != E; ++I) {
- TRY_TO(TraverseConstructorInitializer(*I));
+ for (auto *I : Ctor->inits()) {
+ TRY_TO(TraverseConstructorInitializer(I));
}
}
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Mar 13 12:34:31 2014
@@ -2135,6 +2135,14 @@ public:
/// \brief Iterates through the member/base initializer list.
typedef CXXCtorInitializer * const * init_const_iterator;
+ typedef llvm::iterator_range<init_iterator> init_range;
+ typedef llvm::iterator_range<init_const_iterator> init_const_range;
+
+ init_range inits() { return init_range(init_begin(), init_end()); }
+ init_const_range inits() const {
+ return init_const_range(init_begin(), init_end());
+ }
+
/// \brief Retrieve an iterator to the first initializer.
init_iterator init_begin() { return CtorInitializers; }
/// \brief Retrieve an iterator to the first initializer.
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Thu Mar 13 12:34:31 2014
@@ -1827,10 +1827,8 @@ bool RecursiveASTVisitor<Derived>::Trave
if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
// Constructor initializers.
- for (CXXConstructorDecl::init_iterator I = Ctor->init_begin(),
- E = Ctor->init_end();
- I != E; ++I) {
- TRY_TO(TraverseConstructorInitializer(*I));
+ for (auto *I : Ctor->inits()) {
+ TRY_TO(TraverseConstructorInitializer(I));
}
}
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Mar 13 12:34:31 2014
@@ -3511,11 +3511,9 @@ AST_MATCHER_P(CXXConstructorDecl, forEac
internal::Matcher<CXXCtorInitializer>, InnerMatcher) {
BoundNodesTreeBuilder Result;
bool Matched = false;
- for (CXXConstructorDecl::init_const_iterator I = Node.init_begin(),
- E = Node.init_end();
- I != E; ++I) {
+ for (const auto *I : Node.inits()) {
BoundNodesTreeBuilder InitBuilder(*Builder);
- if (InnerMatcher.matches(**I, Finder, &InitBuilder)) {
+ if (InnerMatcher.matches(*I, Finder, &InitBuilder)) {
Matched = true;
Result.addMatch(InitBuilder);
}
Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Thu Mar 13 12:34:31 2014
@@ -490,10 +490,7 @@ void DeclPrinter::VisitFunctionDecl(Func
if (CDecl) {
bool HasInitializerList = false;
- for (CXXConstructorDecl::init_const_iterator B = CDecl->init_begin(),
- E = CDecl->init_end();
- B != E; ++B) {
- CXXCtorInitializer *BMInitializer = (*B);
+ for (const auto *BMInitializer : CDecl->inits()) {
if (BMInitializer->isInClassMemberInitializer())
continue;
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Mar 13 12:34:31 2014
@@ -3686,15 +3686,14 @@ static bool HandleConstructorCall(Source
#ifndef NDEBUG
CXXRecordDecl::base_class_const_iterator BaseIt = RD->bases_begin();
#endif
- for (CXXConstructorDecl::init_const_iterator I = Definition->init_begin(),
- E = Definition->init_end(); I != E; ++I) {
+ for (const auto *I : Definition->inits()) {
LValue Subobject = This;
APValue *Value = &Result;
// Determine the subobject to initialize.
FieldDecl *FD = 0;
- if ((*I)->isBaseInitializer()) {
- QualType BaseType((*I)->getBaseClass(), 0);
+ if (I->isBaseInitializer()) {
+ QualType BaseType(I->getBaseClass(), 0);
#ifndef NDEBUG
// Non-virtual base classes are initialized in the order in the class
// definition. We have already checked for virtual base classes.
@@ -3703,12 +3702,12 @@ static bool HandleConstructorCall(Source
"base class initializers not in expected order");
++BaseIt;
#endif
- if (!HandleLValueDirectBase(Info, (*I)->getInit(), Subobject, RD,
+ if (!HandleLValueDirectBase(Info, I->getInit(), Subobject, RD,
BaseType->getAsCXXRecordDecl(), &Layout))
return false;
Value = &Result.getStructBase(BasesSeen++);
- } else if ((FD = (*I)->getMember())) {
- if (!HandleLValueMember(Info, (*I)->getInit(), Subobject, FD, &Layout))
+ } else if ((FD = I->getMember())) {
+ if (!HandleLValueMember(Info, I->getInit(), Subobject, FD, &Layout))
return false;
if (RD->isUnion()) {
Result = APValue(FD);
@@ -3716,7 +3715,7 @@ static bool HandleConstructorCall(Source
} else {
Value = &Result.getStructField(FD->getFieldIndex());
}
- } else if (IndirectFieldDecl *IFD = (*I)->getIndirectMember()) {
+ } else if (IndirectFieldDecl *IFD = I->getIndirectMember()) {
// Walk the indirect field decl's chain to find the object to initialize,
// and make sure we've initialized every step along it.
for (auto *C : IFD->chain()) {
@@ -3735,7 +3734,7 @@ static bool HandleConstructorCall(Source
*Value = APValue(APValue::UninitStruct(), CD->getNumBases(),
std::distance(CD->field_begin(), CD->field_end()));
}
- if (!HandleLValueMember(Info, (*I)->getInit(), Subobject, FD))
+ if (!HandleLValueMember(Info, I->getInit(), Subobject, FD))
return false;
if (CD->isUnion())
Value = &Value->getUnionValue();
@@ -3747,8 +3746,8 @@ static bool HandleConstructorCall(Source
}
FullExpressionRAII InitScope(Info);
- if (!EvaluateInPlace(*Value, Info, Subobject, (*I)->getInit()) ||
- (FD && FD->isBitField() && !truncateBitfieldValue(Info, (*I)->getInit(),
+ if (!EvaluateInPlace(*Value, Info, Subobject, I->getInit()) ||
+ (FD && FD->isBitField() && !truncateBitfieldValue(Info, I->getInit(),
*Value, FD))) {
// If we're checking for a potential constant expression, evaluate all
// initializers even if some of them fail.
Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp Thu Mar 13 12:34:31 2014
@@ -242,10 +242,8 @@ ParentMap &AnalysisDeclContext::getParen
if (!PM) {
PM.reset(new ParentMap(getBody()));
if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(getDecl())) {
- for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
- E = C->init_end();
- I != E; ++I) {
- PM->addStmt((*I)->getInit());
+ for (const auto *I : C->inits()) {
+ PM->addStmt(I->getInit());
}
}
if (builtCFG)
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Mar 13 12:34:31 2014
@@ -1155,12 +1155,10 @@ bool Sema::CheckConstexprFunctionBody(co
// always initialized so do not need to be checked. Dependent bases
// might not have initializers in the member initializer list.
llvm::SmallSet<Decl*, 16> Inits;
- for (CXXConstructorDecl::init_const_iterator
- I = Constructor->init_begin(), E = Constructor->init_end();
- I != E; ++I) {
- if (FieldDecl *FD = (*I)->getMember())
+ for (const auto *I: Constructor->inits()) {
+ if (FieldDecl *FD = I->getMember())
Inits.insert(FD);
- else if (IndirectFieldDecl *ID = (*I)->getIndirectMember())
+ else if (IndirectFieldDecl *ID = I->getIndirectMember())
Inits.insert(ID->chain_begin(), ID->chain_end());
}
@@ -2322,17 +2320,13 @@ namespace {
}
}
- for (CXXConstructorDecl::init_const_iterator FieldInit =
- Constructor->init_begin(),
- FieldInitEnd = Constructor->init_end();
- FieldInit != FieldInitEnd; ++FieldInit) {
-
- Expr *InitExpr = (*FieldInit)->getInit();
+ for (const auto *FieldInit : Constructor->inits()) {
+ Expr *InitExpr = FieldInit->getInit();
CheckInitExprContainsUninitializedFields(
SemaRef, InitExpr, UninitializedFields, Constructor);
- if (FieldDecl *Field = (*FieldInit)->getAnyMember())
+ if (FieldDecl *Field = FieldInit->getAnyMember())
UninitializedFields.erase(Field);
}
}
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Mar 13 12:34:31 2014
@@ -4005,11 +4005,7 @@ Sema::InstantiateMemInitializers(CXXCons
bool AnyErrors = Tmpl->isInvalidDecl();
// Instantiate all the initializers.
- for (CXXConstructorDecl::init_const_iterator Inits = Tmpl->init_begin(),
- InitsEnd = Tmpl->init_end();
- Inits != InitsEnd; ++Inits) {
- CXXCtorInitializer *Init = *Inits;
-
+ for (const auto *Init : Tmpl->inits()) {
// Only instantiate written initializers, let Sema re-construct implicit
// ones.
if (!Init->isWritten())
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Mar 13 12:34:31 2014
@@ -812,13 +812,11 @@ bool CursorVisitor::VisitFunctionDecl(Fu
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ND)) {
// Find the initializers that were written in the source.
SmallVector<CXXCtorInitializer *, 4> WrittenInits;
- for (CXXConstructorDecl::init_iterator I = Constructor->init_begin(),
- IEnd = Constructor->init_end();
- I != IEnd; ++I) {
- if (!(*I)->isWritten())
+ for (auto *I : Constructor->inits()) {
+ if (!I->isWritten())
continue;
- WrittenInits.push_back(*I);
+ WrittenInits.push_back(I);
}
// Sort the initializers in source order
Modified: cfe/trunk/tools/libclang/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexDecl.cpp?rev=203819&r1=203818&r2=203819&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Thu Mar 13 12:34:31 2014
@@ -71,10 +71,7 @@ public:
if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
// Constructor initializers.
- for (CXXConstructorDecl::init_const_iterator I = Ctor->init_begin(),
- E = Ctor->init_end();
- I != E; ++I) {
- CXXCtorInitializer *Init = *I;
+ for (const auto *Init : Ctor->inits()) {
if (Init->isWritten()) {
IndexCtx.indexTypeSourceInfo(Init->getTypeSourceInfo(), D);
if (const FieldDecl *Member = Init->getAnyMember())
More information about the cfe-commits
mailing list