Dmitri Gribenko | aa58081 | 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 | |
Dmitri Gribenko | 81c53b4 | 2012-08-16 20:16:11 +0000 | [diff] [blame] | 18 | bool CommandTraits::isVerbatimBlockCommand(StringRef StartName, |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 19 | StringRef &EndName) const { |
Dmitri Gribenko | 81c53b4 | 2012-08-16 20:16:11 +0000 | [diff] [blame] | 20 | const char *Result = llvm::StringSwitch<const char *>(StartName) |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 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) |
Dmitri Gribenko | 81c53b4 | 2012-08-16 20:16:11 +0000 | [diff] [blame] | 47 | if (I->StartName == StartName) { |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 48 | EndName = I->EndName; |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | bool CommandTraits::isVerbatimLineCommand(StringRef Name) const { |
Dmitri Gribenko | 62290ae | 2012-08-09 18:20:29 +0000 | [diff] [blame] | 56 | bool Result = isDeclarationCommand(Name) || llvm::StringSwitch<bool>(Name) |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 57 | .Case("defgroup", true) |
| 58 | .Case("ingroup", true) |
| 59 | .Case("addtogroup", true) |
| 60 | .Case("weakgroup", true) |
| 61 | .Case("name", true) |
| 62 | |
| 63 | .Case("section", true) |
| 64 | .Case("subsection", true) |
| 65 | .Case("subsubsection", true) |
| 66 | .Case("paragraph", true) |
| 67 | |
| 68 | .Case("mainpage", true) |
| 69 | .Case("subpage", true) |
| 70 | .Case("ref", true) |
| 71 | |
| 72 | .Default(false); |
| 73 | |
| 74 | if (Result) |
| 75 | return true; |
| 76 | |
| 77 | for (VerbatimLineCommandVector::const_iterator |
| 78 | I = VerbatimLineCommands.begin(), |
| 79 | E = VerbatimLineCommands.end(); |
| 80 | I != E; ++I) |
| 81 | if (I->Name == Name) |
| 82 | return true; |
| 83 | |
| 84 | return false; |
| 85 | } |
| 86 | |
Dmitri Gribenko | 62290ae | 2012-08-09 18:20:29 +0000 | [diff] [blame] | 87 | bool CommandTraits::isDeclarationCommand(StringRef Name) const { |
| 88 | return llvm::StringSwitch<bool>(Name) |
| 89 | // Doxygen commands. |
| 90 | .Case("fn", true) |
| 91 | .Case("var", true) |
| 92 | .Case("property", true) |
| 93 | .Case("typedef", true) |
| 94 | |
| 95 | .Case("overload", true) |
| 96 | |
| 97 | // HeaderDoc commands. |
| 98 | .Case("class", true) |
| 99 | .Case("interface", true) |
| 100 | .Case("protocol", true) |
| 101 | .Case("category", true) |
| 102 | .Case("template", true) |
| 103 | .Case("function", true) |
| 104 | .Case("method", true) |
| 105 | .Case("callback", true) |
| 106 | .Case("var", true) |
| 107 | .Case("const", true) |
| 108 | .Case("constant", true) |
| 109 | .Case("property", true) |
| 110 | .Case("struct", true) |
| 111 | .Case("union", true) |
| 112 | .Case("typedef", true) |
| 113 | .Case("enum", true) |
| 114 | |
| 115 | .Default(false); |
| 116 | } |
| 117 | |
Dmitri Gribenko | 81c53b4 | 2012-08-16 20:16:11 +0000 | [diff] [blame] | 118 | void CommandTraits::addVerbatimBlockCommand(StringRef StartName, |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 119 | StringRef EndName) { |
| 120 | VerbatimBlockCommand VBC; |
Dmitri Gribenko | 81c53b4 | 2012-08-16 20:16:11 +0000 | [diff] [blame] | 121 | VBC.StartName = StartName; |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 122 | VBC.EndName = EndName; |
| 123 | VerbatimBlockCommands.push_back(VBC); |
| 124 | } |
| 125 | |
| 126 | void CommandTraits::addVerbatimLineCommand(StringRef Name) { |
| 127 | VerbatimLineCommand VLC; |
| 128 | VLC.Name = Name; |
| 129 | VerbatimLineCommands.push_back(VLC); |
| 130 | } |
| 131 | |
| 132 | } // end namespace comments |
| 133 | } // end namespace clang |
| 134 | |