From d1db12540e572d6e3d998a4b770a6b2c7267d7fc Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Thu, 9 Aug 2012 17:33:20 +0000 Subject: [PATCH] Comment to HTML and XML conversion: use CommandTraits to classify commands. This also fixes a bug in comment to XML conversion: \result was just an ordinary paragraph, not an alias for \returns. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161596 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/CommentCommandTraits.h | 2 ++ test/Index/annotate-comments.cpp | 2 +- tools/libclang/CXComment.cpp | 14 +++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/clang/AST/CommentCommandTraits.h b/include/clang/AST/CommentCommandTraits.h index 85f2d82a4c..91ce1fd6dd 100644 --- a/include/clang/AST/CommentCommandTraits.h +++ b/include/clang/AST/CommentCommandTraits.h @@ -28,6 +28,8 @@ namespace comments { /// in comments. class CommandTraits { public: + CommandTraits() { } + /// \brief Check if a given command is a verbatim-like block command. /// /// A verbatim-like block command eats every character (except line starting diff --git a/test/Index/annotate-comments.cpp b/test/Index/annotate-comments.cpp index 765d996494..f35c238883 100644 --- a/test/Index/annotate-comments.cpp +++ b/test/Index/annotate-comments.cpp @@ -587,7 +587,7 @@ enum class comment_to_xml_conversion_17 { // CHECK-NEXT: (CXComment_BlockCommand CommandName=[returns] // CHECK-NEXT: (CXComment_Paragraph // CHECK-NEXT: (CXComment_Text Text=[ Bbb.]))))] -// CHECK: annotate-comments.cpp:262:6: FunctionDecl=comment_to_html_conversion_9:{{.*}} FullCommentAsHTML=[

Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_9c:@F@comment_to_html_conversion_9# Aaa. Bbb.] +// CHECK: annotate-comments.cpp:262:6: FunctionDecl=comment_to_html_conversion_9:{{.*}} FullCommentAsHTML=[

Aaa.

Returns Bbb.

] FullCommentAsXML=[comment_to_html_conversion_9c:@F@comment_to_html_conversion_9# Aaa. Bbb.] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp index 4606fdced9..0bb6ab7878 100644 --- a/tools/libclang/CXComment.cpp +++ b/tools/libclang/CXComment.cpp @@ -18,6 +18,7 @@ #include "CXTranslationUnit.h" #include "clang/AST/CommentVisitor.h" +#include "clang/AST/CommentCommandTraits.h" #include "clang/AST/Decl.h" #include "clang/Frontend/ASTUnit.h" @@ -416,6 +417,7 @@ struct FullCommentParts { FullCommentParts::FullCommentParts(const FullComment *C) : Brief(NULL), FirstParagraph(NULL), Returns(NULL) { + const CommandTraits Traits; for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); I != E; ++I) { const Comment *Child = *I; @@ -439,11 +441,11 @@ FullCommentParts::FullCommentParts(const FullComment *C) : case Comment::BlockCommandCommentKind: { const BlockCommandComment *BCC = cast(Child); StringRef CommandName = BCC->getCommandName(); - if (!Brief && (CommandName == "brief" || CommandName == "short")) { + if (!Brief && Traits.isBriefCommand(CommandName)) { Brief = BCC; break; } - if (!Returns && (CommandName == "returns" || CommandName == "return")) { + if (!Returns && Traits.isReturnsCommand(CommandName)) { Returns = BCC; break; } @@ -553,6 +555,8 @@ public: void appendToResultWithHTMLEscaping(StringRef S); private: + const CommandTraits Traits; + /// Output stream for HTML. llvm::raw_svector_ostream Result; }; @@ -628,14 +632,13 @@ void CommentASTToHTMLConverter::visitParagraphComment( void CommentASTToHTMLConverter::visitBlockCommandComment( const BlockCommandComment *C) { StringRef CommandName = C->getCommandName(); - if (CommandName == "brief" || CommandName == "short") { + if (Traits.isBriefCommand(CommandName)) { Result << "

"; visitNonStandaloneParagraphComment(C->getParagraph()); Result << "

"; return; } - if (CommandName == "returns" || CommandName == "return" || - CommandName == "result") { + if (Traits.isReturnsCommand(CommandName)) { Result << "

" "Returns "; visitNonStandaloneParagraphComment(C->getParagraph()); @@ -862,6 +865,7 @@ public: private: const SourceManager &SM; + /// Output stream for XML. llvm::raw_svector_ostream Result; }; -- 2.40.0