Skip to content
Snippets Groups Projects
Commit 423dd93c authored by Manuel Klimek's avatar Manuel Klimek
Browse files

Fixes recovering from errors when parsing braced init lists.

Before we would build huge unwrapped lines which take a long time
to optimze.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179168 91177308-0d34-0410-b5e6-96231b3b80d8
parent ac3223e4
No related branches found
No related tags found
No related merge requests found
......@@ -440,16 +440,36 @@ void UnwrappedLineParser::parseStructuralElement() {
void UnwrappedLineParser::parseBracedList() {
nextToken();
// FIXME: Once we have an expression parser in the UnwrappedLineParser,
// replace this by using parseAssigmentExpression() inside.
bool StartOfExpression = true;
do {
// FIXME: When we start to support lambdas, we'll want to parse them away
// here, otherwise our bail-out scenarios below break. The better solution
// might be to just implement a more or less complete expression parser.
switch (FormatTok.Tok.getKind()) {
case tok::l_brace:
if (!StartOfExpression) {
// Probably a missing closing brace. Bail out.
addUnwrappedLine();
return;
}
parseBracedList();
StartOfExpression = false;
break;
case tok::r_brace:
nextToken();
return;
case tok::semi:
// Probably a missing closing brace. Bail out.
return;
case tok::comma:
nextToken();
StartOfExpression = true;
break;
default:
nextToken();
StartOfExpression = false;
break;
}
} while (!eof());
......@@ -462,6 +482,11 @@ void UnwrappedLineParser::parseReturn() {
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();
......
......@@ -3734,5 +3734,19 @@ TEST_F(FormatTest, DoNotBreakStringLiteralsInEscapeSequence) {
format("R\"(\\x\\x00)\"\n", getLLVMStyleWithColumns(7)));
}
TEST_F(FormatTest, DoNotCreateUnreasonableUnwrappedLines) {
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()\n"
"{\n"
" f();\n"
" g();\n"
"}");
}
} // end namespace tooling
} // end namespace clang
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment