diff options
author | Daniel Jasper <djasper@google.com> | 2013-09-05 10:04:31 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-09-05 10:04:31 +0000 |
commit | 9a8d48b5e1df1c459625bef47d36424bd25c7efb (patch) | |
tree | e09792102e7b727d2a2ecb4f35d5f938b989f288 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | 9fe0e8dacdb36520bd93ed720afd4ce045931a44 (diff) | |
download | bcm5719-llvm-9a8d48b5e1df1c459625bef47d36424bd25c7efb.tar.gz bcm5719-llvm-9a8d48b5e1df1c459625bef47d36424bd25c7efb.zip |
clang-format: Fix parsing and indenting lambdas.
Before:
void f() {
other(x.begin(), x.end(), //
[&](int, int) { return 1; });
}
After:
void f() {
other(x.begin(), x.end(), //
[&](int, int) { return 1; });
}
llvm-svn: 190039
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 4e70625f5bd..13b9847527a 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -676,27 +676,22 @@ void UnwrappedLineParser::parseStructuralElement() { void UnwrappedLineParser::tryToParseLambda() { assert(FormatTok->is(tok::l_square)); FormatToken &LSquare = *FormatTok; - if (!tryToParseLambdaIntroducer()) { + if (!tryToParseLambdaIntroducer()) return; - } - if (FormatTok->is(tok::l_paren)) { - parseParens(); - } while (FormatTok->isNot(tok::l_brace)) { switch (FormatTok->Tok.getKind()) { - case tok::l_brace: - break; - case tok::l_paren: - parseParens(); - break; - case tok::semi: - case tok::equal: - case tok::eof: - return; - default: - nextToken(); - break; + case tok::l_brace: + break; + case tok::l_paren: + parseParens(); + break; + case tok::identifier: + case tok::kw_mutable: + nextToken(); + break; + default: + return; } } LSquare.Type = TT_LambdaLSquare; @@ -707,23 +702,33 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() { nextToken(); if (FormatTok->is(tok::equal)) { nextToken(); - if (FormatTok->is(tok::r_square)) return true; - if (FormatTok->isNot(tok::comma)) return false; + if (FormatTok->is(tok::r_square)) { + nextToken(); + return true; + } + if (FormatTok->isNot(tok::comma)) + return false; nextToken(); } else if (FormatTok->is(tok::amp)) { nextToken(); - if (FormatTok->is(tok::r_square)) return true; + if (FormatTok->is(tok::r_square)) { + nextToken(); + return true; + } if (!FormatTok->isOneOf(tok::comma, tok::identifier)) { return false; } - if (FormatTok->is(tok::comma)) nextToken(); + if (FormatTok->is(tok::comma)) + nextToken(); } else if (FormatTok->is(tok::r_square)) { nextToken(); return true; } do { - if (FormatTok->is(tok::amp)) nextToken(); - if (!FormatTok->isOneOf(tok::identifier, tok::kw_this)) return false; + if (FormatTok->is(tok::amp)) + nextToken(); + if (!FormatTok->isOneOf(tok::identifier, tok::kw_this)) + return false; nextToken(); if (FormatTok->is(tok::comma)) { nextToken(); @@ -836,6 +841,9 @@ void UnwrappedLineParser::parseParens() { case tok::r_brace: // A "}" inside parenthesis is an error if there wasn't a matching "{". return; + case tok::l_square: + tryToParseLambda(); + break; case tok::l_brace: { if (!tryToParseBracedList()) { parseChildBlock(); @@ -1195,7 +1203,7 @@ static void printDebugInfo(const UnwrappedLine &Line, StringRef Prefix = "") { for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) { - llvm::dbgs() << I->Tok->Tok.getName() << " "; + llvm::dbgs() << I->Tok->Tok.getName() << "[" << I->Tok->Type << "] "; } for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(), E = Line.Tokens.end(); |