r198407 - clang-format: Recognize single-line macro usages inside macros.
Daniel Jasper
djasper at google.com
Fri Jan 3 03:50:46 PST 2014
Author: djasper
Date: Fri Jan 3 05:50:46 2014
New Revision: 198407
URL: http://llvm.org/viewvc/llvm-project?rev=198407&view=rev
Log:
clang-format: Recognize single-line macro usages inside macros.
Before:
#define LIST(L) \
L(FirstElement) L(SecondElement) L(ThirdElement) L(FourthElement) \
L(FifthElement)
After:
#define LIST(L) \
L(FirstElement) \
L(SecondElement) \
L(ThirdElement) \
L(FourthElement) \
L(FifthElement)
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=198407&r1=198406&r2=198407&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Jan 3 05:50:46 2014
@@ -719,7 +719,7 @@ void UnwrappedLineParser::parseStructura
// Recognize function-like macro usages without trailing semicolon.
if (FormatTok->Tok.is(tok::l_paren)) {
parseParens();
- if (FormatTok->HasUnescapedNewline &&
+ if (FormatTok->NewlinesBefore > 0 &&
tokenCanStartNewLine(FormatTok->Tok)) {
addUnwrappedLine();
return;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=198407&r1=198406&r2=198407&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 3 05:50:46 2014
@@ -2198,6 +2198,17 @@ TEST_F(FormatTest, MacroCallsWithoutTrai
" IPC_END_MESSAGE_MAP()\n"
"}"));
+ // Same inside macros.
+ EXPECT_EQ("#define LIST(L) \\\n"
+ " L(A) \\\n"
+ " L(B) \\\n"
+ " L(C)",
+ format("#define LIST(L) \\\n"
+ " L(A) \\\n"
+ " L(B) \\\n"
+ " L(C)",
+ getGoogleStyle()));
+
// These must not be recognized as macros.
EXPECT_EQ("int q() {\n"
" f(x);\n"
More information about the cfe-commits
mailing list