From 557a8d568bd7f32b6695162eba3be07787d9e779 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Tue, 28 Aug 2012 01:20:53 +0000 Subject: Merging consecutive comments: be more conservative. Should fix part 2 of PR13374. llvm-svn: 162723 --- clang/lib/AST/RawCommentList.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'clang/lib/AST/RawCommentList.cpp') diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp index a5a32870577..d75d49aff0f 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; -- cgit v1.2.1