[cfe-commits] r171715 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Manuel Klimek
klimek at google.com
Mon Jan 7 01:24:17 PST 2013
Author: klimek
Date: Mon Jan 7 03:24:17 2013
New Revision: 171715
URL: http://llvm.org/viewvc/llvm-project?rev=171715&view=rev
Log:
Do not ever allow using the full line in preprocessor directives.
We would format:
#define A \
int f(a); int i;
as
#define A \
int f(a);\
int i
The fix will break up macro definitions that could fit a line, but hit
the last column; fixing that is more involved, though, as it requires
looking at the following line.
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=171715&r1=171714&r2=171715&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Jan 7 03:24:17 2013
@@ -137,7 +137,7 @@
// FIXME: We need to check whether we're in a preprocessor directive, even
// if all tokens fit - the next line might be a preprocessor directive,
// too, in which case we need to account for the possible escaped newline.
- if (Columns > Style.ColumnLimit ||
+ if (Columns > Style.ColumnLimit - (Line.InPPDirective ? 1 : 0) ||
(Annotations[i].MustBreakBefore &&
Annotations[i].Type != TokenAnnotation::TT_CtorInitializerColon)) {
FitsOnALine = false;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171715&r1=171714&r2=171715&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 7 03:24:17 2013
@@ -413,11 +413,13 @@
}
TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) {
- // If the macro fits in one line, we have the full width.
- verifyFormat("#define A(B)", getLLVMStyleWithColumns(12));
+ // If the macro fits in one line, we still do not get the full
+ // line, as only the next line decides whether we need an escaped newline and
+ // thus use the last column.
+ verifyFormat("#define A(B)", getLLVMStyleWithColumns(13));
- verifyFormat("#define A(\\\n B)", getLLVMStyleWithColumns(11));
- verifyFormat("#define AA(\\\n B)", getLLVMStyleWithColumns(11));
+ verifyFormat("#define A( \\\n B)", getLLVMStyleWithColumns(12));
+ verifyFormat("#define AA(\\\n B)", getLLVMStyleWithColumns(12));
verifyFormat("#define A( \\\n A, B)", getLLVMStyleWithColumns(12));
}
@@ -490,6 +492,13 @@
getLLVMStyleWithColumns(11)));
}
+TEST_F(FormatTest, CalculateSpaceOnConsecutiveLinesInMacro) {
+ verifyFormat("#define A \\\n"
+ " int v( \\\n"
+ " a); \\\n"
+ " int i;", getLLVMStyleWithColumns(11));
+}
+
TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) {
EXPECT_EQ(
"#define ALooooooooooooooooooooooooooooooooooooooongMacro("
More information about the cfe-commits
mailing list