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.cpp25
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);
}
OpenPOWER on IntegriCloud