diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-21 10:07:49 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-21 10:07:49 +0000 |
commit | c44ee89cb448e34aada006b707eb45a1280f31e3 (patch) | |
tree | e91a03c0785386bfc36f353087425407a0bea2a5 | |
parent | 2cb3d300ecd36558bf2201debe28808d12a97be2 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173017 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 29 | ||||
-rw-r--r-- | lib/Format/UnwrappedLineParser.h | 1 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 4 |
3 files changed, 34 insertions, 0 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 393416de02..3fd1ff9024 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -308,6 +308,9 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::kw_case: parseCaseLabel(); return; + case tok::kw_return: + parseReturn(); + return; default: break; } @@ -380,6 +383,32 @@ void UnwrappedLineParser::parseBracedList() { } 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(); diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h index 010569af7b..47148ef66d 100644 --- a/lib/Format/UnwrappedLineParser.h +++ b/lib/Format/UnwrappedLineParser.h @@ -131,6 +131,7 @@ private: void parseComments(); void parseStructuralElement(); void parseBracedList(); + void parseReturn(); void parseParens(); void parseIfThenElse(); void parseForOrWhileLoop(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c9319d5939..1d3463ccfd 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1474,6 +1474,10 @@ TEST_F(FormatTest, LayoutCallsInsideBraceInitializers) { "};", getLLVMStyleWithColumns(25)); } +TEST_F(FormatTest, LayoutBraceInitializersInReturnStatement) { + verifyFormat("return (a)(b) { 1, 2, 3 };"); +} + TEST_F(FormatTest, LayoutTokensFollowingBlockInParentheses) { verifyFormat( "Aaa({\n" |