blob: 8f9fca372b2f62ff886bb55bae97920bf34bf704 [file] [log] [blame]
Dmitri Gribenkoaa580812012-08-09 00:03:17 +00001//===--- 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/LLVM.h"
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000020#include "llvm/ADT/SmallVector.h"
Chandler Carruth30a2e162012-12-04 09:18:49 +000021#include "llvm/ADT/StringRef.h"
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000022#include "llvm/Support/Allocator.h"
23#include "llvm/Support/ErrorHandling.h"
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000024
25namespace clang {
26namespace comments {
27
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000028/// \brief Information about a single command.
29///
30/// When reordering, adding or removing members please update the corresponding
31/// TableGen backend.
32struct CommandInfo {
33 unsigned getID() const {
34 return ID;
35 }
Dmitri Gribenkod1db1252012-08-09 17:33:20 +000036
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000037 const char *Name;
38
39 /// Name of the command that ends the verbatim block.
40 const char *EndCommandName;
41
42 unsigned ID : 8;
43
44 /// Number of word-like arguments for a given block command, except for
45 /// \\param and \\tparam commands -- these have special argument parsers.
46 unsigned NumArgs : 4;
47
48 /// True if this command is a inline command (of any kind).
49 unsigned IsInlineCommand : 1;
50
51 /// True if this command is a block command (of any kind).
52 unsigned IsBlockCommand : 1;
53
54 /// True if this command is introducing a brief documentation
55 /// paragraph (\\brief or an alias).
56 unsigned IsBriefCommand : 1;
57
58 /// True if this command is \\returns or an alias.
59 unsigned IsReturnsCommand : 1;
60
61 /// True if this command is introducing documentation for a function
62 /// parameter (\\param or an alias).
63 unsigned IsParamCommand : 1;
64
65 /// True if this command is introducing documentation for
66 /// a template parameter (\\tparam or an alias).
67 unsigned IsTParamCommand : 1;
68
Dmitri Gribenko0bd98382012-09-22 21:47:50 +000069 /// True if this command is \\deprecated or an alias.
70 unsigned IsDeprecatedCommand : 1;
Dmitri Gribenko17d15f32013-01-31 23:20:06 +000071
72 /// \brief True if this is a \\headerfile-like command.
Fariborz Jahanianf843a582013-01-31 23:12:39 +000073 unsigned IsHeaderfileCommand : 1;
Dmitri Gribenko0bd98382012-09-22 21:47:50 +000074
Dmitri Gribenkoabcf0dc2012-09-13 20:36:01 +000075 /// True if we don't want to warn about this command being passed an empty
76 /// paragraph. Meaningful only for block commands.
77 unsigned IsEmptyParagraphAllowed : 1;
78
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000079 /// \brief True if this command is a verbatim-like block command.
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000080 ///
81 /// A verbatim-like block command eats every character (except line starting
82 /// decorations) until matching end command is seen or comment end is hit.
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000083 unsigned IsVerbatimBlockCommand : 1;
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000084
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000085 /// \brief True if this command is an end command for a verbatim-like block.
86 unsigned IsVerbatimBlockEndCommand : 1;
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000087
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000088 /// \brief True if this command is a verbatim line command.
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000089 ///
90 /// A verbatim-like line command eats everything until a newline is seen or
91 /// comment end is hit.
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000092 unsigned IsVerbatimLineCommand : 1;
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000093
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000094 /// \brief True if this command contains a declaration for the entity being
95 /// documented.
Dmitri Gribenko62290ae2012-08-09 18:20:29 +000096 ///
97 /// For example:
98 /// \code
99 /// \fn void f(int a);
100 /// \endcode
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000101 unsigned IsDeclarationCommand : 1;
Dmitri Gribenko62290ae2012-08-09 18:20:29 +0000102
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000103 /// \brief True if this command is unknown. This \c CommandInfo object was
104 /// created during parsing.
105 unsigned IsUnknownCommand : 1;
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000106};
107
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000108/// This class provides information about commands that can be used
109/// in comments.
110class CommandTraits {
111public:
Dmitri Gribenkoaf01bed2013-02-01 20:23:57 +0000112 enum KnownCommandIDs {
113#define COMMENT_COMMAND(NAME) KCI_##NAME,
114#include "clang/AST/CommentCommandList.inc"
115#undef COMMENT_COMMAND
116 KCI_Last
117 };
118
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000119 CommandTraits(llvm::BumpPtrAllocator &Allocator);
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000120
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000121 /// \returns a CommandInfo object for a given command name or
122 /// NULL if no CommandInfo object exists for this command.
123 const CommandInfo *getCommandInfoOrNULL(StringRef Name) const;
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000124
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000125 const CommandInfo *getCommandInfo(StringRef Name) const {
126 if (const CommandInfo *Info = getCommandInfoOrNULL(Name))
127 return Info;
128 llvm_unreachable("the command should be known");
129 }
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000130
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000131 const CommandInfo *getCommandInfo(unsigned CommandID) const;
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000132
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000133 const CommandInfo *registerUnknownCommand(StringRef CommandName);
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000134
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000135 /// \returns a CommandInfo object for a given command name or
136 /// NULL if \c Name is not a builtin command.
137 static const CommandInfo *getBuiltinCommandInfo(StringRef Name);
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000138
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000139 /// \returns a CommandInfo object for a given command ID or
140 /// NULL if \c CommandID is not a builtin command.
141 static const CommandInfo *getBuiltinCommandInfo(unsigned CommandID);
142
143private:
144 CommandTraits(const CommandTraits &) LLVM_DELETED_FUNCTION;
145 void operator=(const CommandTraits &) LLVM_DELETED_FUNCTION;
146
147 const CommandInfo *getRegisteredCommandInfo(StringRef Name) const;
148 const CommandInfo *getRegisteredCommandInfo(unsigned CommandID) const;
149
150 unsigned NextID;
151
152 /// Allocator for CommandInfo objects.
153 llvm::BumpPtrAllocator &Allocator;
154
155 SmallVector<CommandInfo *, 4> RegisteredCommands;
156};
Dmitri Gribenkoaa580812012-08-09 00:03:17 +0000157
158} // end namespace comments
159} // end namespace clang
160
161#endif
162