Parser.Line.reset(new UnwrappedLine());
Parser.Line->Level = PreBlockLine->Level;
Parser.Line->InPPDirective = PreBlockLine->InPPDirective;
+ Parser.CommentsBeforeNextToken.swap(CommentsBeforeNextToken);
}
~ScopedLineState() {
Parser.MustBreakBeforeNextToken = true;
if (SwitchToPreprocessorLines)
Parser.CurrentLines = &Parser.Lines;
+ Parser.CommentsBeforeNextToken.swap(CommentsBeforeNextToken);
}
private:
const bool SwitchToPreprocessorLines;
UnwrappedLine *PreBlockLine;
+ SmallVector<FormatToken, 1> CommentsBeforeNextToken;
};
UnwrappedLineParser::UnwrappedLineParser(
while (!Line->InPPDirective && FormatTok.Tok.is(tok::hash) &&
((FormatTok.NewlinesBefore > 0 && FormatTok.HasUnescapedNewline) ||
FormatTok.IsFirst)) {
- flushComments(FormatTok.NewlinesBefore > 0);
// If there is an unfinished unwrapped line, we flush the preprocessor
// directives only after that unwrapped line was finished later.
bool SwitchToPreprocessorLines =
getLLVMStyleWithColumns(20)));
}
+TEST_F(FormatTest, ParsesCommentsAdjacentToPPDirectives) {
+ EXPECT_EQ("namespace {}\n// Test\n#define A",
+ format("namespace {}\n // Test\n#define A"));
+ EXPECT_EQ("namespace {}\n/* Test */\n#define A",
+ format("namespace {}\n /* Test */\n#define A"));
+ EXPECT_EQ("namespace {}\n/* Test */ #define A",
+ format("namespace {}\n /* Test */ #define A"));
+}
+
TEST_F(FormatTest, SplitsLongLinesInComments) {
EXPECT_EQ("/* This is a long\n"
" * comment that\n"