r174878 - Fixes handling of empty lines in macros.
Manuel Klimek
klimek at google.com
Mon Feb 11 04:33:24 PST 2013
Author: klimek
Date: Mon Feb 11 06:33:24 2013
New Revision: 174878
URL: http://llvm.org/viewvc/llvm-project?rev=174878&view=rev
Log:
Fixes handling of empty lines in macros.
Now correctly formats:
#define A \
\
b;
to
#define A b;
Added the state whether an unwrapped line is a macro to the debug
output.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.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=174878&r1=174877&r2=174878&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Feb 11 06:33:24 2013
@@ -804,9 +804,10 @@ public:
// Consume and record whitespace until we find a significant token.
while (FormatTok.Tok.is(tok::unknown)) {
- FormatTok.NewlinesBefore += Text.count('\n');
- FormatTok.HasUnescapedNewline =
- Text.count("\\\n") != FormatTok.NewlinesBefore;
+ unsigned Newlines = Text.count('\n');
+ unsigned EscapedNewlines = Text.count("\\\n");
+ FormatTok.NewlinesBefore += Newlines;
+ FormatTok.HasUnescapedNewline |= EscapedNewlines != Newlines;
FormatTok.WhiteSpaceLength += FormatTok.Tok.getLength();
if (FormatTok.Tok.is(tok::eof))
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=174878&r1=174877&r2=174878&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Feb 11 06:33:24 2013
@@ -766,7 +766,8 @@ void UnwrappedLineParser::addUnwrappedLi
if (Line->Tokens.empty())
return;
DEBUG({
- llvm::dbgs() << "Line(" << Line->Level << "): ";
+ llvm::dbgs() << "Line(" << Line->Level << ")"
+ << (Line->InPPDirective ? " MACRO" : "") << ": ";
for (std::list<FormatToken>::iterator I = Line->Tokens.begin(),
E = Line->Tokens.end();
I != E; ++I) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174878&r1=174877&r2=174878&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Feb 11 06:33:24 2013
@@ -858,6 +858,26 @@ TEST_F(FormatTest, RespectWhitespaceInMa
verifyFormat("#define A (1)");
}
+TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {
+ EXPECT_EQ("#define A b;", format("#define A \\\n"
+ " \\\n"
+ " b;", getLLVMStyleWithColumns(25)));
+ EXPECT_EQ("#define A \\\n"
+ " \\\n"
+ " a; \\\n"
+ " b;", format("#define A \\\n"
+ " \\\n"
+ " a; \\\n"
+ " b;", getLLVMStyleWithColumns(11)));
+ EXPECT_EQ("#define A \\\n"
+ " a; \\\n"
+ " \\\n"
+ " b;", format("#define A \\\n"
+ " a; \\\n"
+ " \\\n"
+ " b;", getLLVMStyleWithColumns(11)));
+}
+
TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
EXPECT_EQ("{\n {\n#define A\n }\n}", format("{{\n#define A\n}}"));
}
More information about the cfe-commits
mailing list