diff options
author | Nico Weber <nicolasweber@gmx.de> | 2019-09-13 13:18:55 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2019-09-13 13:18:55 +0000 |
commit | 41f4d68a50beeaeb821baa29b5591a7146b98b05 (patch) | |
tree | 8febfa2728645ea0d7e8fbe20857fd8f2223a5b0 /clang/lib/Format/TokenAnnotator.cpp | |
parent | ab9acda026e4beee458a953f02fd8c342c89ad56 (diff) | |
download | bcm5719-llvm-41f4d68a50beeaeb821baa29b5591a7146b98b05.tar.gz bcm5719-llvm-41f4d68a50beeaeb821baa29b5591a7146b98b05.zip |
clang-format: Add support for formatting (some) lambdas with explicit template parameters.
This patch makes cases work where the lambda's template list doesn't
contain any of + - ! ~ / % << | || && ^ == != >= <= ? : true false
(see added FIXME).
Ports r359967 to clang-format.
Differential Revision: https://reviews.llvm.org/D67246
llvm-svn: 371854
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 55ab654f960..9802711834e 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -40,6 +40,21 @@ static bool canBeObjCSelectorComponent(const FormatToken &Tok) { return Tok.Tok.getIdentifierInfo() != nullptr; } +/// With `Left` being '(', check if we're at either `[...](` or +/// `[...]<...>(`, where the [ opens a lambda capture list. +static bool isLambdaParameterList(const FormatToken *Left) { + // Skip <...> if present. + if (Left->Previous && Left->Previous->is(tok::greater) && + Left->Previous->MatchingParen && + Left->Previous->MatchingParen->is(TT_TemplateOpener)) + Left = Left->Previous->MatchingParen; + + // Check for `[...]`. + return Left->Previous && Left->Previous->is(tok::r_square) && + Left->Previous->MatchingParen && + Left->Previous->MatchingParen->is(TT_LambdaLSquare); +} + /// A parser that gathers additional information about tokens. /// /// The \c TokenAnnotator tries to match parenthesis and square brakets and @@ -191,9 +206,7 @@ private: Left->Previous->is(TT_JsTypeColon)) { // let x: (SomeType); Contexts.back().IsExpression = false; - } else if (Left->Previous && Left->Previous->is(tok::r_square) && - Left->Previous->MatchingParen && - Left->Previous->MatchingParen->is(TT_LambdaLSquare)) { + } else if (isLambdaParameterList(Left)) { // This is a parameter list of a lambda expression. Contexts.back().IsExpression = false; } else if (Line.InPPDirective && |