diff options
author | Manuel Klimek <klimek@google.com> | 2013-09-04 13:25:30 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-09-04 13:25:30 +0000 |
commit | 516e054c05fcf92b89fbac3e22048f2c00cf218f (patch) | |
tree | 9cf51038c5b86a23d7a0833e7c43bcf5459804d6 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | dc647a2603712672e705479497d6f6bff53e027e (diff) | |
download | bcm5719-llvm-516e054c05fcf92b89fbac3e22048f2c00cf218f.tar.gz bcm5719-llvm-516e054c05fcf92b89fbac3e22048f2c00cf218f.zip |
Implement parsing of blocks (^{ ... }) in the unwrapped line parser.
This patch makes sure we produce the right number of unwrapped lines,
a follow-up patch will make the whitespace formatting consistent.
Before:
void f() {
int i = {[operation setCompletionBlock : ^{ [self onOperationDone];
}]
}
;
}
After:
void f() {
int i = {[operation setCompletionBlock : ^{
[self onOperationDone];
}] };
}
llvm-svn: 189932
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index f58ee823032..c780fdb566d 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -346,6 +346,20 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel) { Line->Level = InitialLevel; } +void UnwrappedLineParser::parseChildBlock() { + FormatTok->BlockKind = BK_Block; + nextToken(); + { + ScopedLineState LineState(*this); + ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack, + /*MustBeDeclaration=*/false); + Line->Level += 1; + parseLevel(/*HasOpeningBrace=*/true); + Line->Level -= 1; + } + nextToken(); +} + void UnwrappedLineParser::parsePPDirective() { assert(FormatTok->Tok.is(tok::hash) && "'#' expected"); ScopedMacroState MacroState(*Line, Tokens, FormatTok, StructuralError); @@ -591,6 +605,12 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::l_paren: parseParens(); break; + case tok::caret: + nextToken(); + if (FormatTok->is(tok::l_brace)) { + parseChildBlock(); + } + break; case tok::l_brace: if (!tryToParseBracedList()) { // A block outside of parentheses must be the last part of a @@ -674,17 +694,7 @@ void UnwrappedLineParser::tryToParseLambda() { break; } } - FormatTok->BlockKind = BK_Block; - nextToken(); - { - ScopedLineState LineState(*this); - ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack, - /*MustBeDeclaration=*/false); - Line->Level += 1; - parseLevel(/*HasOpeningBrace=*/true); - Line->Level -= 1; - } - nextToken(); + parseChildBlock(); } bool UnwrappedLineParser::tryToParseLambdaIntroducer() { @@ -741,9 +751,15 @@ 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::caret: + nextToken(); + if (FormatTok->is(tok::l_brace)) { + parseChildBlock(); + } + break; + case tok::l_square: + tryToParseLambda(); + break; case tok::l_brace: // Assume there are no blocks inside a braced init list apart // from the ones we explicitly parse out (like lambdas). |