diff --git a/lib/TableGen/SetTheory.cpp b/lib/TableGen/SetTheory.cpp index 0389bd3ac83..f7ba75243c1 100644 --- a/lib/TableGen/SetTheory.cpp +++ b/lib/TableGen/SetTheory.cpp @@ -53,9 +53,9 @@ struct SubOp : public SetTheory::Operator { RecSet Add, Sub; ST.evaluate(*Expr->arg_begin(), Add, Loc); ST.evaluate(Expr->arg_begin() + 1, Expr->arg_end(), Sub, Loc); - for (RecSet::iterator I = Add.begin(), E = Add.end(); I != E; ++I) - if (!Sub.count(*I)) - Elts.insert(*I); + for (const auto &I : Add) + if (!Sub.count(I)) + Elts.insert(I); } }; @@ -69,9 +69,9 @@ struct AndOp : public SetTheory::Operator { RecSet S1, S2; ST.evaluate(Expr->arg_begin()[0], S1, Loc); ST.evaluate(Expr->arg_begin()[1], S2, Loc); - for (RecSet::iterator I = S1.begin(), E = S1.end(); I != E; ++I) - if (S2.count(*I)) - Elts.insert(*I); + for (const auto &I : S1) + if (S2.count(I)) + Elts.insert(I); } }; diff --git a/lib/TableGen/StringMatcher.cpp b/lib/TableGen/StringMatcher.cpp index 2fca068893f..7f30c7b6075 100644 --- a/lib/TableGen/StringMatcher.cpp +++ b/lib/TableGen/StringMatcher.cpp @@ -110,14 +110,14 @@ bool StringMatcher::EmitStringMatcherForChar( OS << Indent << "switch (" << StrVariableName << "[" << CharNo << "]) {\n"; OS << Indent << "default: break;\n"; - for (std::map>::iterator LI = - MatchesByLetter.begin(), E = MatchesByLetter.end(); LI != E; ++LI) { + for (const auto &LI : MatchesByLetter) { // TODO: escape hard stuff (like \n) if we ever care about it. - OS << Indent << "case '" << LI->first << "':\t // " - << LI->second.size() << " string"; - if (LI->second.size() != 1) OS << 's'; + OS << Indent << "case '" << LI.first << "':\t // " << LI.second.size() + << " string"; + if (LI.second.size() != 1) + OS << 's'; OS << " to match.\n"; - if (EmitStringMatcherForChar(LI->second, CharNo + 1, IndentCount + 1, + if (EmitStringMatcherForChar(LI.second, CharNo + 1, IndentCount + 1, IgnoreDuplicates)) OS << Indent << " break;\n"; } @@ -143,12 +143,11 @@ void StringMatcher::Emit(unsigned Indent, bool IgnoreDuplicates) const { OS.indent(Indent*2+2) << "switch (" << StrVariableName << ".size()) {\n"; OS.indent(Indent*2+2) << "default: break;\n"; - for (std::map>::iterator LI = - MatchesByLength.begin(), E = MatchesByLength.end(); LI != E; ++LI) { - OS.indent(Indent*2+2) << "case " << LI->first << ":\t // " - << LI->second.size() - << " string" << (LI->second.size() == 1 ? "" : "s") << " to match.\n"; - if (EmitStringMatcherForChar(LI->second, 0, Indent, IgnoreDuplicates)) + for (const auto &LI : MatchesByLength) { + OS.indent(Indent * 2 + 2) + << "case " << LI.first << ":\t // " << LI.second.size() << " string" + << (LI.second.size() == 1 ? "" : "s") << " to match.\n"; + if (EmitStringMatcherForChar(LI.second, 0, Indent, IgnoreDuplicates)) OS.indent(Indent*2+4) << "break;\n"; } diff --git a/lib/TableGen/TGLexer.cpp b/lib/TableGen/TGLexer.cpp index 94c79102c7c..60a0e34ea8e 100644 --- a/lib/TableGen/TGLexer.cpp +++ b/lib/TableGen/TGLexer.cpp @@ -626,12 +626,12 @@ bool TGLexer::prepExitInclude(bool IncludeStackMustBeEmpty) { } tgtok::TokKind TGLexer::prepIsDirective() const { - for (unsigned ID = 0; ID < llvm::array_lengthof(PreprocessorDirs); ++ID) { + for (const auto &PD : PreprocessorDirs) { int NextChar = *CurPtr; bool Match = true; unsigned I = 0; - for (; I < strlen(PreprocessorDirs[ID].Word); ++I) { - if (NextChar != PreprocessorDirs[ID].Word[I]) { + for (; I < strlen(PD.Word); ++I) { + if (NextChar != PD.Word[I]) { Match = false; break; } @@ -642,7 +642,7 @@ tgtok::TokKind TGLexer::prepIsDirective() const { // Check for whitespace after the directive. If there is no whitespace, // then we do not recognize it as a preprocessing directive. if (Match) { - tgtok::TokKind Kind = PreprocessorDirs[ID].Kind; + tgtok::TokKind Kind = PD.Kind; // New line and EOF may follow only #else/#endif. It will be reported // as an error for #ifdef/#define after the call to prepLexMacroName(). @@ -683,10 +683,10 @@ tgtok::TokKind TGLexer::prepIsDirective() const { bool TGLexer::prepEatPreprocessorDirective(tgtok::TokKind Kind) { TokStart = CurPtr; - for (unsigned ID = 0; ID < llvm::array_lengthof(PreprocessorDirs); ++ID) - if (PreprocessorDirs[ID].Kind == Kind) { + for (const auto &PD : PreprocessorDirs) + if (PD.Kind == Kind) { // Advance CurPtr to the end of the preprocessing word. - CurPtr += strlen(PreprocessorDirs[ID].Word); + CurPtr += strlen(PD.Word); return true; }