Comment parsing: extract TableGen'able pieces into new CommandTraits class.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161548 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/CommentBriefParser.cpp b/lib/AST/CommentBriefParser.cpp
index 22209c0..0aebc1e 100644
--- a/lib/AST/CommentBriefParser.cpp
+++ b/lib/AST/CommentBriefParser.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/AST/CommentBriefParser.h"
+#include "clang/AST/CommentCommandTraits.h"
 #include "llvm/ADT/StringSwitch.h"
 
 namespace clang {
@@ -39,20 +40,14 @@
 
   S.resize(O - S.begin());
 }
-
-bool isBlockCommand(StringRef Name) {
-  return llvm::StringSwitch<bool>(Name)
-      .Cases("brief", "short", true)
-      .Cases("result", "return", "returns", true)
-      .Cases("author", "authors", true)
-      .Case("pre", true)
-      .Case("post", true)
-      .Cases("param", "arg", true)
-      .Case("tparam", true)
-      .Default(false);
-}
 } // unnamed namespace
 
+BriefParser::BriefParser(Lexer &L, const CommandTraits &Traits) :
+    L(L), Traits(Traits) {
+  // Get lookahead token.
+  ConsumeToken();
+}
+
 std::string BriefParser::Parse() {
   std::string FirstParagraphOrBrief;
   std::string ReturnsParagraph;
@@ -72,18 +67,18 @@
 
     if (Tok.is(tok::command)) {
       StringRef Name = Tok.getCommandName();
-      if (Name == "brief" || Name == "short") {
+      if (Traits.isBriefCommand(Name)) {
         FirstParagraphOrBrief.clear();
         InBrief = true;
         ConsumeToken();
         continue;
       }
-      if (Name == "result" || Name == "return" || Name == "returns") {
+      if (Traits.isReturnsCommand(Name)) {
         InReturns = true;
         ReturnsParagraph += "Returns ";
       }
       // Block commands implicitly start a new paragraph.
-      if (isBlockCommand(Name)) {
+      if (Traits.isBlockCommand(Name)) {
         // We found an implicit paragraph end.
         InFirstParagraph = false;
         if (InBrief)
@@ -121,11 +116,6 @@
   return ReturnsParagraph;
 }
 
-BriefParser::BriefParser(Lexer &L) : L(L) {
-  // Get lookahead token.
-  ConsumeToken();
-}
-
 } // end namespace comments
 } // end namespace clang