// 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))
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) {
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}}"));
}