aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-02-11 12:33:24 +0000
committerManuel Klimek <klimek@google.com>2013-02-11 12:33:24 +0000
commita28fc067e3ee8eb84368530e878ce094f39651d3 (patch)
tree0d9d30a3b21cd665e4e075a958ff4f0a13dc22d3
parent2d000d3eb9a2464e0769bb9f6977652782c988bd (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174878 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/Format.cpp7
-rw-r--r--lib/Format/UnwrappedLineParser.cpp3
-rw-r--r--unittests/Format/FormatTest.cpp20
3 files changed, 26 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 299a8558b9..a78b650dfa 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -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))
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index cb956084e0..3030789ad0 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -766,7 +766,8 @@ void UnwrappedLineParser::addUnwrappedLine() {
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) {
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 1865b5059c..83e4fc54e3 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -858,6 +858,26 @@ TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {
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}}"));
}