r180625 - Comment parsing: -fparse-all-comments: recognize empty line comments
Dmitri Gribenko
gribozavr at gmail.com
Fri Apr 26 13:12:49 PDT 2013
Author: gribozavr
Date: Fri Apr 26 15:12:49 2013
New Revision: 180625
URL: http://llvm.org/viewvc/llvm-project?rev=180625&view=rev
Log:
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.
Modified:
cfe/trunk/lib/AST/RawCommentList.cpp
cfe/trunk/test/Index/parse-all-comments.c
Modified: cfe/trunk/lib/AST/RawCommentList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RawCommentList.cpp?rev=180625&r1=180624&r2=180625&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RawCommentList.cpp (original)
+++ cfe/trunk/lib/AST/RawCommentList.cpp Fri Apr 26 15:12:49 2013
@@ -21,8 +21,10 @@ using namespace clang;
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 ParseAllComments) {
+ const size_t MinCommentLength = ParseAllComments ? 2 : 3;
+ if ((Comment.size() < MinCommentLength) || Comment[0] != '/')
return std::make_pair(RawComment::RCK_Invalid, false);
RawComment::CommentKind K;
@@ -76,7 +78,7 @@ RawComment::RawComment(const SourceManag
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;
Modified: cfe/trunk/test/Index/parse-all-comments.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/parse-all-comments.c?rev=180625&r1=180624&r2=180625&view=diff
==============================================================================
--- cfe/trunk/test/Index/parse-all-comments.c (original)
+++ cfe/trunk/test/Index/parse-all-comments.c Fri Apr 26 15:12:49 2013
@@ -28,6 +28,11 @@ void isdoxy6(void);
/** 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 @@ void multi_line_comment_plus_ordinary(in
// 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
More information about the cfe-commits
mailing list