summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/RawCommentList.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-08-28 01:20:53 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-08-28 01:20:53 +0000
commit557a8d568bd7f32b6695162eba3be07787d9e779 (patch)
tree46b27e603dcba6da56ba861bced07be587385a18 /clang/lib/AST/RawCommentList.cpp
parent365be442c4f6da7cdf0ee6e0426d28345b10acd6 (diff)
Merging consecutive comments: be more conservative.
Should fix part 2 of PR13374. llvm-svn: 162723
Diffstat (limited to 'clang/lib/AST/RawCommentList.cpp')
-rw-r--r--clang/lib/AST/RawCommentList.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp
index a5a32870577a..d75d49aff0f4 100644
--- a/clang/lib/AST/RawCommentList.cpp
+++ b/clang/lib/AST/RawCommentList.cpp
@@ -244,15 +244,20 @@ void RawCommentList::addComment(const RawComment &RC,
// Merge comments only if there is only whitespace between them.
// Can't merge trailing and non-trailing comments.
- // Merge trailing comments if they are on same or consecutive lines.
+ // Merge comments if they are on same or consecutive lines.
+ bool Merged = false;
if (OnlyWhitespaceSeen &&
- (C1.isTrailingComment() == C2.isTrailingComment()) &&
- (!C1.isTrailingComment() ||
- C1.getEndLine(SourceMgr) + 1 >= C2.getBeginLine(SourceMgr))) {
- SourceRange MergedRange(C1.getSourceRange().getBegin(),
- C2.getSourceRange().getEnd());
- *Comments.back() = RawComment(SourceMgr, MergedRange, true);
- } else
+ (C1.isTrailingComment() == C2.isTrailingComment())) {
+ unsigned C1EndLine = C1.getEndLine(SourceMgr);
+ unsigned C2BeginLine = C2.getBeginLine(SourceMgr);
+ if (C1EndLine + 1 == C2BeginLine || C1EndLine == C2BeginLine) {
+ SourceRange MergedRange(C1.getSourceRange().getBegin(),
+ C2.getSourceRange().getEnd());
+ *Comments.back() = RawComment(SourceMgr, MergedRange, true);
+ Merged = true;
+ }
+ }
+ if (!Merged)
Comments.push_back(new (Allocator) RawComment(RC));
OnlyWhitespaceSeen = true;