diff options
| author | Daniel Jasper <djasper@google.com> | 2012-12-21 10:20:02 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2012-12-21 10:20:02 +0000 |
| commit | ab7654e894f46112abaca50cb5e6855b0955928d (patch) | |
| tree | 3a316c7601f490049563b9b8520f3aa04bd89fc9 /clang/lib | |
| parent | 8dd404737b8fcfb0990b7365b775a29d6740d6fa (diff) | |
| download | bcm5719-llvm-ab7654e894f46112abaca50cb5e6855b0955928d.tar.gz bcm5719-llvm-ab7654e894f46112abaca50cb5e6855b0955928d.zip | |
Use OperatorPrecedence.h in clang-format
No indented functional changes other than handling more operators
correctly.
llvm-svn: 170875
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 9a0fa7d31de..d14c1ce5b55 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -19,6 +19,7 @@ #include "clang/Format/Format.h" #include "UnwrappedLineParser.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/OperatorPrecedence.h" #include "clang/Lex/Lexer.h" #include <string> @@ -650,11 +651,12 @@ private: TokenAnnotation &Annotation = Annotations[i]; const FormatToken &Tok = Line.Tokens[i]; - if (Tok.Tok.is(tok::equal) || Tok.Tok.is(tok::plusequal) || - Tok.Tok.is(tok::minusequal) || Tok.Tok.is(tok::starequal) || - Tok.Tok.is(tok::slashequal)) + if (getBinOpPrecedence(Tok.Tok.getKind(), true, true) == prec::Assignment) AssignmentEncountered = true; + if (Annotation.Type != TokenAnnotation::TT_Unknown) + continue; + if (Tok.Tok.is(tok::star) || Tok.Tok.is(tok::amp)) { Annotation.Type = determineStarAmpUsage(i, AssignmentEncountered); } else if (Tok.Tok.is(tok::minus) || Tok.Tok.is(tok::plus)) { @@ -663,9 +665,9 @@ private: Annotation.Type = determineIncrementUsage(i); } else if (Tok.Tok.is(tok::exclaim)) { Annotation.Type = TokenAnnotation::TT_UnaryOperator; - } else if (isBinaryOperator(Line.Tokens[i])) + } else if (isBinaryOperator(Line.Tokens[i])) { Annotation.Type = TokenAnnotation::TT_BinaryOperator; - else if (Tok.Tok.is(tok::comment)) { + } else if (Tok.Tok.is(tok::comment)) { StringRef Data(SourceMgr.getCharacterData(Tok.Tok.getLocation()), Tok.Tok.getLength()); if (Data.startswith("//")) @@ -677,23 +679,8 @@ private: } bool isBinaryOperator(const FormatToken &Tok) { - switch (Tok.Tok.getKind()) { - case tok::equal: - case tok::equalequal: - case tok::exclaimequal: - case tok::star: - //case tok::amp: - case tok::plus: - case tok::slash: - case tok::minus: - case tok::ampamp: - case tok::pipe: - case tok::pipepipe: - case tok::percent: - return true; - default: - return false; - } + // Comma is a binary operator, but does not behave a such wrt. formatting. + return getBinOpPrecedence(Tok.Tok.getKind(), true, true) > prec::Comma; } TokenAnnotation::TokenType determineStarAmpUsage(unsigned Index, @@ -796,12 +783,11 @@ private: if (Right.Tok.is(tok::r_paren) || Right.Tok.is(tok::l_brace) || Right.Tok.is(tok::comment) || Right.Tok.is(tok::greater)) return false; - if (isBinaryOperator(Left) || Right.Tok.is(tok::lessless) || - Right.Tok.is(tok::arrow) || Right.Tok.is(tok::period)) - return true; - return Right.Tok.is(tok::colon) || Left.Tok.is(tok::comma) || Left.Tok.is( - tok::semi) || Left.Tok.is(tok::equal) || Left.Tok.is(tok::ampamp) || - Left.Tok.is(tok::pipepipe) || Left.Tok.is(tok::l_brace) || + return (isBinaryOperator(Left) && Left.Tok.isNot(tok::lessless)) || + Left.Tok.is(tok::comma) || Right.Tok.is(tok::lessless) || + Right.Tok.is(tok::arrow) || Right.Tok.is(tok::period) || + Right.Tok.is(tok::colon) || Left.Tok.is(tok::semi) || + Left.Tok.is(tok::l_brace) || (Left.Tok.is(tok::l_paren) && !Right.Tok.is(tok::r_paren)); } |

