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