Skip to content
Snippets Groups Projects
Commit 002f9281 authored by Dmitri Gribenko's avatar Dmitri Gribenko
Browse files

Comment parsing: -fparse-all-comments: recognize empty line comments

In -fparse-all-comments mode empty '//' comments were recognized as
RCK_Invalid, and were not merged with next and previous lines.

Patch by Amin Shali.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180625 91177308-0d34-0410-b5e6-96231b3b80d8
parent a2c3646c
No related branches found
No related tags found
No related merge requests found
...@@ -21,8 +21,10 @@ using namespace clang; ...@@ -21,8 +21,10 @@ using namespace clang;
namespace { namespace {
/// Get comment kind and bool describing if it is a trailing comment. /// Get comment kind and bool describing if it is a trailing comment.
std::pair<RawComment::CommentKind, bool> getCommentKind(StringRef Comment) { std::pair<RawComment::CommentKind, bool> getCommentKind(StringRef Comment,
if (Comment.size() < 3 || Comment[0] != '/') bool ParseAllComments) {
const size_t MinCommentLength = ParseAllComments ? 2 : 3;
if ((Comment.size() < MinCommentLength) || Comment[0] != '/')
return std::make_pair(RawComment::RCK_Invalid, false); return std::make_pair(RawComment::RCK_Invalid, false);
RawComment::CommentKind K; RawComment::CommentKind K;
...@@ -76,7 +78,7 @@ RawComment::RawComment(const SourceManager &SourceMgr, SourceRange SR, ...@@ -76,7 +78,7 @@ RawComment::RawComment(const SourceManager &SourceMgr, SourceRange SR,
if (!Merged) { if (!Merged) {
// Guess comment kind. // Guess comment kind.
std::pair<CommentKind, bool> K = getCommentKind(RawText); std::pair<CommentKind, bool> K = getCommentKind(RawText, ParseAllComments);
Kind = K.first; Kind = K.first;
IsTrailingComment = K.second; IsTrailingComment = K.second;
......
...@@ -28,6 +28,11 @@ void isdoxy6(void); ...@@ -28,6 +28,11 @@ void isdoxy6(void);
/** But there are other blocks that are part of the comment, too. IS_DOXYGEN_END */ /** But there are other blocks that are part of the comment, too. IS_DOXYGEN_END */
void multi_line_comment_plus_ordinary(int); void multi_line_comment_plus_ordinary(int);
// MULTILINE COMMENT
//
// WITH EMPTY LINE
void multi_line_comment_empty_line(int);
#endif #endif
// RUN: rm -rf %t // RUN: rm -rf %t
...@@ -54,3 +59,4 @@ void multi_line_comment_plus_ordinary(int); ...@@ -54,3 +59,4 @@ void multi_line_comment_plus_ordinary(int);
// CHECK: parse-all-comments.c:19:6: FunctionDecl=isdoxy5:{{.*}} isdoxy5 IS_DOXYGEN_SINGLE // 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: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: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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment