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
diff --git a/include/clang/AST/CommentCommandTraits.h b/include/clang/AST/CommentCommandTraits.h
index 85f2d82..91ce1fd 100644
--- a/include/clang/AST/CommentCommandTraits.h
+++ b/include/clang/AST/CommentCommandTraits.h
@@ -28,6 +28,8 @@
 /// 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 765d996..f35c238 100644
--- a/test/Index/annotate-comments.cpp
+++ b/test/Index/annotate-comments.cpp
@@ -587,7 +587,7 @@
 // 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 4606fdc..0bb6ab7 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 @@
 
 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 @@
     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 @@
   void appendToResultWithHTMLEscaping(StringRef S);
 
 private:
+  const CommandTraits Traits;
+
   /// Output stream for HTML.
   llvm::raw_svector_ostream Result;
 };
@@ -628,14 +632,13 @@
 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 @@
 
 private:
   const SourceManager &SM;
+
   /// Output stream for XML.
   llvm::raw_svector_ostream Result;
 };