diff options
author | Daniel Jasper <djasper@google.com> | 2014-11-14 13:03:40 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-11-14 13:03:40 +0000 |
commit | 6c22c44e12ac0082aabb467607c77cd09a4f025c (patch) | |
tree | c1e82f80021e559408fa53e867e49b1188725ec8 /clang/lib/Format/TokenAnnotator.cpp | |
parent | ba7308c07e6d57b020eeb6915220fdc9636edd46 (diff) | |
download | bcm5719-llvm-6c22c44e12ac0082aabb467607c77cd09a4f025c.tar.gz bcm5719-llvm-6c22c44e12ac0082aabb467607c77cd09a4f025c.zip |
clang-format: Support assignments as conditional operands.
Before:
return a != b
// comment
? a
: a = a != b
// comment
? a =
b : a;
After:
return a != b
// comment
? a
: a = a != b
// comment
? a = b
: a;
llvm-svn: 221987
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index cb945c6161b..5234de2bb7d 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1120,7 +1120,9 @@ public: // At the end of the line or when an operator with higher precedence is // found, insert fake parenthesis and return. if (!Current || (Current->closesScope() && Current->MatchingParen) || - (CurrentPrecedence != -1 && CurrentPrecedence < Precedence)) { + (CurrentPrecedence != -1 && CurrentPrecedence < Precedence) || + (CurrentPrecedence == prec::Conditional && + Precedence == prec::Assignment && Current->is(tok::colon))) { if (LatestOperator) { LatestOperator->LastOperator = true; if (Precedence == PrecedenceArrowAndPeriod) { @@ -1220,11 +1222,11 @@ private: if (!Current || !Current->is(tok::question)) return; next(); - parseConditionalExpr(); + parse(prec::Assignment); if (!Current || Current->Type != TT_ConditionalExpr) return; next(); - parseConditionalExpr(); + parse(prec::Assignment); addFakeParenthesis(Start, prec::Conditional); } |