summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands/CommandObjectCommands.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-09-22 20:22:55 +0000
committerZachary Turner <zturner@google.com>2016-09-22 20:22:55 +0000
commit1f0f5b5b9eeaea93126583b40070091baf3bc92d (patch)
tree93be6068ce5a7314fb9bfdf0621f65c03b3cad0b /lldb/source/Commands/CommandObjectCommands.cpp
parent387eb83a509926ed6bd36591d1f235335ec215c0 (diff)
downloadbcm5719-llvm-1f0f5b5b9eeaea93126583b40070091baf3bc92d.tar.gz
bcm5719-llvm-1f0f5b5b9eeaea93126583b40070091baf3bc92d.zip
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the signature of `Options::GetDefinitions()` and `OptionGroup:: GetDefinitions()` to return an `ArrayRef<OptionDefinition>` instead of a `const OptionDefinition *`. In the case of the former, it deletes the sentinel entry from every table, and in the case of the latter, it removes the `GetNumDefinitions()` method from the interface. These are no longer necessary as `ArrayRef` carries its own length. In the former case, iteration was done by using a sentinel entry, so there was no knowledge of length. Because of this the individual option tables were allowed to be defined below the corresponding class (after all, only a pointer was needed). Now, however, the length must be known at compile time to construct the `ArrayRef`, and as a result it is necessary to move every option table before its corresponding class. This results in this CL looking very big, but in terms of substance there is not much here. Differential revision: https://reviews.llvm.org/D24834 llvm-svn: 282188
Diffstat (limited to 'lldb/source/Commands/CommandObjectCommands.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectCommands.cpp176
1 files changed, 76 insertions, 100 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index f4f3afb32ba..74f0362b251 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -36,6 +36,15 @@ using namespace lldb_private;
// CommandObjectCommandsSource
//-------------------------------------------------------------------------
+static OptionDefinition g_history_options[] = {
+ // clang-format off
+ { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "How many history commands to print." },
+ { LLDB_OPT_SET_1, false, "start-index", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)." },
+ { LLDB_OPT_SET_1, false, "end-index", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands." },
+ { LLDB_OPT_SET_2, false, "clear", 'C', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Clears the current command history." },
+ // clang-format on
+};
+
class CommandObjectCommandsHistory : public CommandObjectParsed {
public:
CommandObjectCommandsHistory(CommandInterpreter &interpreter)
@@ -98,11 +107,9 @@ protected:
m_clear.Clear();
}
- const OptionDefinition *GetDefinitions() override { return g_option_table; }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+ return g_history_options;
+ }
// Instance variables to hold the values for command options.
@@ -180,21 +187,18 @@ protected:
CommandOptions m_options;
};
-OptionDefinition
- CommandObjectCommandsHistory::CommandOptions::g_option_table[] = {
- // clang-format off
- {LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "How many history commands to print."},
- {LLDB_OPT_SET_1, false, "start-index", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)."},
- {LLDB_OPT_SET_1, false, "end-index", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands."},
- {LLDB_OPT_SET_2, false, "clear", 'C', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Clears the current command history."},
- {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
-};
-
//-------------------------------------------------------------------------
// CommandObjectCommandsSource
//-------------------------------------------------------------------------
+static OptionDefinition g_source_options[] = {
+ // clang-format off
+ { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on error." },
+ { LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on continue." },
+ { LLDB_OPT_SET_ALL, false, "silent-run", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true don't echo commands while executing." },
+ // clang-format on
+};
+
class CommandObjectCommandsSource : public CommandObjectParsed {
public:
CommandObjectCommandsSource(CommandInterpreter &interpreter)
@@ -285,11 +289,9 @@ protected:
m_stop_on_continue.Clear();
}
- const OptionDefinition *GetDefinitions() override { return g_option_table; }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+ return g_source_options;
+ }
// Instance variables to hold the values for command options.
@@ -340,21 +342,18 @@ protected:
CommandOptions m_options;
};
-OptionDefinition CommandObjectCommandsSource::CommandOptions::g_option_table[] =
- {
- // clang-format off
- {LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on error."},
- {LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on continue."},
- {LLDB_OPT_SET_ALL, false, "silent-run", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true don't echo commands while executing."},
- {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
-};
-
#pragma mark CommandObjectCommandsAlias
//-------------------------------------------------------------------------
// CommandObjectCommandsAlias
//-------------------------------------------------------------------------
+static OptionDefinition g_alias_options[] = {
+ // clang-format off
+ { LLDB_OPT_SET_ALL, false, "help", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Help text for this command" },
+ { LLDB_OPT_SET_ALL, false, "long-help", 'H', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Long help text for this command" },
+ // clang-format on
+};
+
static const char *g_python_command_instructions =
"Enter your Python command(s). Type 'DONE' to end.\n"
"You must define a Python function with this signature:\n"
@@ -368,15 +367,15 @@ protected:
~CommandOptions() override = default;
- uint32_t GetNumDefinitions() override { return 3; }
-
- const OptionDefinition *GetDefinitions() override { return g_option_table; }
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+ return g_alias_options;
+ }
Error SetOptionValue(uint32_t option_idx, const char *option_value,
ExecutionContext *execution_context) override {
Error error;
- const int short_option = g_option_table[option_idx].short_option;
+ const int short_option = GetDefinitions()[option_idx].short_option;
switch (short_option) {
case 'h':
@@ -403,9 +402,6 @@ protected:
m_long_help.Clear();
}
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
OptionValueString m_help;
OptionValueString m_long_help;
};
@@ -810,15 +806,6 @@ protected:
}
};
-OptionDefinition CommandObjectCommandsAlias::CommandOptions::g_option_table[] =
- {
- // clang-format off
- {LLDB_OPT_SET_ALL, false, "help", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Help text for this command"},
- {LLDB_OPT_SET_ALL, false, "long-help", 'H', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Long help text for this command"},
- {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
-};
-
#pragma mark CommandObjectCommandsUnalias
//-------------------------------------------------------------------------
// CommandObjectCommandsUnalias
@@ -966,6 +953,14 @@ protected:
//-------------------------------------------------------------------------
// CommandObjectCommandsAddRegex
//-------------------------------------------------------------------------
+
+static OptionDefinition g_regex_options[] = {
+ // clang-format off
+ { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "The help text to display for this command." },
+ { LLDB_OPT_SET_1, false, "syntax", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "A syntax string showing the typical usage syntax." },
+ // clang-format on
+};
+
#pragma mark CommandObjectCommandsAddRegex
class CommandObjectCommandsAddRegex : public CommandObjectParsed,
@@ -1248,11 +1243,9 @@ private:
m_syntax.clear();
}
- const OptionDefinition *GetDefinitions() override { return g_option_table; }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+ return g_regex_options;
+ }
const char *GetHelp() {
return (m_help.empty() ? nullptr : m_help.c_str());
@@ -1274,15 +1267,6 @@ private:
CommandOptions m_options;
};
-OptionDefinition
- CommandObjectCommandsAddRegex::CommandOptions::g_option_table[] = {
- // clang-format off
- {LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "The help text to display for this command."},
- {LLDB_OPT_SET_1, false, "syntax", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "A syntax string showing the typical usage syntax."},
- {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
-};
-
class CommandObjectPythonFunction : public CommandObjectRaw {
public:
CommandObjectPythonFunction(CommandInterpreter &interpreter, std::string name,
@@ -1447,6 +1431,12 @@ private:
// CommandObjectCommandsScriptImport
//-------------------------------------------------------------------------
+OptionDefinition g_script_import_options[] = {
+ // clang-format off
+ { LLDB_OPT_SET_1, false, "allow-reload", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow the script to be loaded even if it was already loaded before. This argument exists for backwards compatibility, but reloading is always allowed, whether you specify it or not." },
+ // clang-format on
+};
+
class CommandObjectCommandsScriptImport : public CommandObjectParsed {
public:
CommandObjectCommandsScriptImport(CommandInterpreter &interpreter)
@@ -1517,11 +1507,9 @@ protected:
m_allow_reload = true;
}
- const OptionDefinition *GetDefinitions() override { return g_option_table; }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+ return g_script_import_options;
+ }
// Instance variables to hold the values for command options.
@@ -1578,18 +1566,28 @@ protected:
CommandOptions m_options;
};
-OptionDefinition
- CommandObjectCommandsScriptImport::CommandOptions::g_option_table[] = {
- // clang-format off
- {LLDB_OPT_SET_1, false, "allow-reload", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow the script to be loaded even if it was already loaded before. This argument exists for backwards compatibility, but reloading is always allowed, whether you specify it or not."},
- {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
- // clang-format on
-};
-
//-------------------------------------------------------------------------
// CommandObjectCommandsScriptAdd
//-------------------------------------------------------------------------
+static OptionEnumValueElement g_script_synchro_type[] = {
+ {eScriptedCommandSynchronicitySynchronous, "synchronous",
+ "Run synchronous"},
+ {eScriptedCommandSynchronicityAsynchronous, "asynchronous",
+ "Run asynchronous"},
+ {eScriptedCommandSynchronicityCurrentValue, "current",
+ "Do not alter current setting"},
+ {0, nullptr, nullptr}};
+
+static OptionDefinition g_script_add_options[] = {
+ // clang-format off
+ { LLDB_OPT_SET_1, false, "function", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Name of the Python function to bind to this command name." },
+ { LLDB_OPT_SET_2, false, "class", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "Name of the Python class to bind to this command name." },
+ { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "The help text to display for this command." },
+ { LLDB_OPT_SET_ALL, false, "synchronicity", 's', OptionParser::eRequiredArgument, nullptr, g_script_synchro_type, 0, eArgTypeScriptedCommandSynchronicity, "Set the synchronicity of this command's executions with regard to LLDB event system." },
+ // clang-format on
+};
+
class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
public IOHandlerDelegateMultiline {
public:
@@ -1647,7 +1645,7 @@ protected:
case 's':
m_synchronicity =
(ScriptedCommandSynchronicity)Args::StringToOptionEnum(
- option_arg, g_option_table[option_idx].enum_values, 0, error);
+ option_arg, GetDefinitions()[option_idx].enum_values, 0, error);
if (!error.Success())
error.SetErrorStringWithFormat(
"unrecognized value for synchronicity '%s'", option_arg);
@@ -1668,11 +1666,9 @@ protected:
m_synchronicity = eScriptedCommandSynchronicitySynchronous;
}
- const OptionDefinition *GetDefinitions() override { return g_option_table; }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+ return g_script_add_options;
+ }
// Instance variables to hold the values for command options.
@@ -1816,26 +1812,6 @@ protected:
ScriptedCommandSynchronicity m_synchronicity;
};
-static OptionEnumValueElement g_script_synchro_type[] = {
- {eScriptedCommandSynchronicitySynchronous, "synchronous",
- "Run synchronous"},
- {eScriptedCommandSynchronicityAsynchronous, "asynchronous",
- "Run asynchronous"},
- {eScriptedCommandSynchronicityCurrentValue, "current",
- "Do not alter current setting"},
- {0, nullptr, nullptr}};
-
-OptionDefinition
- CommandObjectCommandsScriptAdd::CommandOptions::g_option_table[] = {
- // clang-format off
- {LLDB_OPT_SET_1, false, "function", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Name of the Python function to bind to this command name."},
- {LLDB_OPT_SET_2, false, "class", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "Name of the Python class to bind to this command name."},
- {LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "The help text to display for this command."},
- {LLDB_OPT_SET_ALL, false, "synchronicity", 's', OptionParser::eRequiredArgument, nullptr, g_script_synchro_type, 0, eArgTypeScriptedCommandSynchronicity, "Set the synchronicity of this command's executions with regard to LLDB event system."},
- {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
-};
-
//-------------------------------------------------------------------------
// CommandObjectCommandsScriptList
//-------------------------------------------------------------------------
OpenPOWER on IntegriCloud