aboutsummaryrefslogtreecommitdiff
path: root/lib/Format
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-04-10 09:52:05 +0000
committerManuel Klimek <klimek@google.com>2013-04-10 09:52:05 +0000
commit423dd93c8011aa8bca9b761b0b121ea8bce0fd03 (patch)
tree67f1e06375115bb6c1b6dead979ba6d1e283b1d2 /lib/Format
parentac3223e45e7d17c65b143439313800eef4fdf71d (diff)
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
Diffstat (limited to 'lib/Format')
-rw-r--r--lib/Format/UnwrappedLineParser.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 22aa8195dd..cf2ef718e9 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -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();