[PATCH] D24400: Also cleanup comments around redundant colons/commas in format::cleanup.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 9 10:59:17 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL281064: Also cleanup comments around redundant colons/commas in format::cleanup. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D24400?vs=70865&id=70867#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24400

Files:
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/CleanupTest.cpp

Index: cfe/trunk/lib/Format/Format.cpp
===================================================================
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1132,6 +1132,8 @@
         break;
       if (Left->is(LK) && Right->is(RK)) {
         deleteToken(DeleteLeft ? Left : Right);
+        for (auto *Tok = Left->Next; Tok && Tok != Right; Tok = Tok->Next)
+          deleteToken(Tok);
         // If the right token is deleted, we should keep the left token
         // unchanged and pair it with the new right token.
         if (!DeleteLeft)
Index: cfe/trunk/unittests/Format/CleanupTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/CleanupTest.cpp
+++ cfe/trunk/unittests/Format/CleanupTest.cpp
@@ -188,39 +188,34 @@
   EXPECT_EQ(Expected, Result);
 }
 
-// FIXME: delete comments too.
-TEST_F(CleanupTest, CtorInitializationCommentAroundCommas) {
-  // Remove redundant commas around comment.
-  std::string Code = "class A {\nA() : x({1}), /* comment */, {} };";
-  std::string Expected = "class A {\nA() : x({1}) /* comment */ {} };";
+TEST_F(CleanupTest, RemoveCommentsAroundDeleteCode) {
+  std::string Code =
+      "class A {\nA() : x({1}), /* comment */, /* comment */ {} };";
+  std::string Expected = "class A {\nA() : x({1}) {} };";
   std::vector<tooling::Range> Ranges;
   Ranges.push_back(tooling::Range(25, 0));
   Ranges.push_back(tooling::Range(40, 0));
   std::string Result = cleanup(Code, Ranges);
   EXPECT_EQ(Expected, Result);
 
-  // Remove trailing comma and ignore comment.
-  Code = "class A {\nA() : x({1}), // comment\n{} };";
-  Expected = "class A {\nA() : x({1}) // comment\n{} };";
+  Code = "class A {\nA() : x({1}), // comment\n {} };";
+  Expected = "class A {\nA() : x({1})\n {} };";
   Ranges = std::vector<tooling::Range>(1, tooling::Range(25, 0));
   Result = cleanup(Code, Ranges);
   EXPECT_EQ(Expected, Result);
 
-  // Remove trailing comma and ignore comment.
   Code = "class A {\nA() : x({1}), // comment\n , y(1),{} };";
-  Expected = "class A {\nA() : x({1}), // comment\n  y(1){} };";
+  Expected = "class A {\nA() : x({1}),  y(1){} };";
   Ranges = std::vector<tooling::Range>(1, tooling::Range(38, 0));
   Result = cleanup(Code, Ranges);
   EXPECT_EQ(Expected, Result);
 
-  // Remove trailing comma and ignore comment.
   Code = "class A {\nA() : x({1}), \n/* comment */, y(1),{} };";
-  Expected = "class A {\nA() : x({1}), \n/* comment */ y(1){} };";
+  Expected = "class A {\nA() : x({1}), \n y(1){} };";
   Ranges = std::vector<tooling::Range>(1, tooling::Range(40, 0));
   Result = cleanup(Code, Ranges);
   EXPECT_EQ(Expected, Result);
 
-  // Remove trailing comma and ignore comment.
   Code = "class A {\nA() : , // comment\n y(1),{} };";
   Expected = "class A {\nA() :  // comment\n y(1){} };";
   Ranges = std::vector<tooling::Range>(1, tooling::Range(17, 0));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24400.70867.patch
Type: text/x-patch
Size: 2917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160909/f92259e8/attachment.bin>


More information about the cfe-commits mailing list