[TableGen] Use range-based for loops (NFC)
authorKazu Hirata <kazu@google.com>
Sat, 6 Mar 2021 23:52:55 +0000 (15:52 -0800)
committerKazu Hirata <kazu@google.com>
Sat, 6 Mar 2021 23:52:55 +0000 (15:52 -0800)
llvm/lib/TableGen/SetTheory.cpp
llvm/lib/TableGen/StringMatcher.cpp
llvm/lib/TableGen/TGLexer.cpp

index 0389bd3..f7ba752 100644 (file)
@@ -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);
   }
 };
 
index 2fca068..7f30c7b 100644 (file)
@@ -110,14 +110,14 @@ bool StringMatcher::EmitStringMatcherForChar(
   OS << Indent << "switch (" << StrVariableName << "[" << CharNo << "]) {\n";
   OS << Indent << "default: break;\n";
 
-  for (std::map<char, std::vector<const StringPair*>>::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<unsigned, std::vector<const StringPair*>>::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";
   }
 
index 94c7910..60a0e34 100644 (file)
@@ -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;
     }