blob: dc7a0bd1753286ba8eea3dd9430d25dd21b4cdc3 [file] [log] [blame]
Dmitri Gribenkoaa580812012-08-09 00:03:17 +00001//===--- 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
13namespace clang {
14namespace comments {
15
16// TODO: tablegen
17
Dmitri Gribenko81c53b42012-08-16 20:16:11 +000018bool CommandTraits::isVerbatimBlockCommand(StringRef StartName,
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000019 StringRef &EndName) const {
Dmitri Gribenko81c53b42012-08-16 20:16:11 +000020 const char *Result = llvm::StringSwitch<const char *>(StartName)
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000021 .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 Gribenko81c53b42012-08-16 20:16:11 +000047 if (I->StartName == StartName) {
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000048 EndName = I->EndName;
49 return true;
50 }
51
52 return false;
53}
54
55bool CommandTraits::isVerbatimLineCommand(StringRef Name) const {
Dmitri Gribenko62290ae2012-08-09 18:20:29 +000056 bool Result = isDeclarationCommand(Name) || llvm::StringSwitch<bool>(Name)
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000057 .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 Gribenko62290ae2012-08-09 18:20:29 +000087bool 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 Gribenko81c53b42012-08-16 20:16:11 +0000118void CommandTraits::addVerbatimBlockCommand(StringRef StartName,
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000119 StringRef EndName) {
120 VerbatimBlockCommand VBC;
Dmitri Gribenko81c53b42012-08-16 20:16:11 +0000121 VBC.StartName = StartName;
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000122 VBC.EndName = EndName;
123 VerbatimBlockCommands.push_back(VBC);
124}
125
126void 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