Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 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/LLVM.h" |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | 30a2e16 | 2012-12-04 09:18:49 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringRef.h" |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Allocator.h" |
| 23 | #include "llvm/Support/ErrorHandling.h" |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 24 | |
| 25 | namespace clang { |
| 26 | namespace comments { |
| 27 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 28 | /// \brief Information about a single command. |
| 29 | /// |
| 30 | /// When reordering, adding or removing members please update the corresponding |
| 31 | /// TableGen backend. |
| 32 | struct CommandInfo { |
| 33 | unsigned getID() const { |
| 34 | return ID; |
| 35 | } |
Dmitri Gribenko | d1db125 | 2012-08-09 17:33:20 +0000 | [diff] [blame] | 36 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 37 | 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 Gribenko | 0bd9838 | 2012-09-22 21:47:50 +0000 | [diff] [blame] | 69 | /// True if this command is \\deprecated or an alias. |
| 70 | unsigned IsDeprecatedCommand : 1; |
Dmitri Gribenko | 17d15f3 | 2013-01-31 23:20:06 +0000 | [diff] [blame] | 71 | |
| 72 | /// \brief True if this is a \\headerfile-like command. |
Fariborz Jahanian | f843a58 | 2013-01-31 23:12:39 +0000 | [diff] [blame] | 73 | unsigned IsHeaderfileCommand : 1; |
Dmitri Gribenko | 0bd9838 | 2012-09-22 21:47:50 +0000 | [diff] [blame] | 74 | |
Dmitri Gribenko | abcf0dc | 2012-09-13 20:36:01 +0000 | [diff] [blame] | 75 | /// 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 Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 79 | /// \brief True if this command is a verbatim-like block command. |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 80 | /// |
| 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 Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 83 | unsigned IsVerbatimBlockCommand : 1; |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 84 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 85 | /// \brief True if this command is an end command for a verbatim-like block. |
| 86 | unsigned IsVerbatimBlockEndCommand : 1; |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 87 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 88 | /// \brief True if this command is a verbatim line command. |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 89 | /// |
| 90 | /// A verbatim-like line command eats everything until a newline is seen or |
| 91 | /// comment end is hit. |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 92 | unsigned IsVerbatimLineCommand : 1; |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 93 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 94 | /// \brief True if this command contains a declaration for the entity being |
| 95 | /// documented. |
Dmitri Gribenko | 62290ae | 2012-08-09 18:20:29 +0000 | [diff] [blame] | 96 | /// |
| 97 | /// For example: |
| 98 | /// \code |
| 99 | /// \fn void f(int a); |
| 100 | /// \endcode |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 101 | unsigned IsDeclarationCommand : 1; |
Dmitri Gribenko | 62290ae | 2012-08-09 18:20:29 +0000 | [diff] [blame] | 102 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 103 | /// \brief True if this command is unknown. This \c CommandInfo object was |
| 104 | /// created during parsing. |
| 105 | unsigned IsUnknownCommand : 1; |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 108 | /// This class provides information about commands that can be used |
| 109 | /// in comments. |
| 110 | class CommandTraits { |
| 111 | public: |
Dmitri Gribenko | af01bed | 2013-02-01 20:23:57 +0000 | [diff] [blame^] | 112 | 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 Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 119 | CommandTraits(llvm::BumpPtrAllocator &Allocator); |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 120 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 121 | /// \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 Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 124 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 125 | 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 Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 130 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 131 | const CommandInfo *getCommandInfo(unsigned CommandID) const; |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 132 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 133 | const CommandInfo *registerUnknownCommand(StringRef CommandName); |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 134 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 135 | /// \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 Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 138 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 139 | /// \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 | |
| 143 | private: |
| 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 Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 157 | |
| 158 | } // end namespace comments |
| 159 | } // end namespace clang |
| 160 | |
| 161 | #endif |
| 162 | |