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