From: Manuel Klimek Date: Mon, 11 Feb 2013 12:33:24 +0000 (+0000) Subject: Fixes handling of empty lines in macros. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c13795f68a3d2fe0bc31650260809ad8f160a3b;p=platform%2Fupstream%2Fllvm.git 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. llvm-svn: 174878 --- diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 299a855..a78b650 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/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/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index cb95608..3030789 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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::iterator I = Line->Tokens.begin(), E = Line->Tokens.end(); I != E; ++I) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 1865b50..83e4fc5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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}}")); }