summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-06-07 16:02:52 +0000
committerAlexander Kornienko <alexfh@google.com>2013-06-07 16:02:52 +0000
commitdd7ece53a2958ab3910007f6521bbb078b33505c (patch)
tree8b16bfa4d9034dc88a102d1683c1ef6d1f937cba /clang/lib/Format/TokenAnnotator.cpp
parentcead69d4a3f80fa8684f5636a9469d043f4f7285 (diff)
downloadbcm5719-llvm-dd7ece53a2958ab3910007f6521bbb078b33505c.tar.gz
bcm5719-llvm-dd7ece53a2958ab3910007f6521bbb078b33505c.zip
Fixed calculation of penalty when breaking tokens.
Summary: Introduced two new style parameters: PenaltyBreakComment and PenaltyBreakString. Add penalty for each character of a breakable token beyond the column limit (this relates mainly to comments, as they are broken only on whitespace). Tuned PenaltyBreakComment to prefer comment breaking over breaking inside most binary expressions. Fixed a bug that prevented *, & and && from being considered TT_BinaryOperator in the presense of adjacent comments. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D933 llvm-svn: 183530
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 8b1382ed7c6..20709bbb306 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -103,13 +103,16 @@ private:
// '*' has to be a binary operator but determineStarAmpUsage() will
// categorize it as an unary operator, so set the right type here.
if (LookForDecls && CurrentToken->Next) {
- FormatToken *Prev = CurrentToken->Previous;
- FormatToken *Next = CurrentToken->Next;
- if (Prev->Previous->is(tok::identifier) &&
- Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
- CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
- Prev->Type = TT_BinaryOperator;
- LookForDecls = false;
+ FormatToken *Prev = CurrentToken->getPreviousNoneComment();
+ if (Prev) {
+ FormatToken *PrevPrev = Prev->getPreviousNoneComment();
+ FormatToken *Next = CurrentToken->Next;
+ if (PrevPrev && PrevPrev->is(tok::identifier) &&
+ Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
+ CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
+ Prev->Type = TT_BinaryOperator;
+ LookForDecls = false;
+ }
}
}
OpenPOWER on IntegriCloud