summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index ac45859a5ae..13d3facb079 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1013,22 +1013,21 @@ private:
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;
+ for (SmallVectorImpl<AnnotatedLine *>::reverse_iterator I = Lines.rbegin(),
+ E = Lines.rend();
+ I != E; ++I) {
+ if (NextNonCommentLine && (*I)->First->is(tok::comment) &&
+ (*I)->First->Next == NULL)
+ (*I)->Level = NextNonCommentLine->Level;
else
- NextNonCommentLine =
- Lines[i]->First->isNot(tok::r_brace) ? Lines[i] : NULL;
+ NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : NULL;
+
+ setCommentLineLevels((*I)->Children);
}
}
void TokenAnnotator::annotate(AnnotatedLine &Line) {
- setCommentLineLevels(Line.Children);
for (SmallVectorImpl<AnnotatedLine *>::iterator I = Line.Children.begin(),
E = Line.Children.end();
I != E; ++I) {
OpenPOWER on IntegriCloud