CommentCommandTraits.h revision 17d15f3c3dad45f6df8034c9ea3e3c8ff466076c
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" 20#include "llvm/ADT/SmallVector.h" 21#include "llvm/ADT/StringRef.h" 22#include "llvm/Support/Allocator.h" 23#include "llvm/Support/ErrorHandling.h" 24 25namespace clang { 26namespace comments { 27 28/// \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 } 36 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 69 /// True if this command is \\deprecated or an alias. 70 unsigned IsDeprecatedCommand : 1; 71 72 /// \brief True if this is a \\headerfile-like command. 73 unsigned IsHeaderfileCommand : 1; 74 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 79 /// \brief True if this command is a verbatim-like block command. 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. 83 unsigned IsVerbatimBlockCommand : 1; 84 85 /// \brief True if this command is an end command for a verbatim-like block. 86 unsigned IsVerbatimBlockEndCommand : 1; 87 88 /// \brief True if this command is a verbatim line command. 89 /// 90 /// A verbatim-like line command eats everything until a newline is seen or 91 /// comment end is hit. 92 unsigned IsVerbatimLineCommand : 1; 93 94 /// \brief True if this command contains a declaration for the entity being 95 /// documented. 96 /// 97 /// For example: 98 /// \code 99 /// \fn void f(int a); 100 /// \endcode 101 unsigned IsDeclarationCommand : 1; 102 103 /// \brief True if this command is unknown. This \c CommandInfo object was 104 /// created during parsing. 105 unsigned IsUnknownCommand : 1; 106}; 107 108/// This class provides information about commands that can be used 109/// in comments. 110class CommandTraits { 111public: 112 CommandTraits(llvm::BumpPtrAllocator &Allocator); 113 114 /// \returns a CommandInfo object for a given command name or 115 /// NULL if no CommandInfo object exists for this command. 116 const CommandInfo *getCommandInfoOrNULL(StringRef Name) const; 117 118 const CommandInfo *getCommandInfo(StringRef Name) const { 119 if (const CommandInfo *Info = getCommandInfoOrNULL(Name)) 120 return Info; 121 llvm_unreachable("the command should be known"); 122 } 123 124 const CommandInfo *getCommandInfo(unsigned CommandID) const; 125 126 const CommandInfo *registerUnknownCommand(StringRef CommandName); 127 128 /// \returns a CommandInfo object for a given command name or 129 /// NULL if \c Name is not a builtin command. 130 static const CommandInfo *getBuiltinCommandInfo(StringRef Name); 131 132 /// \returns a CommandInfo object for a given command ID or 133 /// NULL if \c CommandID is not a builtin command. 134 static const CommandInfo *getBuiltinCommandInfo(unsigned CommandID); 135 136private: 137 CommandTraits(const CommandTraits &) LLVM_DELETED_FUNCTION; 138 void operator=(const CommandTraits &) LLVM_DELETED_FUNCTION; 139 140 const CommandInfo *getRegisteredCommandInfo(StringRef Name) const; 141 const CommandInfo *getRegisteredCommandInfo(unsigned CommandID) const; 142 143 unsigned NextID; 144 145 /// Allocator for CommandInfo objects. 146 llvm::BumpPtrAllocator &Allocator; 147 148 SmallVector<CommandInfo *, 4> RegisteredCommands; 149}; 150 151} // end namespace comments 152} // end namespace clang 153 154#endif 155 156