r174978 - Fix bug in the adjustment to existing lines.
Daniel Jasper
djasper at google.com
Tue Feb 12 08:51:23 PST 2013
Author: djasper
Date: Tue Feb 12 10:51:23 2013
New Revision: 174978
URL: http://llvm.org/viewvc/llvm-project?rev=174978&view=rev
Log:
Fix bug in the adjustment to existing lines.
Before (if only the second line was reformatted):
void f() {}
void g() {}
After:
void f() {}
void g() {}
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=174978&r1=174977&r2=174978&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Feb 12 10:51:23 2013
@@ -957,12 +957,15 @@ public:
TheLine.Last->FormatTok.Tok.getLocation()) +
Lex.MeasureTokenLength(TheLine.Last->FormatTok.Tok.getLocation(),
SourceMgr, Lex.getLangOpts()) - 1;
- unsigned Indent = SourceMgr.getSpellingColumnNumber(
- TheLine.First.FormatTok.Tok.getLocation()) - 1;
- unsigned LevelIndent = Indent;
- if (static_cast<int>(LevelIndent) - Offset >= 0)
- LevelIndent -= Offset;
- IndentForLevel[TheLine.Level] = LevelIndent;
+ if (TheLine.First.FormatTok.NewlinesBefore > 0 ||
+ TheLine.First.FormatTok.IsFirst) {
+ unsigned Indent = SourceMgr.getSpellingColumnNumber(
+ TheLine.First.FormatTok.Tok.getLocation()) - 1;
+ unsigned LevelIndent = Indent;
+ if (static_cast<int>(LevelIndent) - Offset >= 0)
+ LevelIndent -= Offset;
+ IndentForLevel[TheLine.Level] = LevelIndent;
+ }
}
}
return Whitespaces.generateReplacements();
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174978&r1=174977&r2=174978&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 12 10:51:23 2013
@@ -2660,6 +2660,9 @@ TEST_F(FormatTest, ReformatRegionAdjusts
" }", format(" {\n"
"a;\n"
" }", 4, 2, getLLVMStyle()));
+ EXPECT_EQ("void f() {}\n"
+ "void g() {}", format("void f() {}\n"
+ "void g() {}", 13, 0, getLLVMStyle()));
}
} // end namespace tooling
More information about the cfe-commits
mailing list