else
Line.MustBeDeclaration = true;
}
+
private:
UnwrappedLine &Line;
std::vector<bool> &Stack;
return Token;
}
- virtual unsigned getPosition() {
- return PreviousTokenSource->getPosition();
- }
+ virtual unsigned getPosition() { return PreviousTokenSource->getPosition(); }
virtual FormatToken *setPosition(unsigned Position) {
Token = PreviousTokenSource->setPosition(Position);
case tok::kw_for:
case tok::kw_switch:
case tok::kw_try:
- if (!LBraceStack.empty())
+ if (!LBraceStack.empty())
LBraces[LBraceStack.back()] = BS_Block;
break;
default:
parsePPUnknown();
}
-void UnwrappedLineParser::parsePPElIf() {
- parsePPElse();
-}
+void UnwrappedLineParser::parsePPElIf() { parsePPElse(); }
void UnwrappedLineParser::parsePPEndIf() {
if (!PPStack.empty())
case tok::r_paren:
nextToken();
return;
+ case tok::r_brace:
+ // A "}" inside parenthesis is an error if there wasn't a matching "{".
+ return;
case tok::l_brace: {
if (!tryToParseBracedList()) {
nextToken();
- ScopedLineState LineState(*this);
- ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
- /*MustBeDeclaration=*/ false);
- Line->Level += 1;
- parseLevel(/*HasOpeningBrace=*/ true);
- Line->Level -= 1;
+ {
+ ScopedLineState LineState(*this);
+ ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
+ /*MustBeDeclaration=*/ false);
+ Line->Level += 1;
+ parseLevel(/*HasOpeningBrace=*/ true);
+ Line->Level -= 1;
+ }
+ nextToken();
}
break;
}
" int i;\n"
"});",
format(" functionCall ( {int i;} );"));
+
+ // FIXME: This is bad, find a better and more generic solution.
+ EXPECT_EQ("functionCall({\n"
+ " int i;\n"
+ "},\n"
+ " aaaa, bbbb, cccc);",
+ format(" functionCall ( {int i;}, aaaa, bbbb, cccc);"));
+ verifyFormat(
+ "Aaa({\n"
+ " int i;\n"
+ "},\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " ccccccccccccccccc));");
}
TEST_F(FormatTest, LayoutBlockInsideStatement) {
TEST_F(FormatTest, DoesNotTouchUnwrappedLinesWithErrors) {
verifyFormat("namespace {\n"
- "class Foo { Foo ( }; } // comment");
+ "class Foo { Foo (\n"
+ "};\n"
+ "} // comment");
}
TEST_F(FormatTest, IncorrectCodeErrorDetection) {
NoSpaces);
}
-TEST_F(FormatTest, LayoutTokensFollowingBlockInParentheses) {
- // FIXME: This is bad, find a better and more generic solution.
- verifyFormat(
- "Aaa({\n"
- " int i;\n"
- "},\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
- " ccccccccccccccccc));");
-}
-
TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {
verifyFormat("void f() { return 42; }");
verifyFormat("void f() {\n"