[cfe-commits] r173017 - in /cfe/trunk: lib/Format/UnwrappedLineParser.cpp lib/Format/UnwrappedLineParser.h unittests/Format/FormatTest.cpp
Manuel Klimek
klimek at google.com
Mon Jan 21 02:07:49 PST 2013
Author: klimek
Date: Mon Jan 21 04:07:49 2013
New Revision: 173017
URL: http://llvm.org/viewvc/llvm-project?rev=173017&view=rev
Log:
Fix parsing of return statements.
Previously, we would not detect brace initializer lists in return
statements, thus:
return (a)(b) { 1, 2, 3 };
would put the semicolon onto the next line.
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
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=173017&r1=173016&r2=173017&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jan 21 04:07:49 2013
@@ -308,6 +308,9 @@
case tok::kw_case:
parseCaseLabel();
return;
+ case tok::kw_return:
+ parseReturn();
+ return;
default:
break;
}
@@ -380,6 +383,32 @@
} while (!eof());
}
+void UnwrappedLineParser::parseReturn() {
+ nextToken();
+
+ do {
+ switch (FormatTok.Tok.getKind()) {
+ case tok::l_brace:
+ parseBracedList();
+ break;
+ case tok::l_paren:
+ parseParens();
+ break;
+ case tok::r_brace:
+ // Assume missing ';'.
+ addUnwrappedLine();
+ return;
+ case tok::semi:
+ nextToken();
+ addUnwrappedLine();
+ return;
+ default:
+ nextToken();
+ break;
+ }
+ } while (!eof());
+}
+
void UnwrappedLineParser::parseParens() {
assert(FormatTok.Tok.is(tok::l_paren) && "'(' expected.");
nextToken();
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=173017&r1=173016&r2=173017&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Mon Jan 21 04:07:49 2013
@@ -131,6 +131,7 @@
void parseComments();
void parseStructuralElement();
void parseBracedList();
+ void parseReturn();
void parseParens();
void parseIfThenElse();
void parseForOrWhileLoop();
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173017&r1=173016&r2=173017&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 21 04:07:49 2013
@@ -1474,6 +1474,10 @@
"};", getLLVMStyleWithColumns(25));
}
+TEST_F(FormatTest, LayoutBraceInitializersInReturnStatement) {
+ verifyFormat("return (a)(b) { 1, 2, 3 };");
+}
+
TEST_F(FormatTest, LayoutTokensFollowingBlockInParentheses) {
verifyFormat(
"Aaa({\n"
More information about the cfe-commits
mailing list