[llvm] dd9a641 - [TableGen] Use range-based for loops (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 6 15:53:23 PST 2021


Author: Kazu Hirata
Date: 2021-03-06T15:52:55-08:00
New Revision: dd9a6411846b06e424a59c0b12cfacf4e4e17532

URL: https://github.com/llvm/llvm-project/commit/dd9a6411846b06e424a59c0b12cfacf4e4e17532
DIFF: https://github.com/llvm/llvm-project/commit/dd9a6411846b06e424a59c0b12cfacf4e4e17532.diff

LOG: [TableGen] Use range-based for loops (NFC)

Added: 
    

Modified: 
    llvm/lib/TableGen/SetTheory.cpp
    llvm/lib/TableGen/StringMatcher.cpp
    llvm/lib/TableGen/TGLexer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/TableGen/SetTheory.cpp b/llvm/lib/TableGen/SetTheory.cpp
index 0389bd3ac830..f7ba75243c15 100644
--- a/llvm/lib/TableGen/SetTheory.cpp
+++ b/llvm/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/llvm/lib/TableGen/StringMatcher.cpp b/llvm/lib/TableGen/StringMatcher.cpp
index 2fca068893f3..7f30c7b60752 100644
--- a/llvm/lib/TableGen/StringMatcher.cpp
+++ b/llvm/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<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";
   }
 

diff  --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index 94c79102c7cd..60a0e34ea8e8 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/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;
     }
 


        


More information about the llvm-commits mailing list