1 //===- CLICommand.h - Classes used to represent commands --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a small class hierarchy used to represent the various types
11 // of commands in the CLI debugger front-end.
13 //===----------------------------------------------------------------------===//
25 /// CLICommand - Base class of the hierarchy, used to provide the abstract
26 /// interface common to all commands.
29 /// ShortHelp, LongHelp - The short and long helps strings printed for the
30 /// command. The ShortHelp string should be a single line of text without a
31 /// newline. The LongHelp string should be a full description with
32 /// terminating newline.
33 std::string ShortHelp
, LongHelp
;
35 /// RefCount - This contains the number of entries in the CLIDebugger
36 /// CommandTable that points to this command.
39 /// OptionNames - This contains a list of names for the option. Keeping
40 /// track of this is done just to make the help output more helpful.
42 std::vector
<std::string
> OptionNames
;
44 CLICommand(const std::string
&SH
, const std::string
&LH
)
45 : ShortHelp(SH
), LongHelp(LH
), RefCount(0) {}
47 virtual ~CLICommand() {}
49 /// addRef/dropRef - Implement a simple reference counting scheme to make
50 /// sure we delete commands that are no longer used.
51 void addRef() { ++RefCount
; }
53 if (--RefCount
== 0) delete this;
56 /// getPrimaryOptionName - Return the first name the option was added under.
57 /// This is the name we report for the option in the help output.
58 std::string
getPrimaryOptionName() const {
59 return OptionNames
.empty() ? "" : OptionNames
[0];
62 /// getOptionName - Return all of the names the option is registered as.
64 const std::vector
<std::string
> &getOptionNames() const {
68 /// addOptionName - Add a name that this option is known as.
70 void addOptionName(const std::string
&Name
) {
71 OptionNames
.push_back(Name
);
74 /// removeOptionName - Eliminate one of the names for this option.
76 void removeOptionName(const std::string
&Name
) {
78 for (; OptionNames
[i
] != Name
; ++i
)
79 assert(i
+1 < OptionNames
.size() && "Didn't find option name!");
80 OptionNames
.erase(OptionNames
.begin()+i
);
84 /// getShortHelp - Return the short help string for this command.
86 const std::string
&getShortHelp() { return ShortHelp
; }
88 /// getLongHelp - Return the long help string for this command, if it
90 const std::string
&getLongHelp() { return LongHelp
; }
92 virtual void runCommand(CLIDebugger
&D
, std::string
&Arguments
) = 0;
95 /// BuiltinCLICommand - This class represents commands that are built directly
96 /// into the debugger.
97 class BuiltinCLICommand
: public CLICommand
{
98 // Impl - Pointer to the method that implements the command
99 void (CLIDebugger::*Impl
)(std::string
&);
101 BuiltinCLICommand(const std::string
&ShortHelp
, const std::string
&LongHelp
,
102 void (CLIDebugger::*impl
)(std::string
&))
103 : CLICommand(ShortHelp
, LongHelp
), Impl(impl
) {}
105 void runCommand(CLIDebugger
&D
, std::string
&Arguments
) {
106 (D
.*Impl
)(Arguments
);