From d52b20c706326cc2c5c3707a902e7ca4474719b6 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 21 Jun 2013 23:49:29 +0000 Subject: [PATCH] [document parsing]: Allow multiple adjacent \return and the like commands. Render them properly in XML output. // rdar://14207725 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184610 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/CommentSema.cpp | 5 ++--- test/Index/comment-to-html-xml-conversion.cpp | 13 ++++++------ test/Sema/warn-documentation.cpp | 4 ---- tools/libclang/CXComment.cpp | 21 ++++++++++++------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index 06f23462ef..12b4876e30 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -624,11 +624,10 @@ void Sema::checkBlockCommandDuplicate(const BlockCommandComment *Command) { } PrevCommand = BriefCommand; } else if (Info->IsReturnsCommand) { - if (!ReturnsCommand) { + if (!ReturnsCommand) ReturnsCommand = Command; - return; - } PrevCommand = ReturnsCommand; + return; } else if (Info->IsHeaderfileCommand) { if (!HeaderfileCommand) { HeaderfileCommand = Command; diff --git a/test/Index/comment-to-html-xml-conversion.cpp b/test/Index/comment-to-html-xml-conversion.cpp index c770ca8d30..590643590f 100644 --- a/test/Index/comment-to-html-xml-conversion.cpp +++ b/test/Index/comment-to-html-xml-conversion.cpp @@ -116,7 +116,8 @@ void comment_to_html_conversion_6(); /// \return Bbb. void comment_to_html_conversion_7(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_7:{{.*}} FullCommentAsHTML=[

Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_7c:@F@comment_to_html_conversion_7#void comment_to_html_conversion_7() Aaa. Bbb.] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_7:{{.*}} FullCommentAsHTML=[

Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_7c:@F@comment_to_html_conversion_7#void comment_to_html_conversion_7() Aaa. Bbb.] + // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph @@ -132,7 +133,7 @@ void comment_to_html_conversion_7(); /// \returns Bbb. void comment_to_html_conversion_8(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_8:{{.*}} FullCommentAsHTML=[

Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_8c:@F@comment_to_html_conversion_8#void comment_to_html_conversion_8() Aaa. Bbb.] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_8:{{.*}} FullCommentAsHTML=[

Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_8c:@F@comment_to_html_conversion_8#void comment_to_html_conversion_8() Aaa. Bbb.] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph @@ -148,7 +149,7 @@ void comment_to_html_conversion_8(); /// \result Bbb. void comment_to_html_conversion_9(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_9:{{.*}} FullCommentAsHTML=[

Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_9c:@F@comment_to_html_conversion_9#void comment_to_html_conversion_9() Aaa. Bbb.] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_9:{{.*}} FullCommentAsHTML=[

Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_9c:@F@comment_to_html_conversion_9#void comment_to_html_conversion_9() Aaa. Bbb.] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph @@ -163,7 +164,7 @@ void comment_to_html_conversion_9(); /// \returns Bbb. void comment_to_html_conversion_10(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_10:{{.*}} FullCommentAsHTML=[

Returns Bbb.

Returns Aaa.

] FullCommentAsXML=[comment_to_html_conversion_10c:@F@comment_to_html_conversion_10#void comment_to_html_conversion_10() Aaa. Bbb.] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_10:{{.*}} FullCommentAsHTML=[

Returns Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_10c:@F@comment_to_html_conversion_10#void comment_to_html_conversion_10() Aaa. Bbb.] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph IsWhitespace @@ -183,7 +184,7 @@ void comment_to_html_conversion_10(); /// \returns Ccc. void comment_to_html_conversion_11(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_11:{{.*}} FullCommentAsHTML=[

Aaa.

Bbb.

Returns Ccc.

] FullCommentAsXML=[comment_to_html_conversion_11c:@F@comment_to_html_conversion_11#void comment_to_html_conversion_11() Aaa. Ccc. Bbb.] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_11:{{.*}} FullCommentAsHTML=[

Aaa.

Bbb.

Returns Ccc.

] FullCommentAsXML=[comment_to_html_conversion_11c:@F@comment_to_html_conversion_11#void comment_to_html_conversion_11() Aaa. Ccc. Bbb.] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph @@ -387,7 +388,7 @@ void comment_to_html_conversion_21(); /// \returns Eee. void comment_to_html_conversion_22(int x1, int x2); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_22:{{.*}} FullCommentAsHTML=[

Aaa.

Bbb.

x1
Ccc.
x2
Ddd.

Returns Eee.

] FullCommentAsXML=[comment_to_html_conversion_22c:@F@comment_to_html_conversion_22#I#I#void comment_to_html_conversion_22(int x1, int x2) Aaa.x10in Ccc. x21in Ddd. Eee. Bbb.] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_22:{{.*}} FullCommentAsHTML=[

Aaa.

Bbb.

x1
Ccc.
x2
Ddd.

Returns Eee.

] FullCommentAsXML=[comment_to_html_conversion_22c:@F@comment_to_html_conversion_22#I#I#void comment_to_html_conversion_22(int x1, int x2) Aaa.x10in Ccc. x21in Ddd. Eee. Bbb.] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph IsWhitespace diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp index 1306ac991f..27a13ab97c 100644 --- a/test/Sema/warn-documentation.cpp +++ b/test/Sema/warn-documentation.cpp @@ -136,7 +136,6 @@ int test_duplicate_brief2(int); int test_duplicate_brief3(int); -// expected-warning@+5 {{duplicated command '\return'}} expected-note@+1 {{previous command '\return' here}} /// \return Aaa /// /// Bbb @@ -144,7 +143,6 @@ int test_duplicate_brief3(int); /// \return Ccc int test_duplicate_returns1(int); -// expected-warning@+5 {{duplicated command '\returns'}} expected-note@+1 {{previous command '\returns' here}} /// \returns Aaa /// /// Bbb @@ -152,7 +150,6 @@ int test_duplicate_returns1(int); /// \returns Ccc int test_duplicate_returns2(int); -// expected-warning@+5 {{duplicated command '\result'}} expected-note@+1 {{previous command '\result' here}} /// \result Aaa /// /// Bbb @@ -160,7 +157,6 @@ int test_duplicate_returns2(int); /// \result Ccc int test_duplicate_returns3(int); -// expected-warning@+5 {{duplicated command '\return'}} expected-note@+1 {{previous command '\returns' (an alias of '\return') here}} /// \returns Aaa /// /// Bbb diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp index 1c127e1589..b96ca1c47f 100644 --- a/tools/libclang/CXComment.cpp +++ b/tools/libclang/CXComment.cpp @@ -412,7 +412,7 @@ struct FullCommentParts { const BlockContentComment *Brief; const BlockContentComment *Headerfile; const ParagraphComment *FirstParagraph; - const BlockCommandComment *Returns; + SmallVector Returns; SmallVector Params; SmallVector TParams; SmallVector MiscBlocks; @@ -420,7 +420,7 @@ struct FullCommentParts { FullCommentParts::FullCommentParts(const FullComment *C, const CommandTraits &Traits) : - Brief(NULL), Headerfile(NULL), FirstParagraph(NULL), Returns(NULL) { + Brief(NULL), Headerfile(NULL), FirstParagraph(NULL) { for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); I != E; ++I) { const Comment *Child = *I; @@ -452,8 +452,8 @@ FullCommentParts::FullCommentParts(const FullComment *C, Headerfile = BCC; break; } - if (!Returns && Info->IsReturnsCommand) { - Returns = BCC; + if (Info->IsReturnsCommand) { + Returns.push_back(BCC); break; } MiscBlocks.push_back(BCC); @@ -786,8 +786,12 @@ void CommentASTToHTMLConverter::visitFullComment(const FullComment *C) { Result << ""; } - if (Parts.Returns) - visit(Parts.Returns); + if (Parts.Returns.size() != 0) { + Result << "
"; + for (unsigned i = 0, e = Parts.Returns.size(); i != e; ++i) + visit(Parts.Returns[i]); + Result << "
"; + } Result.flush(); } @@ -1297,9 +1301,10 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { Result << ""; } - if (Parts.Returns) { + if (Parts.Returns.size() != 0) { Result << ""; - visit(Parts.Returns); + for (unsigned i = 0, e = Parts.Returns.size(); i != e; ++i) + visit(Parts.Returns[i]); Result << ""; } -- 2.40.0