r177524 - Do not consider comments when adjusting to local indent style.
Daniel Jasper
djasper at google.com
Wed Mar 20 07:31:47 PDT 2013
Author: djasper
Date: Wed Mar 20 09:31:47 2013
New Revision: 177524
URL: http://llvm.org/viewvc/llvm-project?rev=177524&view=rev
Log:
Do not consider comments when adjusting to local indent style.
Before (when only reformatting "int b"):
int a; // comment
// comment
int b;
After:
int a; // comment
// comment
int b;
This also fixes llvm.org/PR15433.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=177524&r1=177523&r2=177524&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar 20 09:31:47 2013
@@ -1324,7 +1324,8 @@ public:
unsigned LevelIndent = Indent;
if (static_cast<int>(LevelIndent) - Offset >= 0)
LevelIndent -= Offset;
- IndentForLevel[TheLine.Level] = LevelIndent;
+ if (TheLine.First.isNot(tok::comment))
+ IndentForLevel[TheLine.Level] = LevelIndent;
// Remove trailing whitespace of the previous line if it was touched.
if (PreviousLineWasTouched || touchesEmptyLineBefore(TheLine))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=177524&r1=177523&r2=177524&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 20 09:31:47 2013
@@ -3279,6 +3279,13 @@ TEST_F(FormatTest, ReformatRegionAdjusts
format("void f() {}\n"
"void g() {}",
13, 0, getLLVMStyle()));
+ EXPECT_EQ("int a; // comment\n"
+ " // line 2\n"
+ "int b;",
+ format("int a; // comment\n"
+ " // line 2\n"
+ " int b;",
+ 35, 0, getLLVMStyle()));
}
TEST_F(FormatTest, BreakStringLiterals) {
More information about the cfe-commits
mailing list