r203248 - [C++11] Replacing FunctionDecl iterators param_begin() and param_end() with iterator_range params(). Updating all of the usages of the iterators with range-based for loops.
Aaron Ballman
aaron at aaronballman.com
Fri Mar 7 07:12:57 PST 2014
Author: aaronballman
Date: Fri Mar 7 09:12:56 2014
New Revision: 203248
URL: http://llvm.org/viewvc/llvm-project?rev=203248&view=rev
Log:
[C++11] Replacing FunctionDecl iterators param_begin() and param_end() with iterator_range params(). Updating all of the usages of the iterators with range-based for loops.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/Analysis/Consumed.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
cfe/trunk/tools/libclang/IndexDecl.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Mar 7 09:12:56 2014
@@ -1843,12 +1843,20 @@ public:
unsigned param_size() const { return getNumParams(); }
typedef ParmVarDecl **param_iterator;
typedef ParmVarDecl * const *param_const_iterator;
+ typedef llvm::iterator_range<param_iterator> param_range;
+ typedef llvm::iterator_range<param_const_iterator> param_const_range;
- param_iterator param_begin() { return ParamInfo; }
- param_iterator param_end() { return ParamInfo+param_size(); }
+ param_iterator param_begin() { return params().begin(); }
+ param_iterator param_end() { return params().end(); }
+ param_range params() {
+ return param_range(ParamInfo, ParamInfo + param_size());
+ }
- param_const_iterator param_begin() const { return ParamInfo; }
- param_const_iterator param_end() const { return ParamInfo+param_size(); }
+ param_const_iterator param_begin() const { return params().begin(); }
+ param_const_iterator param_end() const { return params().end(); }
+ param_const_range params() const {
+ return param_const_range(ParamInfo, ParamInfo + param_size());
+ }
/// getNumParams - Return the number of parameters this function must have
/// based on its FunctionType. This is the length of the ParamInfo array
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Mar 7 09:12:56 2014
@@ -4850,9 +4850,8 @@ bool ASTContext::getObjCEncodingForFunct
getObjCEncodingForType(Decl->getReturnType(), S);
CharUnits ParmOffset;
// Compute size of all parameters.
- for (FunctionDecl::param_const_iterator PI = Decl->param_begin(),
- E = Decl->param_end(); PI != E; ++PI) {
- QualType PType = (*PI)->getType();
+ for (auto PI : Decl->params()) {
+ QualType PType = PI->getType();
CharUnits sz = getObjCEncodingTypeSize(PType);
if (sz.isZero())
continue;
@@ -4865,9 +4864,7 @@ bool ASTContext::getObjCEncodingForFunct
ParmOffset = CharUnits::Zero();
// Argument types.
- for (FunctionDecl::param_const_iterator PI = Decl->param_begin(),
- E = Decl->param_end(); PI != E; ++PI) {
- ParmVarDecl *PVDecl = *PI;
+ for (auto PVDecl : Decl->params()) {
QualType PType = PVDecl->getOriginalType();
if (const ArrayType *AT =
dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) {
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Fri Mar 7 09:12:56 2014
@@ -2743,9 +2743,8 @@ Decl *ASTNodeImporter::VisitFunctionDecl
// Import the function parameters.
SmallVector<ParmVarDecl *, 8> Parameters;
- for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
- P != PEnd; ++P) {
- ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(*P));
+ for (auto P : D->params()) {
+ ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P));
if (!ToP)
return 0;
Modified: cfe/trunk/lib/Analysis/Consumed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Consumed.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/Consumed.cpp (original)
+++ cfe/trunk/lib/Analysis/Consumed.cpp Fri Mar 7 09:12:56 2014
@@ -1388,9 +1388,8 @@ void ConsumedAnalyzer::run(AnalysisDeclC
ConsumedStmtVisitor Visitor(AC, *this, CurrStates);
// Add all trackable parameters to the state map.
- for (FunctionDecl::param_const_iterator PI = D->param_begin(),
- PE = D->param_end(); PI != PE; ++PI) {
- Visitor.VisitParmVarDecl(*PI);
+ for (auto PI : D->params()) {
+ Visitor.VisitParmVarDecl(PI);
}
// Visit all of the function's basic blocks.
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Mar 7 09:12:56 2014
@@ -2195,11 +2195,9 @@ void CodeGenFunction::EmitLambdaDelegati
CallArgs.add(RValue::get(ThisPtr), ThisType);
// Add the rest of the parameters.
- for (FunctionDecl::param_const_iterator I = MD->param_begin(),
- E = MD->param_end(); I != E; ++I) {
- ParmVarDecl *param = *I;
- EmitDelegateCallArg(CallArgs, param, param->getLocStart());
- }
+ for (auto Param : MD->params())
+ EmitDelegateCallArg(CallArgs, Param, Param->getLocStart());
+
const CXXMethodDecl *CallOp = Lambda->getLambdaCallOperator();
// For a generic lambda, find the corresponding call operator specialization
// to which the call to the static-invoker shall be forwarded.
Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Fri Mar 7 09:12:56 2014
@@ -259,13 +259,12 @@ void DeclContextPrinter::PrintDeclContex
// Print the parameters.
Out << "(";
bool PrintComma = false;
- for (FunctionDecl::param_const_iterator I = FD->param_begin(),
- E = FD->param_end(); I != E; ++I) {
+ for (auto I : FD->params()) {
if (PrintComma)
Out << ", ";
else
PrintComma = true;
- Out << **I;
+ Out << *I;
}
Out << ")";
break;
Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Fri Mar 7 09:12:56 2014
@@ -205,12 +205,9 @@ void USRGenerator::VisitFunctionDecl(con
}
// Mangle in type information for the arguments.
- for (FunctionDecl::param_const_iterator I = D->param_begin(),
- E = D->param_end();
- I != E; ++I) {
+ for (auto PD : D->params()) {
Out << '#';
- if (ParmVarDecl *PD = *I)
- VisitType(PD->getType());
+ VisitType(PD->getType());
}
if (D->isVariadic())
Out << '.';
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar 7 09:12:56 2014
@@ -7326,11 +7326,8 @@ Sema::ActOnFunctionDeclarator(Scope *S,
}
llvm::SmallPtrSet<const Type *, 16> ValidTypes;
- for (FunctionDecl::param_iterator PI = NewFD->param_begin(),
- PE = NewFD->param_end(); PI != PE; ++PI) {
- ParmVarDecl *Param = *PI;
+ for (auto Param : NewFD->params())
checkIsValidOpenCLKernelParameter(*this, D, Param, ValidTypes);
- }
}
MarkUnusedFileScopedDecl(NewFD);
@@ -9599,8 +9596,7 @@ Decl *Sema::ActOnStartOfFunctionDef(Scop
/*CheckParameterNames=*/true);
// Introduce our parameters into the function scope
- for (unsigned p = 0, NumParams = FD->getNumParams(); p < NumParams; ++p) {
- ParmVarDecl *Param = FD->getParamDecl(p);
+ for (auto Param : FD->params()) {
Param->setOwningFunction(FD);
// If this has an identifier, add it to the scope stack.
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Mar 7 09:12:56 2014
@@ -10810,10 +10810,8 @@ bool Sema::CheckOverloadedOperatorDeclar
diag::err_operator_overload_static) << FnDecl->getDeclName();
} else {
bool ClassOrEnumParam = false;
- for (FunctionDecl::param_iterator Param = FnDecl->param_begin(),
- ParamEnd = FnDecl->param_end();
- Param != ParamEnd; ++Param) {
- QualType ParamType = (*Param)->getType().getNonReferenceType();
+ for (auto Param : FnDecl->params()) {
+ QualType ParamType = Param->getType().getNonReferenceType();
if (ParamType->isDependentType() || ParamType->isRecordType() ||
ParamType->isEnumeralType()) {
ClassOrEnumParam = true;
@@ -10834,12 +10832,11 @@ bool Sema::CheckOverloadedOperatorDeclar
// Only the function-call operator allows default arguments
// (C++ [over.call]p1).
if (Op != OO_Call) {
- for (FunctionDecl::param_iterator Param = FnDecl->param_begin();
- Param != FnDecl->param_end(); ++Param) {
- if ((*Param)->hasDefaultArg())
- return Diag((*Param)->getLocation(),
+ for (auto Param : FnDecl->params()) {
+ if (Param->hasDefaultArg())
+ return Diag(Param->getLocation(),
diag::err_operator_overload_default_arg)
- << FnDecl->getDeclName() << (*Param)->getDefaultArgRange();
+ << FnDecl->getDeclName() << Param->getDefaultArgRange();
}
}
@@ -11042,13 +11039,11 @@ FinishedParams:
// A parameter-declaration-clause containing a default argument is not
// equivalent to any of the permitted forms.
- for (FunctionDecl::param_iterator Param = FnDecl->param_begin(),
- ParamEnd = FnDecl->param_end();
- Param != ParamEnd; ++Param) {
- if ((*Param)->hasDefaultArg()) {
- Diag((*Param)->getDefaultArgRange().getBegin(),
+ for (auto Param : FnDecl->params()) {
+ if (Param->hasDefaultArg()) {
+ Diag(Param->getDefaultArgRange().getBegin(),
diag::err_literal_operator_default_argument)
- << (*Param)->getDefaultArgRange();
+ << Param->getDefaultArgRange();
break;
}
}
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Mar 7 09:12:56 2014
@@ -6284,10 +6284,8 @@ static void StripImplicitInstantiation(N
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
FD->setInlineSpecified(false);
- for (FunctionDecl::param_iterator I = FD->param_begin(),
- E = FD->param_end();
- I != E; ++I)
- (*I)->dropAttrs();
+ for (auto I : FD->params())
+ I->dropAttrs();
}
}
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Fri Mar 7 09:12:56 2014
@@ -2507,11 +2507,8 @@ Sema::SubstituteExplicitTemplateArgument
if (ExplicitTemplateArgs.size() == 0) {
// No arguments to substitute; just copy over the parameter types and
// fill in the function type.
- for (FunctionDecl::param_iterator P = Function->param_begin(),
- PEnd = Function->param_end();
- P != PEnd;
- ++P)
- ParamTypes.push_back((*P)->getType());
+ for (auto P : Function->params())
+ ParamTypes.push_back(P->getType());
if (FunctionType)
*FunctionType = Function->getType();
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Fri Mar 7 09:12:56 2014
@@ -414,9 +414,8 @@ void ASTDeclWriter::VisitFunctionDecl(Fu
}
Record.push_back(D->param_size());
- for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
- P != PEnd; ++P)
- Writer.AddDeclRef(*P, Record);
+ for (auto P : D->params())
+ Writer.AddDeclRef(P, Record);
Code = serialization::DECL_FUNCTION;
}
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp Fri Mar 7 09:12:56 2014
@@ -109,9 +109,8 @@ void CFErrorFunctionChecker::checkASTDec
II = &D->getASTContext().Idents.get("CFErrorRef");
bool hasCFError = false;
- for (FunctionDecl::param_const_iterator
- I = D->param_begin(), E = D->param_end(); I != E; ++I) {
- if (IsCFError((*I)->getType(), II)) {
+ for (auto I : D->params()) {
+ if (IsCFError(I->getType(), II)) {
hasCFError = true;
break;
}
Modified: cfe/trunk/tools/libclang/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexDecl.cpp?rev=203248&r1=203247&r2=203248&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Fri Mar 7 09:12:56 2014
@@ -41,10 +41,8 @@ public:
if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
IndexCtx.handleVar(Parm);
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
- for (FunctionDecl::param_const_iterator PI = FD->param_begin(),
- PE = FD->param_end();
- PI != PE; ++PI) {
- IndexCtx.handleVar(*PI);
+ for (auto PI : FD->params()) {
+ IndexCtx.handleVar(PI);
}
}
}
More information about the cfe-commits
mailing list