diff options
-rw-r--r-- | include/clang/AST/CommentCommandTraits.h | 2 | ||||
-rw-r--r-- | test/Index/annotate-comments.cpp | 2 | ||||
-rw-r--r-- | 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=[<p class="para-brief"> Aaa.</p><p class="para-returns"><span class="word-returns">Returns</span> Bbb.</p>] FullCommentAsXML=[<Function file="{{[^"]+}}annotate-comments.cpp" line="262" column="6"><Name>comment_to_html_conversion_9</Name><USR>c:@F@comment_to_html_conversion_9#</USR><Abstract><Para> Aaa.</Para></Abstract><Discussion><Para> Bbb.</Para></Discussion></Function>] +// CHECK: annotate-comments.cpp:262:6: FunctionDecl=comment_to_html_conversion_9:{{.*}} FullCommentAsHTML=[<p class="para-brief"> Aaa.</p><p class="para-returns"><span class="word-returns">Returns</span> Bbb.</p>] FullCommentAsXML=[<Function file="{{[^"]+}}annotate-comments.cpp" line="262" column="6"><Name>comment_to_html_conversion_9</Name><USR>c:@F@comment_to_html_conversion_9#</USR><Abstract><Para> Aaa.</Para></Abstract><ResultDiscussion><Para> Bbb.</Para></ResultDiscussion></Function>] // 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<BlockCommandComment>(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 << "<p class=\"para-brief\">"; visitNonStandaloneParagraphComment(C->getParagraph()); Result << "</p>"; return; } - if (CommandName == "returns" || CommandName == "return" || - CommandName == "result") { + if (Traits.isReturnsCommand(CommandName)) { Result << "<p class=\"para-returns\">" "<span class=\"word-returns\">Returns</span> "; visitNonStandaloneParagraphComment(C->getParagraph()); @@ -862,6 +865,7 @@ public: private: const SourceManager &SM; + /// Output stream for XML. llvm::raw_svector_ostream Result; }; |