[clang] 6633605 - [clang-format] Address fixme

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 9 12:52:23 PST 2021


Author: Björn Schäpers
Date: 2021-11-09T21:51:44+01:00
New Revision: 66336056911ec1377837ebfe323814521f78d367

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

LOG: [clang-format] Address fixme

Differential Revision: https://reviews.llvm.org/D113320

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.h
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/lib/Format/UnwrappedLineParser.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h
index 0f9c02dbeb34b..6e5e62cd4d82a 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -53,9 +53,7 @@ class AnnotatedLine {
     // left them in a 
diff erent state.
     First->Previous = nullptr;
     FormatToken *Current = First;
-    for (std::list<UnwrappedLineNode>::const_iterator I = ++Line.Tokens.begin(),
-                                                      E = Line.Tokens.end();
-         I != E; ++I) {
+    for (auto I = ++Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) {
       const UnwrappedLineNode &Node = *I;
       Current->Next = I->Tok;
       I->Tok->Previous = Current;

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index ef1785bd54692..ae38e387f1df2 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3034,24 +3034,15 @@ LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line,
   llvm::dbgs() << Prefix << "Line(" << Line.Level
                << ", FSC=" << Line.FirstStartColumn << ")"
                << (Line.InPPDirective ? " MACRO" : "") << ": ";
-  for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(),
-                                                    E = Line.Tokens.end();
-       I != E; ++I) {
-    llvm::dbgs() << I->Tok->Tok.getName() << "["
-                 << "T=" << (unsigned)I->Tok->getType()
-                 << ", OC=" << I->Tok->OriginalColumn << "] ";
-  }
-  for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(),
-                                                    E = Line.Tokens.end();
-       I != E; ++I) {
-    const UnwrappedLineNode &Node = *I;
-    for (SmallVectorImpl<UnwrappedLine>::const_iterator
-             I = Node.Children.begin(),
-             E = Node.Children.end();
-         I != E; ++I) {
-      printDebugInfo(*I, "\nChild: ");
-    }
+  for (const auto &Node : Line.Tokens) {
+    llvm::dbgs() << Node.Tok->Tok.getName() << "["
+                 << "T=" << static_cast<unsigned>(Node.Tok->getType())
+                 << ", OC=" << Node.Tok->OriginalColumn << "] ";
   }
+  for (const auto &Node : Line.Tokens)
+    for (const auto &ChildNode : Node.Children)
+      printDebugInfo(ChildNode, "\nChild: ");
+
   llvm::dbgs() << "\n";
 }
 

diff  --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h
index f22bb6323e3d7..457d41655a628 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -19,8 +19,8 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Format/Format.h"
 #include "llvm/Support/Regex.h"
-#include <list>
 #include <stack>
+#include <vector>
 
 namespace clang {
 namespace format {
@@ -36,9 +36,8 @@ struct UnwrappedLineNode;
 struct UnwrappedLine {
   UnwrappedLine();
 
-  // FIXME: Don't use std::list here.
   /// The \c Tokens comprising this \c UnwrappedLine.
-  std::list<UnwrappedLineNode> Tokens;
+  std::vector<UnwrappedLineNode> Tokens;
 
   /// The indent level of the \c UnwrappedLine.
   unsigned Level;


        


More information about the cfe-commits mailing list