CommentCommandTraits.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- CommentCommandTraits.h - Comment command properties ----*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the class that provides information about comment
  15. // commands.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_AST_COMMENTCOMMANDTRAITS_H
  19. #define LLVM_CLANG_AST_COMMENTCOMMANDTRAITS_H
  20. #include "clang/Basic/CommentOptions.h"
  21. #include "clang/Basic/LLVM.h"
  22. #include "llvm/ADT/SmallVector.h"
  23. #include "llvm/ADT/StringRef.h"
  24. #include "llvm/Support/Allocator.h"
  25. #include "llvm/Support/ErrorHandling.h"
  26. namespace clang {
  27. namespace comments {
  28. /// 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. }
  36. const char *Name;
  37. /// Name of the command that ends the verbatim block.
  38. const char *EndCommandName;
  39. /// DRY definition of the number of bits used for a command ID.
  40. enum { NumCommandIDBits = 20 };
  41. /// The ID of the command.
  42. unsigned ID : NumCommandIDBits;
  43. /// Number of word-like arguments for a given block command, except for
  44. /// \\param and \\tparam commands -- these have special argument parsers.
  45. unsigned NumArgs : 4;
  46. /// True if this command is a inline command (of any kind).
  47. unsigned IsInlineCommand : 1;
  48. /// True if this command is a block command (of any kind).
  49. unsigned IsBlockCommand : 1;
  50. /// True if this command is introducing a brief documentation
  51. /// paragraph (\or an alias).
  52. unsigned IsBriefCommand : 1;
  53. /// True if this command is \\returns or an alias.
  54. unsigned IsReturnsCommand : 1;
  55. /// True if this command is introducing documentation for a function
  56. /// parameter (\\param or an alias).
  57. unsigned IsParamCommand : 1;
  58. /// True if this command is introducing documentation for
  59. /// a template parameter (\\tparam or an alias).
  60. unsigned IsTParamCommand : 1;
  61. /// True if this command is \\throws or an alias.
  62. unsigned IsThrowsCommand : 1;
  63. /// True if this command is \\deprecated or an alias.
  64. unsigned IsDeprecatedCommand : 1;
  65. /// True if this is a \\headerfile-like command.
  66. unsigned IsHeaderfileCommand : 1;
  67. /// True if we don't want to warn about this command being passed an empty
  68. /// paragraph. Meaningful only for block commands.
  69. unsigned IsEmptyParagraphAllowed : 1;
  70. /// True if this command is a verbatim-like block command.
  71. ///
  72. /// A verbatim-like block command eats every character (except line starting
  73. /// decorations) until matching end command is seen or comment end is hit.
  74. unsigned IsVerbatimBlockCommand : 1;
  75. /// True if this command is an end command for a verbatim-like block.
  76. unsigned IsVerbatimBlockEndCommand : 1;
  77. /// True if this command is a verbatim line command.
  78. ///
  79. /// A verbatim-like line command eats everything until a newline is seen or
  80. /// comment end is hit.
  81. unsigned IsVerbatimLineCommand : 1;
  82. /// True if this command contains a declaration for the entity being
  83. /// documented.
  84. ///
  85. /// For example:
  86. /// \code
  87. /// \fn void f(int a);
  88. /// \endcode
  89. unsigned IsDeclarationCommand : 1;
  90. /// True if verbatim-like line command is a function declaration.
  91. unsigned IsFunctionDeclarationCommand : 1;
  92. /// True if block command is further describing a container API; such
  93. /// as \@coclass, \@classdesign, etc.
  94. unsigned IsRecordLikeDetailCommand : 1;
  95. /// True if block command is a container API; such as \@interface.
  96. unsigned IsRecordLikeDeclarationCommand : 1;
  97. /// True if this command is unknown. This \c CommandInfo object was
  98. /// created during parsing.
  99. unsigned IsUnknownCommand : 1;
  100. };
  101. /// This class provides information about commands that can be used
  102. /// in comments.
  103. class CommandTraits {
  104. public:
  105. enum KnownCommandIDs {
  106. #define COMMENT_COMMAND(NAME) KCI_##NAME,
  107. #include "clang/AST/CommentCommandList.inc"
  108. #undef COMMENT_COMMAND
  109. KCI_Last
  110. };
  111. CommandTraits(llvm::BumpPtrAllocator &Allocator,
  112. const CommentOptions &CommentOptions);
  113. void registerCommentOptions(const CommentOptions &CommentOptions);
  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. const CommandInfo *getCommandInfo(StringRef Name) const {
  118. if (const CommandInfo *Info = getCommandInfoOrNULL(Name))
  119. return Info;
  120. llvm_unreachable("the command should be known");
  121. }
  122. const CommandInfo *getTypoCorrectCommandInfo(StringRef Typo) const;
  123. const CommandInfo *getCommandInfo(unsigned CommandID) const;
  124. const CommandInfo *registerUnknownCommand(StringRef CommandName);
  125. const CommandInfo *registerBlockCommand(StringRef CommandName);
  126. /// \returns a CommandInfo object for a given command name or
  127. /// NULL if \c Name is not a builtin command.
  128. static const CommandInfo *getBuiltinCommandInfo(StringRef Name);
  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. private:
  133. CommandTraits(const CommandTraits &) = delete;
  134. void operator=(const CommandTraits &) = delete;
  135. const CommandInfo *getRegisteredCommandInfo(StringRef Name) const;
  136. const CommandInfo *getRegisteredCommandInfo(unsigned CommandID) const;
  137. CommandInfo *createCommandInfoWithName(StringRef CommandName);
  138. unsigned NextID;
  139. /// Allocator for CommandInfo objects.
  140. llvm::BumpPtrAllocator &Allocator;
  141. SmallVector<CommandInfo *, 4> RegisteredCommands;
  142. };
  143. } // end namespace comments
  144. } // end namespace clang
  145. #endif
  146. #ifdef __GNUC__
  147. #pragma GCC diagnostic pop
  148. #endif