forked from OSchip/llvm-project
[C++11] Replacing EnumDecl iterators enumerator_begin() and enumerator_end() with iterator_range enumerators(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203353
This commit is contained in:
parent
951b235be2
commit
23a6dcb365
|
@ -2899,6 +2899,11 @@ public:
|
||||||
// enumerator_iterator - Iterates through the enumerators of this
|
// enumerator_iterator - Iterates through the enumerators of this
|
||||||
// enumeration.
|
// enumeration.
|
||||||
typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator;
|
typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator;
|
||||||
|
typedef specific_decl_range<EnumConstantDecl> enumerator_range;
|
||||||
|
|
||||||
|
enumerator_range enumerators() const {
|
||||||
|
return enumerator_range(enumerator_begin(), enumerator_end());
|
||||||
|
}
|
||||||
|
|
||||||
enumerator_iterator enumerator_begin() const {
|
enumerator_iterator enumerator_begin() const {
|
||||||
const EnumDecl *E = getDefinition();
|
const EnumDecl *E = getDefinition();
|
||||||
|
|
|
@ -1396,6 +1396,10 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename SpecificDecl>
|
||||||
|
using specific_decl_range =
|
||||||
|
llvm::iterator_range<specific_decl_iterator<SpecificDecl>>;
|
||||||
|
|
||||||
/// \brief Iterates over a filtered subrange of declarations stored
|
/// \brief Iterates over a filtered subrange of declarations stored
|
||||||
/// in a DeclContext.
|
/// in a DeclContext.
|
||||||
///
|
///
|
||||||
|
|
|
@ -667,9 +667,7 @@ static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx,
|
||||||
bool PowerOfTwo = true;
|
bool PowerOfTwo = true;
|
||||||
bool AllHexdecimalEnumerator = true;
|
bool AllHexdecimalEnumerator = true;
|
||||||
uint64_t MaxPowerOfTwoVal = 0;
|
uint64_t MaxPowerOfTwoVal = 0;
|
||||||
for (EnumDecl::enumerator_iterator EI = EnumDcl->enumerator_begin(),
|
for (auto Enumerator : EnumDcl->enumerators()) {
|
||||||
EE = EnumDcl->enumerator_end(); EI != EE; ++EI) {
|
|
||||||
EnumConstantDecl *Enumerator = (*EI);
|
|
||||||
const Expr *InitExpr = Enumerator->getInitExpr();
|
const Expr *InitExpr = Enumerator->getInitExpr();
|
||||||
if (!InitExpr) {
|
if (!InitExpr) {
|
||||||
PowerOfTwo = false;
|
PowerOfTwo = false;
|
||||||
|
|
|
@ -1917,9 +1917,7 @@ llvm::DIType CGDebugInfo::CreateEnumType(const EnumType *Ty) {
|
||||||
// Create DIEnumerator elements for each enumerator.
|
// Create DIEnumerator elements for each enumerator.
|
||||||
SmallVector<llvm::Value *, 16> Enumerators;
|
SmallVector<llvm::Value *, 16> Enumerators;
|
||||||
ED = ED->getDefinition();
|
ED = ED->getDefinition();
|
||||||
for (EnumDecl::enumerator_iterator
|
for (const auto *Enum : ED->enumerators()) {
|
||||||
Enum = ED->enumerator_begin(), EnumEnd = ED->enumerator_end();
|
|
||||||
Enum != EnumEnd; ++Enum) {
|
|
||||||
Enumerators.push_back(
|
Enumerators.push_back(
|
||||||
DBuilder.createEnumerator(Enum->getName(),
|
DBuilder.createEnumerator(Enum->getName(),
|
||||||
Enum->getInitVal().getSExtValue()));
|
Enum->getInitVal().getSExtValue()));
|
||||||
|
|
|
@ -817,10 +817,9 @@ void AddTopLevelDeclarationToHash(Decl *D, unsigned &Hash) {
|
||||||
// For an unscoped enum include the enumerators in the hash since they
|
// For an unscoped enum include the enumerators in the hash since they
|
||||||
// enter the top-level namespace.
|
// enter the top-level namespace.
|
||||||
if (!EnumD->isScoped()) {
|
if (!EnumD->isScoped()) {
|
||||||
for (EnumDecl::enumerator_iterator EI = EnumD->enumerator_begin(),
|
for (const auto *EI : EnumD->enumerators()) {
|
||||||
EE = EnumD->enumerator_end(); EI != EE; ++EI) {
|
if (EI->getIdentifier())
|
||||||
if ((*EI)->getIdentifier())
|
Hash = llvm::HashString(EI->getIdentifier()->getName(), Hash);
|
||||||
Hash = llvm::HashString((*EI)->getIdentifier()->getName(), Hash);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3809,8 +3809,7 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type,
|
||||||
}
|
}
|
||||||
|
|
||||||
Result += " {\n";
|
Result += " {\n";
|
||||||
for (EnumDecl::enumerator_iterator EC = ED->enumerator_begin(),
|
for (const auto *EC : ED->enumerators()) {
|
||||||
ECEnd = ED->enumerator_end(); EC != ECEnd; ++EC) {
|
|
||||||
Result += "\t"; Result += EC->getName(); Result += " = ";
|
Result += "\t"; Result += EC->getName(); Result += " = ";
|
||||||
llvm::APSInt Val = EC->getInitVal();
|
llvm::APSInt Val = EC->getInitVal();
|
||||||
Result += Val.toString(10);
|
Result += Val.toString(10);
|
||||||
|
|
|
@ -3795,13 +3795,11 @@ void Sema::CodeCompleteCase(Scope *S) {
|
||||||
CodeCompleter->getCodeCompletionTUInfo(),
|
CodeCompleter->getCodeCompletionTUInfo(),
|
||||||
CodeCompletionContext::CCC_Expression);
|
CodeCompletionContext::CCC_Expression);
|
||||||
Results.EnterNewScope();
|
Results.EnterNewScope();
|
||||||
for (EnumDecl::enumerator_iterator E = Enum->enumerator_begin(),
|
for (auto *E : Enum->enumerators()) {
|
||||||
EEnd = Enum->enumerator_end();
|
if (EnumeratorsSeen.count(E))
|
||||||
E != EEnd; ++E) {
|
|
||||||
if (EnumeratorsSeen.count(*E))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CodeCompletionResult R(*E, CCP_EnumInCase, Qualifier);
|
CodeCompletionResult R(E, CCP_EnumInCase, Qualifier);
|
||||||
Results.AddResult(R, CurContext, 0, false);
|
Results.AddResult(R, CurContext, 0, false);
|
||||||
}
|
}
|
||||||
Results.ExitScope();
|
Results.ExitScope();
|
||||||
|
|
|
@ -9630,10 +9630,9 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) {
|
||||||
|
|
||||||
// Similarly, dive into enums and fish their constants out, making them
|
// Similarly, dive into enums and fish their constants out, making them
|
||||||
// accessible in this scope.
|
// accessible in this scope.
|
||||||
if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
|
if (auto *ED = dyn_cast<EnumDecl>(D)) {
|
||||||
for (EnumDecl::enumerator_iterator EI = ED->enumerator_begin(),
|
for (auto *EI : ED->enumerators())
|
||||||
EE = ED->enumerator_end(); EI != EE; ++EI)
|
PushOnScopeChains(EI, FnBodyScope, /*AddToContext=*/false);
|
||||||
PushOnScopeChains(*EI, FnBodyScope, /*AddToContext=*/false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1015,11 +1015,10 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
|
||||||
|
|
||||||
// Gather all enum values, set their type and sort them,
|
// Gather all enum values, set their type and sort them,
|
||||||
// allowing easier comparison with CaseVals.
|
// allowing easier comparison with CaseVals.
|
||||||
for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin();
|
for (auto *EDI : ED->enumerators()) {
|
||||||
EDI != ED->enumerator_end(); ++EDI) {
|
|
||||||
llvm::APSInt Val = EDI->getInitVal();
|
llvm::APSInt Val = EDI->getInitVal();
|
||||||
AdjustAPSInt(Val, CondWidth, CondIsSigned);
|
AdjustAPSInt(Val, CondWidth, CondIsSigned);
|
||||||
EnumVals.push_back(std::make_pair(Val, *EDI));
|
EnumVals.push_back(std::make_pair(Val, EDI));
|
||||||
}
|
}
|
||||||
std::stable_sort(EnumVals.begin(), EnumVals.end(), CmpEnumVals);
|
std::stable_sort(EnumVals.begin(), EnumVals.end(), CmpEnumVals);
|
||||||
EnumValsTy::iterator EIend =
|
EnumValsTy::iterator EIend =
|
||||||
|
@ -1166,11 +1165,10 @@ Sema::DiagnoseAssignmentEnum(QualType DstType, QualType SrcType,
|
||||||
|
|
||||||
// Gather all enum values, set their type and sort them,
|
// Gather all enum values, set their type and sort them,
|
||||||
// allowing easier comparison with rhs constant.
|
// allowing easier comparison with rhs constant.
|
||||||
for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin();
|
for (auto *EDI : ED->enumerators()) {
|
||||||
EDI != ED->enumerator_end(); ++EDI) {
|
|
||||||
llvm::APSInt Val = EDI->getInitVal();
|
llvm::APSInt Val = EDI->getInitVal();
|
||||||
AdjustAPSInt(Val, DstWidth, DstIsSigned);
|
AdjustAPSInt(Val, DstWidth, DstIsSigned);
|
||||||
EnumVals.push_back(std::make_pair(Val, *EDI));
|
EnumVals.push_back(std::make_pair(Val, EDI));
|
||||||
}
|
}
|
||||||
if (EnumVals.empty())
|
if (EnumVals.empty())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -733,9 +733,7 @@ void TemplateDeclInstantiator::InstantiateEnumDefinition(
|
||||||
SmallVector<Decl*, 4> Enumerators;
|
SmallVector<Decl*, 4> Enumerators;
|
||||||
|
|
||||||
EnumConstantDecl *LastEnumConst = 0;
|
EnumConstantDecl *LastEnumConst = 0;
|
||||||
for (EnumDecl::enumerator_iterator EC = Pattern->enumerator_begin(),
|
for (auto *EC : Pattern->enumerators()) {
|
||||||
ECEnd = Pattern->enumerator_end();
|
|
||||||
EC != ECEnd; ++EC) {
|
|
||||||
// The specified value for the enumerator.
|
// The specified value for the enumerator.
|
||||||
ExprResult Value = SemaRef.Owned((Expr *)0);
|
ExprResult Value = SemaRef.Owned((Expr *)0);
|
||||||
if (Expr *UninstValue = EC->getInitExpr()) {
|
if (Expr *UninstValue = EC->getInitExpr()) {
|
||||||
|
@ -765,7 +763,7 @@ void TemplateDeclInstantiator::InstantiateEnumDefinition(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EnumConst) {
|
if (EnumConst) {
|
||||||
SemaRef.InstantiateAttrs(TemplateArgs, *EC, EnumConst);
|
SemaRef.InstantiateAttrs(TemplateArgs, EC, EnumConst);
|
||||||
|
|
||||||
EnumConst->setAccess(Enum->getAccess());
|
EnumConst->setAccess(Enum->getAccess());
|
||||||
Enum->addDecl(EnumConst);
|
Enum->addDecl(EnumConst);
|
||||||
|
@ -776,7 +774,7 @@ void TemplateDeclInstantiator::InstantiateEnumDefinition(
|
||||||
!Enum->isScoped()) {
|
!Enum->isScoped()) {
|
||||||
// If the enumeration is within a function or method, record the enum
|
// If the enumeration is within a function or method, record the enum
|
||||||
// constant as a local.
|
// constant as a local.
|
||||||
SemaRef.CurrentInstantiationScope->InstantiatedLocal(*EC, EnumConst);
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(EC, EnumConst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue