Dmitri Gribenko | ca7f80a | 2012-08-09 00:03:17 +0000 | [diff] [blame^] | 1 | //===--- CommentCommandTraits.cpp - Comment command properties --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/AST/CommentCommandTraits.h" |
| 11 | #include "llvm/ADT/StringSwitch.h" |
| 12 | |
| 13 | namespace clang { |
| 14 | namespace comments { |
| 15 | |
| 16 | // TODO: tablegen |
| 17 | |
| 18 | bool CommandTraits::isVerbatimBlockCommand(StringRef BeginName, |
| 19 | StringRef &EndName) const { |
| 20 | const char *Result = llvm::StringSwitch<const char *>(BeginName) |
| 21 | .Case("code", "endcode") |
| 22 | .Case("verbatim", "endverbatim") |
| 23 | .Case("htmlonly", "endhtmlonly") |
| 24 | .Case("latexonly", "endlatexonly") |
| 25 | .Case("xmlonly", "endxmlonly") |
| 26 | .Case("manonly", "endmanonly") |
| 27 | .Case("rtfonly", "endrtfonly") |
| 28 | |
| 29 | .Case("dot", "enddot") |
| 30 | .Case("msc", "endmsc") |
| 31 | |
| 32 | .Case("f$", "f$") // Inline LaTeX formula |
| 33 | .Case("f[", "f]") // Displayed LaTeX formula |
| 34 | .Case("f{", "f}") // LaTeX environment |
| 35 | |
| 36 | .Default(NULL); |
| 37 | |
| 38 | if (Result) { |
| 39 | EndName = Result; |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | for (VerbatimBlockCommandVector::const_iterator |
| 44 | I = VerbatimBlockCommands.begin(), |
| 45 | E = VerbatimBlockCommands.end(); |
| 46 | I != E; ++I) |
| 47 | if (I->BeginName == BeginName) { |
| 48 | EndName = I->EndName; |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | bool CommandTraits::isVerbatimLineCommand(StringRef Name) const { |
| 56 | bool Result = llvm::StringSwitch<bool>(Name) |
| 57 | .Case("fn", true) |
| 58 | .Case("var", true) |
| 59 | .Case("property", true) |
| 60 | .Case("typedef", true) |
| 61 | |
| 62 | .Case("overload", true) |
| 63 | |
| 64 | .Case("defgroup", true) |
| 65 | .Case("ingroup", true) |
| 66 | .Case("addtogroup", true) |
| 67 | .Case("weakgroup", true) |
| 68 | .Case("name", true) |
| 69 | |
| 70 | .Case("section", true) |
| 71 | .Case("subsection", true) |
| 72 | .Case("subsubsection", true) |
| 73 | .Case("paragraph", true) |
| 74 | |
| 75 | .Case("mainpage", true) |
| 76 | .Case("subpage", true) |
| 77 | .Case("ref", true) |
| 78 | |
| 79 | .Default(false); |
| 80 | |
| 81 | if (Result) |
| 82 | return true; |
| 83 | |
| 84 | for (VerbatimLineCommandVector::const_iterator |
| 85 | I = VerbatimLineCommands.begin(), |
| 86 | E = VerbatimLineCommands.end(); |
| 87 | I != E; ++I) |
| 88 | if (I->Name == Name) |
| 89 | return true; |
| 90 | |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | void CommandTraits::addVerbatimBlockCommand(StringRef BeginName, |
| 95 | StringRef EndName) { |
| 96 | VerbatimBlockCommand VBC; |
| 97 | VBC.BeginName = BeginName; |
| 98 | VBC.EndName = EndName; |
| 99 | VerbatimBlockCommands.push_back(VBC); |
| 100 | } |
| 101 | |
| 102 | void CommandTraits::addVerbatimLineCommand(StringRef Name) { |
| 103 | VerbatimLineCommand VLC; |
| 104 | VLC.Name = Name; |
| 105 | VerbatimLineCommands.push_back(VLC); |
| 106 | } |
| 107 | |
| 108 | } // end namespace comments |
| 109 | } // end namespace clang |
| 110 | |