CommentCommandTraits.cpp revision 239313
1239310Sdim//===--- CommentCommandTraits.cpp - Comment command properties --*- C++ -*-===//
2239310Sdim//
3239310Sdim//                     The LLVM Compiler Infrastructure
4239310Sdim//
5239310Sdim// This file is distributed under the University of Illinois Open Source
6239310Sdim// License. See LICENSE.TXT for details.
7239310Sdim//
8239310Sdim//===----------------------------------------------------------------------===//
9239310Sdim
10239310Sdim#include "clang/AST/CommentCommandTraits.h"
11239310Sdim#include "llvm/ADT/StringSwitch.h"
12239310Sdim
13239310Sdimnamespace clang {
14239310Sdimnamespace comments {
15239310Sdim
16239310Sdim// TODO: tablegen
17239310Sdim
18239310Sdimbool CommandTraits::isVerbatimBlockCommand(StringRef BeginName,
19239310Sdim                                           StringRef &EndName) const {
20239310Sdim  const char *Result = llvm::StringSwitch<const char *>(BeginName)
21239310Sdim    .Case("code", "endcode")
22239310Sdim    .Case("verbatim", "endverbatim")
23239310Sdim    .Case("htmlonly", "endhtmlonly")
24239310Sdim    .Case("latexonly", "endlatexonly")
25239310Sdim    .Case("xmlonly", "endxmlonly")
26239310Sdim    .Case("manonly", "endmanonly")
27239310Sdim    .Case("rtfonly", "endrtfonly")
28239310Sdim
29239310Sdim    .Case("dot", "enddot")
30239310Sdim    .Case("msc", "endmsc")
31239310Sdim
32239310Sdim    .Case("f$", "f$") // Inline LaTeX formula
33239310Sdim    .Case("f[", "f]") // Displayed LaTeX formula
34239310Sdim    .Case("f{", "f}") // LaTeX environment
35239310Sdim
36239310Sdim    .Default(NULL);
37239310Sdim
38239310Sdim  if (Result) {
39239310Sdim    EndName = Result;
40239310Sdim    return true;
41239310Sdim  }
42239310Sdim
43239310Sdim  for (VerbatimBlockCommandVector::const_iterator
44239310Sdim           I = VerbatimBlockCommands.begin(),
45239310Sdim           E = VerbatimBlockCommands.end();
46239310Sdim       I != E; ++I)
47239310Sdim    if (I->BeginName == BeginName) {
48239310Sdim      EndName = I->EndName;
49239310Sdim      return true;
50239310Sdim    }
51239310Sdim
52239310Sdim  return false;
53239310Sdim}
54239310Sdim
55239310Sdimbool CommandTraits::isVerbatimLineCommand(StringRef Name) const {
56239310Sdim  bool Result = isDeclarationCommand(Name) || llvm::StringSwitch<bool>(Name)
57239310Sdim  .Case("defgroup", true)
58239310Sdim  .Case("ingroup", true)
59239310Sdim  .Case("addtogroup", true)
60239310Sdim  .Case("weakgroup", true)
61239310Sdim  .Case("name", true)
62239310Sdim
63239310Sdim  .Case("section", true)
64239310Sdim  .Case("subsection", true)
65239310Sdim  .Case("subsubsection", true)
66239310Sdim  .Case("paragraph", true)
67239310Sdim
68239310Sdim  .Case("mainpage", true)
69239310Sdim  .Case("subpage", true)
70239310Sdim  .Case("ref", true)
71239310Sdim
72239310Sdim  .Default(false);
73239310Sdim
74239310Sdim  if (Result)
75239310Sdim    return true;
76239310Sdim
77239310Sdim  for (VerbatimLineCommandVector::const_iterator
78239310Sdim           I = VerbatimLineCommands.begin(),
79239310Sdim           E = VerbatimLineCommands.end();
80239310Sdim       I != E; ++I)
81239310Sdim    if (I->Name == Name)
82239310Sdim      return true;
83239310Sdim
84239310Sdim  return false;
85239310Sdim}
86239310Sdim
87239310Sdimbool CommandTraits::isDeclarationCommand(StringRef Name) const {
88239310Sdim  return llvm::StringSwitch<bool>(Name)
89239310Sdim      // Doxygen commands.
90239310Sdim      .Case("fn", true)
91239310Sdim      .Case("var", true)
92239310Sdim      .Case("property", true)
93239310Sdim      .Case("typedef", true)
94239310Sdim
95239310Sdim      .Case("overload", true)
96239310Sdim
97239310Sdim      // HeaderDoc commands.
98239310Sdim      .Case("class", true)
99239310Sdim      .Case("interface", true)
100239310Sdim      .Case("protocol", true)
101239310Sdim      .Case("category", true)
102239310Sdim      .Case("template", true)
103239310Sdim      .Case("function", true)
104239310Sdim      .Case("method", true)
105239310Sdim      .Case("callback", true)
106239310Sdim      .Case("var", true)
107239310Sdim      .Case("const", true)
108239310Sdim      .Case("constant", true)
109239310Sdim      .Case("property", true)
110239310Sdim      .Case("struct", true)
111239310Sdim      .Case("union", true)
112239310Sdim      .Case("typedef", true)
113239310Sdim      .Case("enum", true)
114239310Sdim
115239310Sdim      .Default(false);
116239310Sdim}
117239310Sdim
118239310Sdimvoid CommandTraits::addVerbatimBlockCommand(StringRef BeginName,
119239310Sdim                                            StringRef EndName) {
120239310Sdim  VerbatimBlockCommand VBC;
121239310Sdim  VBC.BeginName = BeginName;
122239310Sdim  VBC.EndName = EndName;
123239310Sdim  VerbatimBlockCommands.push_back(VBC);
124239310Sdim}
125239310Sdim
126239310Sdimvoid CommandTraits::addVerbatimLineCommand(StringRef Name) {
127239310Sdim  VerbatimLineCommand VLC;
128239310Sdim  VLC.Name = Name;
129239310Sdim  VerbatimLineCommands.push_back(VLC);
130239310Sdim}
131239310Sdim
132239310Sdim} // end namespace comments
133239310Sdim} // end namespace clang
134239310Sdim
135239310Sdim