diff options
| author | Daniel Jasper <djasper@google.com> | 2014-01-28 20:13:43 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-01-28 20:13:43 +0000 |
| commit | 559b63cbb94e7027fe73df929d63703a1a3bc0c9 (patch) | |
| tree | dd642652efd641c3e614fc1d688f15e6a77d74d7 /clang/lib/Format/TokenAnnotator.cpp | |
| parent | 5c65e7f345967189ca98f9ed88787d5487c77bb3 (diff) | |
| download | bcm5719-llvm-559b63cbb94e7027fe73df929d63703a1a3bc0c9.tar.gz bcm5719-llvm-559b63cbb94e7027fe73df929d63703a1a3bc0c9.zip | |
clang-format: Understand __attribute__s preceding parameter lists.
Before:
ReturnType __attribute__((unused))
function(int i);
After:
ReturnType __attribute__((unused))
function(int i);
This fixes llvm.org/PR18632.
llvm-svn: 200337
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index e0f3e57cd76..6e82b19148c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -109,6 +109,8 @@ private: } else if (AfterCaret) { // This is the parameter list of an ObjC block. Contexts.back().IsExpression = false; + } else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) { + Left->Type = TT_AttributeParen; } if (StartsObjCMethodExpr) { @@ -159,6 +161,9 @@ private: } } + if (Left->Type == TT_AttributeParen) + CurrentToken->Type = TT_AttributeParen; + if (!HasMultipleLines) Left->PackingKind = PPK_Inconclusive; else if (HasMultipleParametersOnALine) @@ -1332,9 +1337,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, if (Left.is(tok::colon)) return Left.Type != TT_ObjCMethodExpr; if (Right.is(tok::l_paren)) { - if (Left.is(tok::r_paren) && Left.MatchingParen && - Left.MatchingParen->Previous && - Left.MatchingParen->Previous->is(tok::kw___attribute)) + if (Left.is(tok::r_paren) && Left.Type == TT_AttributeParen) return true; return Line.Type == LT_ObjCDecl || Left.isOneOf(tok::kw_return, tok::kw_new, tok::kw_delete, @@ -1519,14 +1522,12 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, return false; if (Left.is(tok::equal) && Line.Type == LT_VirtualFunctionDecl) return false; - if (Left.Previous) { - if (Left.is(tok::l_paren) && Right.is(tok::l_paren) && - Left.Previous->is(tok::kw___attribute)) - return false; - if (Left.is(tok::l_paren) && (Left.Previous->Type == TT_BinaryOperator || - Left.Previous->Type == TT_CastRParen)) - return false; - } + if (Left.is(tok::l_paren) && Left.Type == TT_AttributeParen) + return false; + if (Left.is(tok::l_paren) && Left.Previous && + (Left.Previous->Type == TT_BinaryOperator || + Left.Previous->Type == TT_CastRParen)) + return false; if (Right.Type == TT_ImplicitStringLiteral) return false; @@ -1570,7 +1571,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, Right.isOneOf(tok::lessless, tok::arrow, tok::period, tok::colon, tok::l_square, tok::at) || (Left.is(tok::r_paren) && - Right.isOneOf(tok::identifier, tok::kw_const, tok::kw___attribute)) || + Right.isOneOf(tok::identifier, tok::kw_const)) || (Left.is(tok::l_paren) && !Right.is(tok::r_paren)); } |

