]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/clang/include/clang/AST/CommentCommandTraits.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / clang / include / clang / AST / CommentCommandTraits.h
1 //===--- CommentCommandTraits.h - 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 //  This file defines the class that provides information about comment
11 //  commands.
12 //
13 //===----------------------------------------------------------------------===//
14
15
16 #ifndef LLVM_CLANG_AST_COMMENT_COMMAND_TRAITS_H
17 #define LLVM_CLANG_AST_COMMENT_COMMAND_TRAITS_H
18
19 #include "clang/Basic/CommentOptions.h"
20 #include "clang/Basic/LLVM.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Allocator.h"
24 #include "llvm/Support/ErrorHandling.h"
25
26 namespace clang {
27 namespace comments {
28
29 /// \brief Information about a single command.
30 ///
31 /// When reordering, adding or removing members please update the corresponding
32 /// TableGen backend.
33 struct CommandInfo {
34   unsigned getID() const {
35     return ID;
36   }
37
38   const char *Name;
39
40   /// Name of the command that ends the verbatim block.
41   const char *EndCommandName;
42
43   unsigned ID : 8;
44
45   /// Number of word-like arguments for a given block command, except for
46   /// \\param and \\tparam commands -- these have special argument parsers.
47   unsigned NumArgs : 4;
48
49   /// True if this command is a inline command (of any kind).
50   unsigned IsInlineCommand : 1;
51
52   /// True if this command is a block command (of any kind).
53   unsigned IsBlockCommand : 1;
54
55   /// True if this command is introducing a brief documentation
56   /// paragraph (\\brief or an alias).
57   unsigned IsBriefCommand : 1;
58
59   /// True if this command is \\returns or an alias.
60   unsigned IsReturnsCommand : 1;
61
62   /// True if this command is introducing documentation for a function
63   /// parameter (\\param or an alias).
64   unsigned IsParamCommand : 1;
65
66   /// True if this command is introducing documentation for
67   /// a template parameter (\\tparam or an alias).
68   unsigned IsTParamCommand : 1;
69
70   /// True if this command is \\throws or an alias.
71   unsigned IsThrowsCommand : 1;
72
73   /// True if this command is \\deprecated or an alias.
74   unsigned IsDeprecatedCommand : 1;
75
76   /// \brief True if this is a \\headerfile-like command.
77   unsigned IsHeaderfileCommand : 1;
78
79   /// True if we don't want to warn about this command being passed an empty
80   /// paragraph.  Meaningful only for block commands.
81   unsigned IsEmptyParagraphAllowed : 1;
82
83   /// \brief True if this command is a verbatim-like block command.
84   ///
85   /// A verbatim-like block command eats every character (except line starting
86   /// decorations) until matching end command is seen or comment end is hit.
87   unsigned IsVerbatimBlockCommand : 1;
88
89   /// \brief True if this command is an end command for a verbatim-like block.
90   unsigned IsVerbatimBlockEndCommand : 1;
91
92   /// \brief True if this command is a verbatim line command.
93   ///
94   /// A verbatim-like line command eats everything until a newline is seen or
95   /// comment end is hit.
96   unsigned IsVerbatimLineCommand : 1;
97
98   /// \brief True if this command contains a declaration for the entity being
99   /// documented.
100   ///
101   /// For example:
102   /// \code
103   ///   \fn void f(int a);
104   /// \endcode
105   unsigned IsDeclarationCommand : 1;
106   
107   /// \brief True if verbatim-like line command is a function declaration.
108   unsigned IsFunctionDeclarationCommand : 1;
109
110   /// \brief True if block command is further describing a container API; such
111   /// as \@coclass, \@classdesign, etc.
112   unsigned IsRecordLikeDetailCommand : 1;
113   
114   /// \brief True if block command is a container API; such as \@interface.
115   unsigned IsRecordLikeDeclarationCommand : 1;
116   
117   /// \brief True if this command is unknown.  This \c CommandInfo object was
118   /// created during parsing.
119   unsigned IsUnknownCommand : 1;
120 };
121
122 /// This class provides information about commands that can be used
123 /// in comments.
124 class CommandTraits {
125 public:
126   enum KnownCommandIDs {
127 #define COMMENT_COMMAND(NAME) KCI_##NAME,
128 #include "clang/AST/CommentCommandList.inc"
129 #undef COMMENT_COMMAND
130     KCI_Last
131   };
132
133   CommandTraits(llvm::BumpPtrAllocator &Allocator,
134                 const CommentOptions &CommentOptions);
135
136   void registerCommentOptions(const CommentOptions &CommentOptions);
137
138   /// \returns a CommandInfo object for a given command name or
139   /// NULL if no CommandInfo object exists for this command.
140   const CommandInfo *getCommandInfoOrNULL(StringRef Name) const;
141
142   const CommandInfo *getCommandInfo(StringRef Name) const {
143     if (const CommandInfo *Info = getCommandInfoOrNULL(Name))
144       return Info;
145     llvm_unreachable("the command should be known");
146   }
147
148   const CommandInfo *getTypoCorrectCommandInfo(StringRef Typo) const;
149   
150   const CommandInfo *getCommandInfo(unsigned CommandID) const;
151
152   const CommandInfo *registerUnknownCommand(StringRef CommandName);
153
154   const CommandInfo *registerBlockCommand(StringRef CommandName);
155
156   /// \returns a CommandInfo object for a given command name or
157   /// NULL if \c Name is not a builtin command.
158   static const CommandInfo *getBuiltinCommandInfo(StringRef Name);
159
160   /// \returns a CommandInfo object for a given command ID or
161   /// NULL if \c CommandID is not a builtin command.
162   static const CommandInfo *getBuiltinCommandInfo(unsigned CommandID);
163
164 private:
165   CommandTraits(const CommandTraits &) LLVM_DELETED_FUNCTION;
166   void operator=(const CommandTraits &) LLVM_DELETED_FUNCTION;
167
168   const CommandInfo *getRegisteredCommandInfo(StringRef Name) const;
169   const CommandInfo *getRegisteredCommandInfo(unsigned CommandID) const;
170
171   CommandInfo *createCommandInfoWithName(StringRef CommandName);
172
173   unsigned NextID;
174
175   /// Allocator for CommandInfo objects.
176   llvm::BumpPtrAllocator &Allocator;
177
178   SmallVector<CommandInfo *, 4> RegisteredCommands;
179 };
180
181 } // end namespace comments
182 } // end namespace clang
183
184 #endif
185