clang API Documentation

CommentCommandTraits.h
Go to the documentation of this file.
00001 //===--- CommentCommandTraits.h - Comment command properties ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the class that provides information about comment
00011 //  commands.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 
00016 #ifndef LLVM_CLANG_AST_COMMENTCOMMANDTRAITS_H
00017 #define LLVM_CLANG_AST_COMMENTCOMMANDTRAITS_H
00018 
00019 #include "clang/Basic/CommentOptions.h"
00020 #include "clang/Basic/LLVM.h"
00021 #include "llvm/ADT/SmallVector.h"
00022 #include "llvm/ADT/StringRef.h"
00023 #include "llvm/Support/Allocator.h"
00024 #include "llvm/Support/ErrorHandling.h"
00025 
00026 namespace clang {
00027 namespace comments {
00028 
00029 /// \brief Information about a single command.
00030 ///
00031 /// When reordering, adding or removing members please update the corresponding
00032 /// TableGen backend.
00033 struct CommandInfo {
00034   unsigned getID() const {
00035     return ID;
00036   }
00037 
00038   const char *Name;
00039 
00040   /// Name of the command that ends the verbatim block.
00041   const char *EndCommandName;
00042 
00043   /// DRY definition of the number of bits used for a command ID.
00044   enum { NumCommandIDBits = 20 };
00045 
00046   /// The ID of the command.
00047   unsigned ID : NumCommandIDBits;
00048 
00049   /// Number of word-like arguments for a given block command, except for
00050   /// \\param and \\tparam commands -- these have special argument parsers.
00051   unsigned NumArgs : 4;
00052 
00053   /// True if this command is a inline command (of any kind).
00054   unsigned IsInlineCommand : 1;
00055 
00056   /// True if this command is a block command (of any kind).
00057   unsigned IsBlockCommand : 1;
00058 
00059   /// True if this command is introducing a brief documentation
00060   /// paragraph (\\brief or an alias).
00061   unsigned IsBriefCommand : 1;
00062 
00063   /// True if this command is \\returns or an alias.
00064   unsigned IsReturnsCommand : 1;
00065 
00066   /// True if this command is introducing documentation for a function
00067   /// parameter (\\param or an alias).
00068   unsigned IsParamCommand : 1;
00069 
00070   /// True if this command is introducing documentation for
00071   /// a template parameter (\\tparam or an alias).
00072   unsigned IsTParamCommand : 1;
00073 
00074   /// True if this command is \\throws or an alias.
00075   unsigned IsThrowsCommand : 1;
00076 
00077   /// True if this command is \\deprecated or an alias.
00078   unsigned IsDeprecatedCommand : 1;
00079 
00080   /// \brief True if this is a \\headerfile-like command.
00081   unsigned IsHeaderfileCommand : 1;
00082 
00083   /// True if we don't want to warn about this command being passed an empty
00084   /// paragraph.  Meaningful only for block commands.
00085   unsigned IsEmptyParagraphAllowed : 1;
00086 
00087   /// \brief True if this command is a verbatim-like block command.
00088   ///
00089   /// A verbatim-like block command eats every character (except line starting
00090   /// decorations) until matching end command is seen or comment end is hit.
00091   unsigned IsVerbatimBlockCommand : 1;
00092 
00093   /// \brief True if this command is an end command for a verbatim-like block.
00094   unsigned IsVerbatimBlockEndCommand : 1;
00095 
00096   /// \brief True if this command is a verbatim line command.
00097   ///
00098   /// A verbatim-like line command eats everything until a newline is seen or
00099   /// comment end is hit.
00100   unsigned IsVerbatimLineCommand : 1;
00101 
00102   /// \brief True if this command contains a declaration for the entity being
00103   /// documented.
00104   ///
00105   /// For example:
00106   /// \code
00107   ///   \fn void f(int a);
00108   /// \endcode
00109   unsigned IsDeclarationCommand : 1;
00110   
00111   /// \brief True if verbatim-like line command is a function declaration.
00112   unsigned IsFunctionDeclarationCommand : 1;
00113 
00114   /// \brief True if block command is further describing a container API; such
00115   /// as \@coclass, \@classdesign, etc.
00116   unsigned IsRecordLikeDetailCommand : 1;
00117   
00118   /// \brief True if block command is a container API; such as \@interface.
00119   unsigned IsRecordLikeDeclarationCommand : 1;
00120   
00121   /// \brief True if this command is unknown.  This \c CommandInfo object was
00122   /// created during parsing.
00123   unsigned IsUnknownCommand : 1;
00124 };
00125 
00126 /// This class provides information about commands that can be used
00127 /// in comments.
00128 class CommandTraits {
00129 public:
00130   enum KnownCommandIDs {
00131 #define COMMENT_COMMAND(NAME) KCI_##NAME,
00132 #include "clang/AST/CommentCommandList.inc"
00133 #undef COMMENT_COMMAND
00134     KCI_Last
00135   };
00136 
00137   CommandTraits(llvm::BumpPtrAllocator &Allocator,
00138                 const CommentOptions &CommentOptions);
00139 
00140   void registerCommentOptions(const CommentOptions &CommentOptions);
00141 
00142   /// \returns a CommandInfo object for a given command name or
00143   /// NULL if no CommandInfo object exists for this command.
00144   const CommandInfo *getCommandInfoOrNULL(StringRef Name) const;
00145 
00146   const CommandInfo *getCommandInfo(StringRef Name) const {
00147     if (const CommandInfo *Info = getCommandInfoOrNULL(Name))
00148       return Info;
00149     llvm_unreachable("the command should be known");
00150   }
00151 
00152   const CommandInfo *getTypoCorrectCommandInfo(StringRef Typo) const;
00153   
00154   const CommandInfo *getCommandInfo(unsigned CommandID) const;
00155 
00156   const CommandInfo *registerUnknownCommand(StringRef CommandName);
00157 
00158   const CommandInfo *registerBlockCommand(StringRef CommandName);
00159 
00160   /// \returns a CommandInfo object for a given command name or
00161   /// NULL if \c Name is not a builtin command.
00162   static const CommandInfo *getBuiltinCommandInfo(StringRef Name);
00163 
00164   /// \returns a CommandInfo object for a given command ID or
00165   /// NULL if \c CommandID is not a builtin command.
00166   static const CommandInfo *getBuiltinCommandInfo(unsigned CommandID);
00167 
00168 private:
00169   CommandTraits(const CommandTraits &) LLVM_DELETED_FUNCTION;
00170   void operator=(const CommandTraits &) LLVM_DELETED_FUNCTION;
00171 
00172   const CommandInfo *getRegisteredCommandInfo(StringRef Name) const;
00173   const CommandInfo *getRegisteredCommandInfo(unsigned CommandID) const;
00174 
00175   CommandInfo *createCommandInfoWithName(StringRef CommandName);
00176 
00177   unsigned NextID;
00178 
00179   /// Allocator for CommandInfo objects.
00180   llvm::BumpPtrAllocator &Allocator;
00181 
00182   SmallVector<CommandInfo *, 4> RegisteredCommands;
00183 };
00184 
00185 } // end namespace comments
00186 } // end namespace clang
00187 
00188 #endif
00189