[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
Fri Apr 26 12:19:21 PDT 2013


No rush, just wanted to make sure this didn't go unnoticed.


--
*​ΛMIN*SHΛLI シ


On Tue, Apr 23, 2013 at 5:21 PM, Amin Shali <amshali at gmail.com> wrote:

> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130426/2663ce7c/attachment.html>


More information about the cfe-commits mailing list