[PATCH] Again macros without trailing semicolons: don't care about declaration context.
Alexander Kornienko
alexfh at google.com
Tue Apr 9 04:58:18 PDT 2013
Handle macro calls without semicolons with by blacklisting following next tokens.
Hi djasper, klimek,
http://llvm-reviews.chandlerc.com/D645
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D645?vs=1560&id=1561#toc
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -386,11 +386,31 @@
parseLabel();
return;
}
- // Recognize function-like macro usages without trailing semicolon in
- // declaration context.
+ // Recognize function-like macro usages without trailing semicolon.
if (FormatTok.Tok.is(tok::l_paren)) {
parseParens();
- if (Line->MustBeDeclaration && FormatTok.HasUnescapedNewline) {
+ if (FormatTok.HasUnescapedNewline && FormatTok.Tok.isNot(tok::semi) &&
+ FormatTok.Tok.isNot(tok::l_brace) &&
+ FormatTok.Tok.isNot(tok::l_square) &&
+ FormatTok.Tok.isNot(tok::period) &&
+ FormatTok.Tok.isNot(tok::arrow) &&
+ FormatTok.Tok.isNot(tok::arrowstar) &&
+ FormatTok.Tok.isNot(tok::lessless) &&
+ FormatTok.Tok.isNot(tok::colon) &&
+ FormatTok.Tok.isNot(tok::plusplus) &&
+ FormatTok.Tok.isNot(tok::minusminus) &&
+ FormatTok.Tok.isNot(tok::equal) &&
+ FormatTok.Tok.isNot(tok::plusequal) &&
+ FormatTok.Tok.isNot(tok::minusequal) &&
+ FormatTok.Tok.isNot(tok::starequal) &&
+ FormatTok.Tok.isNot(tok::slashequal) &&
+ FormatTok.Tok.isNot(tok::percentequal) &&
+ FormatTok.Tok.isNot(tok::ampequal) &&
+ FormatTok.Tok.isNot(tok::pipeequal) &&
+ FormatTok.Tok.isNot(tok::caretequal) &&
+ FormatTok.Tok.isNot(tok::greatergreaterequal) &&
+ FormatTok.Tok.isNot(tok::lesslessequal) &&
+ FormatTok.Tok.isNot(tok::kw_try)) {
addUnwrappedLine();
return;
}
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1353,6 +1353,66 @@
" class X {};\n"
" INITIALIZE_PASS_END(ScopDetection, \"polly-detect\")\n"
" int *createScopDetectionPass() { return 0; }"));
+ // FIXME: We could probably treat IPC_BEGIN_MESSAGE_MAP/IPC_END_MESSAGE_MAP as
+ // braces, so that inner block is indented one level more.
+ EXPECT_EQ("int q() {\n"
+ " IPC_BEGIN_MESSAGE_MAP(WebKitTestController, message)\n"
+ " IPC_MESSAGE_HANDLER(xxx, qqq)\n"
+ " IPC_END_MESSAGE_MAP()\n"
+ "}",
+ format("int q() {\n"
+ " IPC_BEGIN_MESSAGE_MAP(WebKitTestController, message)\n"
+ " IPC_MESSAGE_HANDLER(xxx, qqq)\n"
+ " IPC_END_MESSAGE_MAP()\n"
+ "}"));
+ EXPECT_EQ("int q() {\n"
+ " f(x);\n"
+ " f(x) {}\n"
+ " f(x)->g();\n"
+ " f(x)->*g();\n"
+ " f(x).g();\n"
+ " f(x) = x;\n"
+ " f(x) += x;\n"
+ " f(x) -= x;\n"
+ " f(x) *= x;\n"
+ " f(x) /= x;\n"
+ " f(x) %= x;\n"
+ " f(x) &= x;\n"
+ " f(x) |= x;\n"
+ " f(x) ^= x;\n"
+ " f(x) >>= x;\n"
+ " f(x) <<= x;\n"
+ " f(x)[y].z();\n"
+ "}\n"
+ "class A {\n"
+ " A() : t(0) {}\n"
+ " A(X x) try : t(0) {}\n"
+ " catch (...) {\n"
+ " }\n"
+ "};",
+ format("int q() {\n"
+ " f(x)\n;\n"
+ " f(x)\n {}\n"
+ " f(x)\n->g();\n"
+ " f(x)\n->*g();\n"
+ " f(x)\n.g();\n"
+ " f(x)\n = x;\n"
+ " f(x)\n += x;\n"
+ " f(x)\n -= x;\n"
+ " f(x)\n *= x;\n"
+ " f(x)\n /= x;\n"
+ " f(x)\n %= x;\n"
+ " f(x)\n &= x;\n"
+ " f(x)\n |= x;\n"
+ " f(x)\n ^= x;\n"
+ " f(x)\n >>= x;\n"
+ " f(x)\n <<= x;\n"
+ " f(x)\n[y].z();\n"
+ "}\n"
+ "class A {\n"
+ " A()\n : t(0) {}\n"
+ " A(X x)\n try : t(0) {} catch (...) {}\n"
+ "};"));
}
TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D645.2.patch
Type: text/x-patch
Size: 4543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130409/3c2fc00b/attachment.bin>
More information about the cfe-commits
mailing list