r241059 - clang-format: Properly parse parenthesis in braced lists.
Daniel Jasper
djasper at google.com
Tue Jun 30 04:32:22 PDT 2015
Author: djasper
Date: Tue Jun 30 06:32:22 2015
New Revision: 241059
URL: http://llvm.org/viewvc/llvm-project?rev=241059&view=rev
Log:
clang-format: Properly parse parenthesis in braced lists.
Among other things, this makes clang-format understand arbitrary blocks
embedded in them, such as:
SomeFunction({MACRO({ return output; }), b});
where MACRO could e.g. expand to a lambda.
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=241059&r1=241058&r2=241059&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Jun 30 06:32:22 2015
@@ -1111,16 +1111,15 @@ bool UnwrappedLineParser::parseBracedLis
FormatTok->BlockKind = BK_BracedInit;
parseBracedList();
break;
- case tok::r_paren:
+ case tok::l_paren:
+ parseParens();
// JavaScript can just have free standing methods and getters/setters in
// object literals. Detect them by a "{" following ")".
if (Style.Language == FormatStyle::LK_JavaScript) {
- nextToken();
if (FormatTok->is(tok::l_brace))
parseChildBlock();
break;
}
- nextToken();
break;
case tok::r_brace:
nextToken();
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=241059&r1=241058&r2=241059&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jun 30 06:32:22 2015
@@ -3184,6 +3184,8 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
"}, a);",
Style);
+ verifyFormat("SomeFunction({MACRO({ return output; }), b});");
+
verifyNoCrash("^{v^{a}}");
}
More information about the cfe-commits
mailing list