1 //===- CLICommand.h - Classes used to represent commands --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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 //===----------------------------------------------------------------------===//
24 /// CLICommand - Base class of the hierarchy, used to provide the abstract
25 /// interface common to all commands.
28 /// ShortHelp, LongHelp - The short and long helps strings printed for the
29 /// command. The ShortHelp string should be a single line of text without a
30 /// newline. The LongHelp string should be a full description with
31 /// terminating newline.
32 std::string ShortHelp, LongHelp;
34 /// RefCount - This contains the number of entries in the CLIDebugger
35 /// CommandTable that points to this command.
38 /// OptionNames - This contains a list of names for the option. Keeping
39 /// track of this is done just to make the help output more helpful.
41 std::vector<std::string> OptionNames;
43 CLICommand(const std::string &SH, const std::string &LH)
44 : ShortHelp(SH), LongHelp(LH), RefCount(0) {}
46 virtual ~CLICommand() {}
48 /// addRef/dropRef - Implement a simple reference counting scheme to make
49 /// sure we delete commands that are no longer used.
50 void addRef() { ++RefCount; }
52 if (--RefCount == 0) delete this;
55 /// getPrimaryOptionName - Return the first name the option was added under.
56 /// This is the name we report for the option in the help output.
57 std::string getPrimaryOptionName() const {
58 return OptionNames.empty() ? "" : OptionNames[0];
61 /// getOptionName - Return all of the names the option is registered as.
63 const std::vector<std::string> &getOptionNames() const {
67 /// addOptionName - Add a name that this option is known as.
69 void addOptionName(const std::string &Name) {
70 OptionNames.push_back(Name);
73 /// removeOptionName - Eliminate one of the names for this option.
75 void removeOptionName(const std::string &Name) {
77 for (; OptionNames[i] != Name; ++i)
78 assert(i+1 < OptionNames.size() && "Didn't find option name!");
79 OptionNames.erase(OptionNames.begin()+i);
83 /// getShortHelp - Return the short help string for this command.
85 const std::string &getShortHelp() { return ShortHelp; }
87 /// getLongHelp - Return the long help string for this command, if it
89 const std::string &getLongHelp() { return LongHelp; }
91 virtual void runCommand(CLIDebugger &D, std::string &Arguments) = 0;
94 /// BuiltinCLICommand - This class represents commands that are built directly
95 /// into the debugger.
96 class BuiltinCLICommand : public CLICommand {
97 // Impl - Pointer to the method that implements the command
98 void (CLIDebugger::*Impl)(std::string&);
100 BuiltinCLICommand(const std::string &ShortHelp, const std::string &LongHelp,
101 void (CLIDebugger::*impl)(std::string&))
102 : CLICommand(ShortHelp, LongHelp), Impl(impl) {}
104 void runCommand(CLIDebugger &D, std::string &Arguments) {
105 (D.*Impl)(Arguments);