r281064 - 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:50:49 PDT 2016
Author: ioeric
Date: Fri Sep 9 12:50:49 2016
New Revision: 281064
URL: http://llvm.org/viewvc/llvm-project?rev=281064&view=rev
Log:
Also cleanup comments around redundant colons/commas in format::cleanup.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D24400
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/CleanupTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=281064&r1=281063&r2=281064&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Sep 9 12:50:49 2016
@@ -1132,6 +1132,8 @@ private:
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)
Modified: cfe/trunk/unittests/Format/CleanupTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/CleanupTest.cpp?rev=281064&r1=281063&r2=281064&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/CleanupTest.cpp (original)
+++ cfe/trunk/unittests/Format/CleanupTest.cpp Fri Sep 9 12:50:49 2016
@@ -188,39 +188,34 @@ TEST_F(CleanupTest, RedundantCommaNotInA
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));
More information about the cfe-commits
mailing list