diff options
| author | Manuel Klimek <klimek@google.com> | 2013-04-10 09:52:05 +0000 |
|---|---|---|
| committer | Manuel Klimek <klimek@google.com> | 2013-04-10 09:52:05 +0000 |
| commit | a3ff45ebedd83a3e8eab4803a0da838915182f18 (patch) | |
| tree | b5466153859c9d106abd42126302ee58f537338c /clang/lib/Format | |
| parent | c04baae34abb1ecd6e6f26dbc1e443d1df584dfe (diff) | |
| download | bcm5719-llvm-a3ff45ebedd83a3e8eab4803a0da838915182f18.tar.gz bcm5719-llvm-a3ff45ebedd83a3e8eab4803a0da838915182f18.zip | |
Fixes recovering from errors when parsing braced init lists.
Before we would build huge unwrapped lines which take a long time
to optimze.
llvm-svn: 179168
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 22aa8195dd1..cf2ef718e93 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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(); |

