r199982 - Get rid of special parsing for return statements.
Manuel Klimek
klimek at google.com
Fri Jan 24 01:25:23 PST 2014
Author: klimek
Date: Fri Jan 24 03:25:23 2014
New Revision: 199982
URL: http://llvm.org/viewvc/llvm-project?rev=199982&view=rev
Log:
Get rid of special parsing for return statements.
This was done when we were not able to parse lambdas to handle some
edge cases for block formatting different in return statements, but is
not necessary any more.
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=199982&r1=199981&r2=199982&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Jan 24 03:25:23 2014
@@ -641,9 +641,6 @@ void UnwrappedLineParser::parseStructura
case tok::kw_case:
parseCaseLabel();
return;
- case tok::kw_return:
- parseReturn();
- return;
case tok::kw_extern:
nextToken();
if (FormatTok->Tok.is(tok::string_literal)) {
@@ -890,40 +887,6 @@ bool UnwrappedLineParser::parseBracedLis
return false;
}
-void UnwrappedLineParser::parseReturn() {
- nextToken();
-
- do {
- switch (FormatTok->Tok.getKind()) {
- case tok::l_brace:
- parseBracedList();
- if (FormatTok->Tok.isNot(tok::semi)) {
- // Assume missing ';'.
- addUnwrappedLine();
- return;
- }
- break;
- case tok::l_paren:
- parseParens();
- break;
- case tok::r_brace:
- // Assume missing ';'.
- addUnwrappedLine();
- return;
- case tok::semi:
- nextToken();
- addUnwrappedLine();
- return;
- case tok::l_square:
- tryToParseLambda();
- break;
- 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=199982&r1=199981&r2=199982&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Fri Jan 24 03:25:23 2014
@@ -82,7 +82,6 @@ private:
void parseStructuralElement();
bool tryToParseBracedList();
bool parseBracedList(bool ContinueOnSemicolons = false);
- void parseReturn();
void parseParens();
void parseSquare();
void parseIfThenElse();
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=199982&r1=199981&r2=199982&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 24 03:25:23 2014
@@ -6479,14 +6479,18 @@ TEST_F(FormatTest, DoNotCreateUnreasonab
verifyFormat("void f() {\n"
" return g() {}\n"
" void h() {}");
- verifyFormat("if (foo)\n"
- " return { forgot_closing_brace();\n"
- "test();");
verifyFormat("int a[] = { void forgot_closing_brace() { f();\n"
"g();\n"
"}");
}
+TEST_F(FormatTest, DoNotPrematurelyEndUnwrappedLineForReturnStatements) {
+ verifyFormat(
+ "void f() {\n"
+ " return C{ param1, param2 }.SomeCall(param1, param2);\n"
+ "}\n");
+}
+
TEST_F(FormatTest, FormatsClosingBracesInEmptyNestedBlocks) {
verifyFormat("class X {\n"
" void f() {\n"
More information about the cfe-commits
mailing list