CommentCommandTraits.h revision 0bd9838751384181ff387f2fb346896792b89617
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/StringRef.h" 21#include "llvm/ADT/SmallVector.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 /// True if we don't want to warn about this command being passed an empty 73 /// paragraph. Meaningful only for block commands. 74 unsigned IsEmptyParagraphAllowed : 1; 75 76 /// \brief True if this command is a verbatim-like block command. 77 /// 78 /// A verbatim-like block command eats every character (except line starting 79 /// decorations) until matching end command is seen or comment end is hit. 80 unsigned IsVerbatimBlockCommand : 1; 81 82 /// \brief True if this command is an end command for a verbatim-like block. 83 unsigned IsVerbatimBlockEndCommand : 1; 84 85 /// \brief True if this command is a verbatim line command. 86 /// 87 /// A verbatim-like line command eats everything until a newline is seen or 88 /// comment end is hit. 89 unsigned IsVerbatimLineCommand : 1; 90 91 /// \brief True if this command contains a declaration for the entity being 92 /// documented. 93 /// 94 /// For example: 95 /// \code 96 /// \fn void f(int a); 97 /// \endcode 98 unsigned IsDeclarationCommand : 1; 99 100 /// \brief True if this command is unknown. This \c CommandInfo object was 101 /// created during parsing. 102 unsigned IsUnknownCommand : 1; 103}; 104 105/// This class provides information about commands that can be used 106/// in comments. 107class CommandTraits { 108public: 109 CommandTraits(llvm::BumpPtrAllocator &Allocator); 110 111 /// \returns a CommandInfo object for a given command name or 112 /// NULL if no CommandInfo object exists for this command. 113 const CommandInfo *getCommandInfoOrNULL(StringRef Name) const; 114 115 const CommandInfo *getCommandInfo(StringRef Name) const { 116 if (const CommandInfo *Info = getCommandInfoOrNULL(Name)) 117 return Info; 118 llvm_unreachable("the command should be known"); 119 } 120 121 const CommandInfo *getCommandInfo(unsigned CommandID) const; 122 123 const CommandInfo *registerUnknownCommand(StringRef CommandName); 124 125 /// \returns a CommandInfo object for a given command name or 126 /// NULL if \c Name is not a builtin command. 127 static const CommandInfo *getBuiltinCommandInfo(StringRef Name); 128 129 /// \returns a CommandInfo object for a given command ID or 130 /// NULL if \c CommandID is not a builtin command. 131 static const CommandInfo *getBuiltinCommandInfo(unsigned CommandID); 132 133private: 134 CommandTraits(const CommandTraits &) LLVM_DELETED_FUNCTION; 135 void operator=(const CommandTraits &) LLVM_DELETED_FUNCTION; 136 137 const CommandInfo *getRegisteredCommandInfo(StringRef Name) const; 138 const CommandInfo *getRegisteredCommandInfo(unsigned CommandID) const; 139 140 unsigned NextID; 141 142 /// Allocator for CommandInfo objects. 143 llvm::BumpPtrAllocator &Allocator; 144 145 SmallVector<CommandInfo *, 4> RegisteredCommands; 146}; 147 148} // end namespace comments 149} // end namespace clang 150 151#endif 152 153