diff options
author | Daniel Jasper <djasper@google.com> | 2012-12-06 13:16:39 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-12-06 13:16:39 +0000 |
commit | d56a737842f28db4403430082c4d2686bc6cc3b3 (patch) | |
tree | 8dd53289fdb8f05835b1c149dc3996a3b3bd5e98 /lib/Format/Format.cpp | |
parent | 4a29065eb189b6132b82c071f75af84799ede0e7 (diff) |
Improve clang-format's handling of unary operators.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169500 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r-- | lib/Format/Format.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 08096866bf..51db69c5ae 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -618,12 +618,24 @@ private: bool isUnaryOperator(unsigned Index) { const Token &Tok = Line.Tokens[Index].Tok; + + // '++', '--' and '!' are always unary operators. + if (Tok.is(tok::minusminus) || Tok.is(tok::plusplus) || + Tok.is(tok::exclaim)) + return true; + + // The other possible unary operators are '+' and '-' as we + // determine the usage of '*' and '&' in determineStarAmpUsage(). if (Tok.isNot(tok::minus) && Tok.isNot(tok::plus)) return false; + + // Use heuristics to recognize unary operators. const Token &PreviousTok = Line.Tokens[Index - 1].Tok; if (PreviousTok.is(tok::equal) || PreviousTok.is(tok::l_paren) || PreviousTok.is(tok::comma) || PreviousTok.is(tok::l_square)) return true; + + // Fall back to marking the token as binary operator. return Annotations[Index - 1].Type == TokenAnnotation::TT_BinaryOperator; } |