diff options
| author | Daniel Jasper <djasper@google.com> | 2012-12-05 07:51:39 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2012-12-05 07:51:39 +0000 |
| commit | 426702dcd0bf1300800b0c023aff29755a8bdc3c (patch) | |
| tree | 9d8c58525fa5ca2da878742c7879d8b93b322534 /clang/lib/Format/Format.cpp | |
| parent | db47eac37d5b3aed35eba897712370e40e67eac0 (diff) | |
| download | bcm5719-llvm-426702dcd0bf1300800b0c023aff29755a8bdc3c.tar.gz bcm5719-llvm-426702dcd0bf1300800b0c023aff29755a8bdc3c.zip | |
Small tweaks to automatic formatting.
Recognize '!=' as a binary operator and assume that there are no
type definitions on the RHS of an assignment.
llvm-svn: 169363
Diffstat (limited to 'clang/lib/Format/Format.cpp')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index d928aa95804..22805f691e9 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -547,12 +547,16 @@ public: private: void determineTokenTypes() { + bool EqualEncountered = false; for (int i = 0, e = Line.Tokens.size(); i != e; ++i) { TokenAnnotation &Annotation = Annotations[i]; const FormatToken &Tok = Line.Tokens[i]; + if (Tok.Tok.is(tok::equal)) + EqualEncountered = true; + if (Tok.Tok.is(tok::star) || Tok.Tok.is(tok::amp)) - Annotation.Type = determineStarAmpUsage(i); + Annotation.Type = determineStarAmpUsage(i, EqualEncountered); else if (isUnaryOperator(i)) Annotation.Type = TokenAnnotation::TT_UnaryOperator; else if (isBinaryOperator(Line.Tokens[i])) @@ -583,6 +587,7 @@ private: switch (Tok.Tok.getKind()) { case tok::equal: case tok::equalequal: + case tok::exclaimequal: case tok::star: //case tok::amp: case tok::plus: @@ -598,7 +603,8 @@ private: } } - TokenAnnotation::TokenType determineStarAmpUsage(unsigned Index) { + TokenAnnotation::TokenType determineStarAmpUsage(unsigned Index, + bool EqualEncountered) { if (Index == Annotations.size()) return TokenAnnotation::TT_Unknown; @@ -611,6 +617,11 @@ private: Line.Tokens[Index + 1].Tok.isLiteral()) return TokenAnnotation::TT_BinaryOperator; + // It is very unlikely that we are going to find a pointer or reference type + // definition on the RHS of an assignment. + if (EqualEncountered) + return TokenAnnotation::TT_BinaryOperator; + return TokenAnnotation::TT_PointerOrReference; } |

