summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-09-03 15:10:01 +0000
committerManuel Klimek <klimek@google.com>2013-09-03 15:10:01 +0000
commitffdeb595ba7e684207d70ea67edd91372604e542 (patch)
tree026465db6cc2567f245ff2b582719f5f672f87b1 /clang/lib/Format/UnwrappedLineParser.cpp
parent2b8d35f8acee6e7b7a19b191494344761b1f517f (diff)
downloadbcm5719-llvm-ffdeb595ba7e684207d70ea67edd91372604e542.tar.gz
bcm5719-llvm-ffdeb595ba7e684207d70ea67edd91372604e542.zip
First step towards correctly formatting lambdas.
Implements parsing of lambdas in the UnwrappedLineParser. This introduces the correct line breaks; the formatting of lambda captures are still incorrect, and the braces are also still formatted as if they were braced init lists instead of blocks. llvm-svn: 189818
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index a149c185aa8..253dbf97fdc 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -640,6 +640,9 @@ void UnwrappedLineParser::parseStructuralElement() {
parseBracedList();
}
break;
+ case tok::l_square:
+ tryToParseLambda();
+ break;
default:
nextToken();
break;
@@ -647,6 +650,77 @@ void UnwrappedLineParser::parseStructuralElement() {
} while (!eof());
}
+void UnwrappedLineParser::tryToParseLambda() {
+ 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;
+ return;
+ case tok::l_paren:
+ parseParens();
+ break;
+ case tok::semi:
+ case tok::equal:
+ case tok::eof:
+ return;
+ default:
+ nextToken();
+ break;
+ }
+ }
+ nextToken();
+ {
+ ScopedLineState LineState(*this);
+ ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
+ /*MustBeDeclaration=*/false);
+ Line->Level += 1;
+ parseLevel(/*HasOpeningBrace=*/true);
+ Line->Level -= 1;
+ }
+ nextToken();
+}
+
+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;
+ nextToken();
+ } else if (FormatTok->is(tok::amp)) {
+ nextToken();
+ if (FormatTok->is(tok::r_square)) return true;
+ if (!FormatTok->isOneOf(tok::comma, tok::identifier)) {
+ return false;
+ }
+ 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;
+ nextToken();
+ if (FormatTok->is(tok::comma)) {
+ nextToken();
+ } else if (FormatTok->is(tok::r_square)) {
+ nextToken();
+ return true;
+ } else {
+ return false;
+ }
+ } while (!eof());
+ return false;
+}
+
bool UnwrappedLineParser::tryToParseBracedList() {
if (FormatTok->BlockKind == BK_Unknown)
calculateBraceTypes();
@@ -667,6 +741,9 @@ void UnwrappedLineParser::parseBracedList() {
// 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_square:
+ tryToParseLambda();
+ break;
case tok::l_brace:
parseBracedList();
break;
@@ -710,6 +787,9 @@ void UnwrappedLineParser::parseReturn() {
nextToken();
addUnwrappedLine();
return;
+ case tok::l_square:
+ tryToParseLambda();
+ break;
default:
nextToken();
break;
OpenPOWER on IntegriCloud