[PATCH] Multi-line ordinary comments with empty lines in between (starting with //) do not get merged when -fparse-all-comments option is passed.

Amin Shali amshali at gmail.com
Tue Apr 23 17:21:12 PDT 2013


Hi gribozavr,

Multi-line ordinary comments with empty lines in between (starting with //) do not get merged when -fparse-all-comments option is passed.
The issue is that the kind of comment is determined to be "invalid" because we do not take into account the -fparse-all-comments option. As a result if for example one has a comment like this:

  // line 1
  //
  // line 2
  int x;                                                                                                                                                                                 
The only comment attached to the "x" is "// line 2", which is the issue.

This patch fixes this issue. Added a test.


http://llvm-reviews.chandlerc.com/D716

Files:
  lib/AST/RawCommentList.cpp
  test/Index/parse-all-comments.c

Index: lib/AST/RawCommentList.cpp
===================================================================
--- lib/AST/RawCommentList.cpp
+++ lib/AST/RawCommentList.cpp
@@ -21,8 +21,9 @@
 
 namespace {
 /// Get comment kind and bool describing if it is a trailing comment.
-std::pair<RawComment::CommentKind, bool> getCommentKind(StringRef Comment) {
-  if (Comment.size() < 3 || Comment[0] != '/')
+std::pair<RawComment::CommentKind, bool> getCommentKind(StringRef Comment,
+                                                        bool ParseAllComment) {
+  if ((Comment.size() < 3 && !ParseAllComment) || Comment[0] != '/')
     return std::make_pair(RawComment::RCK_Invalid, false);
 
   RawComment::CommentKind K;
@@ -76,7 +77,7 @@
 
   if (!Merged) {
     // Guess comment kind.
-    std::pair<CommentKind, bool> K = getCommentKind(RawText);
+    std::pair<CommentKind, bool> K = getCommentKind(RawText, ParseAllComments);
     Kind = K.first;
     IsTrailingComment = K.second;
 
Index: test/Index/parse-all-comments.c
===================================================================
--- test/Index/parse-all-comments.c
+++ test/Index/parse-all-comments.c
@@ -28,6 +28,11 @@
 /** But there are other blocks that are part of the comment, too.  IS_DOXYGEN_END */
 void multi_line_comment_plus_ordinary(int);
 
+// MULTILINE COMMENT
+//
+// WITH EMPTY LINE
+void multi_line_comment_empty_line(int);
+
 #endif
 
 // RUN: rm -rf %t
@@ -54,3 +59,4 @@
 // CHECK: parse-all-comments.c:19:6: FunctionDecl=isdoxy5:{{.*}} isdoxy5 IS_DOXYGEN_SINGLE
 // CHECK: parse-all-comments.c:22:6: FunctionDecl=isdoxy6:{{.*}} isdoxy6 IS_DOXYGEN_SINGLE
 // CHECK: parse-all-comments.c:29:6: FunctionDecl=multi_line_comment_plus_ordinary:{{.*}} BLOCK_ORDINARY_COMMENT {{.*}} ORDINARY COMMENT {{.*}} IS_DOXYGEN_START {{.*}} IS_DOXYGEN_END
+// CHECK: parse-all-comments.c:34:6: FunctionDecl=multi_line_comment_empty_line:{{.*}} MULTILINE COMMENT{{.*}}\n{{.*}}\n{{.*}} WITH EMPTY LINE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D716.1.patch
Type: text/x-patch
Size: 1961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130423/257c4f34/attachment.bin>


More information about the llvm-commits mailing list