diff options
author | Daniel Jasper <djasper@google.com> | 2013-09-06 07:54:20 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-09-06 07:54:20 +0000 |
commit | 1c5d9df8d1af0f266923edba8fcb367a51a03d26 (patch) | |
tree | 390bc8bac153490c628dc129b01b5f34bd50ec32 /clang/lib/Format/TokenAnnotator.cpp | |
parent | 3b1cc9b858462aa190e3b27089f6f9f8c9dd9bb6 (diff) | |
download | bcm5719-llvm-1c5d9df8d1af0f266923edba8fcb367a51a03d26.tar.gz bcm5719-llvm-1c5d9df8d1af0f266923edba8fcb367a51a03d26.zip |
clang-format: Fix comment formatting bugs in nested blocks.
This fixes two issues:
1) The indent of a line comment was not adapted to the subsequent
statement as it would be outside of a nested block.
2) A missing DryRun flag caused actualy breaks to be inserted in
overly long comments while trying to come up with the best line
breaking decisions.
llvm-svn: 190123
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 46baab4aab3..2f3be557cec 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -974,9 +974,26 @@ private: } // end anonymous namespace +void +TokenAnnotator::setCommentLineLevels(SmallVectorImpl<AnnotatedLine *> &Lines) { + if (Lines.empty()) + return; + + const AnnotatedLine *NextNonCommentLine = NULL; + for (unsigned i = Lines.size() - 1; i > 0; --i) { + if (NextNonCommentLine && Lines[i]->First->is(tok::comment) && + !Lines[i]->First->Next) + Lines[i]->Level = NextNonCommentLine->Level; + else + NextNonCommentLine = + Lines[i]->First->isNot(tok::r_brace) ? Lines[i] : NULL; + } +} + void TokenAnnotator::annotate(AnnotatedLine &Line) { - for (std::vector<AnnotatedLine *>::iterator I = Line.Children.begin(), - E = Line.Children.end(); + setCommentLineLevels(Line.Children); + for (SmallVectorImpl<AnnotatedLine *>::iterator I = Line.Children.begin(), + E = Line.Children.end(); I != E; ++I) { annotate(**I); } @@ -1056,8 +1073,8 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { DEBUG({ printDebugInfo(Line); }); - for (std::vector<AnnotatedLine *>::iterator I = Line.Children.begin(), - E = Line.Children.end(); + for (SmallVectorImpl<AnnotatedLine *>::iterator I = Line.Children.begin(), + E = Line.Children.end(); I != E; ++I) { calculateFormattingInformation(**I); } |