Change the way command aliases are stored. Go from a model where a map holds the alias -> underlying command binding and another map holds the alias -> options, to a model where one single map holds the alias -> (all useful data) combination

Right now, obviously, this is just the pair of (CommandObjectSP,OptionArgVectorSP), so NFC

This is step one of a larger - and tricky - refactoring which will turn command aliases into interesting objects instead of passive storage that the command interpreter does smart things to
This refactoring, in turn, will allow us to do interesting things with aliases, such as intelligent and customizable help

llvm-svn: 262900
This commit is contained in:
Enrico Granata 2016-03-08 02:49:15 +00:00
parent 5e63e78ca9
commit 308f73c5a3
6 changed files with 143 additions and 186 deletions

View File

@ -200,8 +200,14 @@ class CommandInterpreter :
public IOHandlerDelegate
{
public:
typedef std::map<std::string, OptionArgVectorSP> OptionArgMap;
struct CommandAlias
{
lldb::CommandObjectSP m_underlying_command_sp;
OptionArgVectorSP m_option_args_sp;
};
typedef std::map<std::string, CommandAlias> CommandAliasMap;
enum
{
eBroadcastBitThreadShouldExit = (1 << 0),
@ -279,7 +285,8 @@ public:
void
AddAlias (const char *alias_name,
lldb::CommandObjectSP& command_obj_sp);
lldb::CommandObjectSP& command_obj_sp,
OptionArgVectorSP args_sp);
// Remove a command if it is removable (python or regex command)
bool
@ -308,13 +315,6 @@ public:
const char *options_args,
OptionArgVectorSP &option_arg_vector_sp);
void
RemoveAliasOptions (const char *alias_name);
void
AddOrReplaceAliasOptions (const char *alias_name,
OptionArgVectorSP &option_arg_vector_sp);
CommandObject *
BuildAliasResult (const char *alias_name,
std::string &raw_input_string,
@ -533,8 +533,9 @@ public:
bool
GetSynchronous ();
template <typename ValueType>
size_t
FindLongestCommandWord (CommandObject::CommandMap &dict);
FindLongestCommandWord (std::map<std::string,ValueType> &dict);
void
FindCommandsForApropos (const char *word,
@ -700,9 +701,8 @@ private:
bool m_skip_lldbinit_files;
bool m_skip_app_init_files;
CommandObject::CommandMap m_command_dict; // Stores basic built-in commands (they cannot be deleted, removed or overwritten).
CommandObject::CommandMap m_alias_dict; // Stores user aliases/abbreviations for commands
CommandAliasMap m_alias_dict; // Stores user aliases/abbreviations for commands
CommandObject::CommandMap m_user_dict; // Stores user-defined commands
OptionArgMap m_alias_options; // Stores any options (with or without arguments) that go with any alias.
CommandHistory m_command_history;
std::string m_repeat_command; // Stores the command that will be executed for an empty command string.
lldb::ScriptInterpreterSP m_script_interpreter_sp;

View File

@ -28,6 +28,49 @@
namespace lldb_private {
// This function really deals with CommandObjectLists, but we didn't make a
// CommandObjectList class, so I'm sticking it here. But we really should have
// such a class. Anyway, it looks up the commands in the map that match the partial
// string cmd_str, inserts the matches into matches, and returns the number added.
template <typename ValueType>
int
AddNamesMatchingPartialString (std::map<std::string,ValueType> &in_map, const char *cmd_str, StringList &matches)
{
class CommandDictCommandPartialMatch
{
public:
CommandDictCommandPartialMatch (const char *match_str)
{
m_match_str = match_str;
}
bool operator() (const std::pair<std::string, ValueType> map_element) const
{
// A NULL or empty string matches everything.
if (m_match_str == nullptr || *m_match_str == '\0')
return true;
return map_element.first.find (m_match_str, 0) == 0;
}
private:
const char *m_match_str;
};
int number_added = 0;
CommandDictCommandPartialMatch matcher(cmd_str);
auto matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher);
while (matching_cmds != in_map.end())
{
++number_added;
matches.AppendString((*matching_cmds).first.c_str());
matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);;
}
return number_added;
}
class CommandObject
{
public:
@ -230,14 +273,6 @@ public:
void
SetCommandName (const char *name);
// This function really deals with CommandObjectLists, but we didn't make a
// CommandObjectList class, so I'm sticking it here. But we really should have
// such a class. Anyway, it looks up the commands in the map that match the partial
// string cmd_str, inserts the matches into matches, and returns the number added.
static int
AddNamesMatchingPartialString (CommandMap &in_map, const char *cmd_str, StringList &matches);
//------------------------------------------------------------------
/// The input array contains a parsed version of the line. The insertion
/// point is given by cursor_index (the index in input of the word containing

View File

@ -635,21 +635,13 @@ protected:
if (m_interpreter.AliasExists (alias_command.c_str())
|| m_interpreter.UserCommandExists (alias_command.c_str()))
{
OptionArgVectorSP temp_option_arg_sp (m_interpreter.GetAliasOptions (alias_command.c_str()));
if (temp_option_arg_sp)
{
if (option_arg_vector->empty())
m_interpreter.RemoveAliasOptions (alias_command.c_str());
}
result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
alias_command.c_str());
}
if (cmd_obj_sp)
{
m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp);
if (!option_arg_vector->empty())
m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp);
m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp, option_arg_vector_sp);
result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
else
@ -747,22 +739,14 @@ protected:
if (m_interpreter.AliasExists (alias_command.c_str())
|| m_interpreter.UserCommandExists (alias_command.c_str()))
{
OptionArgVectorSP tmp_option_arg_sp (m_interpreter.GetAliasOptions (alias_command.c_str()));
if (tmp_option_arg_sp)
{
if (option_arg_vector->empty())
m_interpreter.RemoveAliasOptions (alias_command.c_str());
}
result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
alias_command.c_str());
}
if (use_subcommand)
m_interpreter.AddAlias (alias_command.c_str(), subcommand_obj_sp);
m_interpreter.AddAlias (alias_command.c_str(), subcommand_obj_sp, option_arg_vector_sp);
else
m_interpreter.AddAlias (alias_command.c_str(), command_obj_sp);
if (!option_arg_vector->empty())
m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp);
m_interpreter.AddAlias (alias_command.c_str(), command_obj_sp, option_arg_vector_sp);
result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
else

View File

@ -56,7 +56,7 @@ CommandObjectMultiword::GetSubcommandSP (const char *sub_cmd, StringList *matche
StringList local_matches;
if (matches == nullptr)
matches = &local_matches;
int num_matches = CommandObject::AddNamesMatchingPartialString (m_subcommand_dict, sub_cmd, *matches);
int num_matches = AddNamesMatchingPartialString (m_subcommand_dict, sub_cmd, *matches);
if (num_matches == 1)
{
@ -227,9 +227,9 @@ CommandObjectMultiword::HandleCompletion(Args &input,
const char *arg0 = input.GetArgumentAtIndex(0);
if (cursor_index == 0)
{
CommandObject::AddNamesMatchingPartialString (m_subcommand_dict,
arg0,
matches);
AddNamesMatchingPartialString (m_subcommand_dict,
arg0,
matches);
if (matches.GetSize() == 1
&& matches.GetStringAtIndex(0) != nullptr

View File

@ -192,149 +192,149 @@ CommandInterpreter::Initialize ()
CommandObjectSP cmd_obj_sp = GetCommandSPExact ("quit", false);
if (cmd_obj_sp)
{
AddAlias ("q", cmd_obj_sp);
AddAlias ("exit", cmd_obj_sp);
AddAlias ("q", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("exit", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("_regexp-attach",false);
if (cmd_obj_sp)
{
AddAlias ("attach", cmd_obj_sp);
AddAlias ("attach", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("process detach",false);
if (cmd_obj_sp)
{
AddAlias ("detach", cmd_obj_sp);
AddAlias ("detach", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("process continue", false);
if (cmd_obj_sp)
{
AddAlias ("c", cmd_obj_sp);
AddAlias ("continue", cmd_obj_sp);
AddAlias ("c", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("continue", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("_regexp-break",false);
if (cmd_obj_sp)
AddAlias ("b", cmd_obj_sp);
AddAlias ("b", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("_regexp-tbreak",false);
if (cmd_obj_sp)
AddAlias ("tbreak", cmd_obj_sp);
AddAlias ("tbreak", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("thread step-inst", false);
if (cmd_obj_sp)
{
AddAlias ("stepi", cmd_obj_sp);
AddAlias ("si", cmd_obj_sp);
AddAlias ("stepi", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("si", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("thread step-inst-over", false);
if (cmd_obj_sp)
{
AddAlias ("nexti", cmd_obj_sp);
AddAlias ("ni", cmd_obj_sp);
AddAlias ("nexti", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("ni", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("thread step-in", false);
if (cmd_obj_sp)
{
AddAlias ("s", cmd_obj_sp);
AddAlias ("step", cmd_obj_sp);
AddAlias ("s", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("step", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset (new OptionArgVector);
ProcessAliasOptionsArgs (cmd_obj_sp, "--end-linenumber block --step-in-target %1", alias_arguments_vector_sp);
AddAlias ("sif", cmd_obj_sp);
AddOrReplaceAliasOptions("sif", alias_arguments_vector_sp);
AddAlias ("sif", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset(new OptionArgVector);
}
cmd_obj_sp = GetCommandSPExact ("thread step-over", false);
if (cmd_obj_sp)
{
AddAlias ("n", cmd_obj_sp);
AddAlias ("next", cmd_obj_sp);
AddAlias ("n", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("next", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("thread step-out", false);
if (cmd_obj_sp)
{
AddAlias ("finish", cmd_obj_sp);
AddAlias ("finish", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("frame select", false);
if (cmd_obj_sp)
{
AddAlias ("f", cmd_obj_sp);
AddAlias ("f", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("thread select", false);
if (cmd_obj_sp)
{
AddAlias ("t", cmd_obj_sp);
AddAlias ("t", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("_regexp-jump",false);
if (cmd_obj_sp)
{
AddAlias ("j", cmd_obj_sp);
AddAlias ("jump", cmd_obj_sp);
AddAlias ("j", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("jump", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("_regexp-list", false);
if (cmd_obj_sp)
{
AddAlias ("l", cmd_obj_sp);
AddAlias ("list", cmd_obj_sp);
AddAlias ("l", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("list", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("_regexp-env", false);
if (cmd_obj_sp)
{
AddAlias ("env", cmd_obj_sp);
AddAlias ("env", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("memory read", false);
if (cmd_obj_sp)
AddAlias ("x", cmd_obj_sp);
AddAlias ("x", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("_regexp-up", false);
if (cmd_obj_sp)
AddAlias ("up", cmd_obj_sp);
AddAlias ("up", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("_regexp-down", false);
if (cmd_obj_sp)
AddAlias ("down", cmd_obj_sp);
AddAlias ("down", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("_regexp-display", false);
if (cmd_obj_sp)
AddAlias ("display", cmd_obj_sp);
AddAlias ("display", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("disassemble", false);
if (cmd_obj_sp)
AddAlias ("dis", cmd_obj_sp);
AddAlias ("dis", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("disassemble", false);
if (cmd_obj_sp)
AddAlias ("di", cmd_obj_sp);
AddAlias ("di", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("_regexp-undisplay", false);
if (cmd_obj_sp)
AddAlias ("undisplay", cmd_obj_sp);
AddAlias ("undisplay", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("_regexp-bt", false);
if (cmd_obj_sp)
AddAlias ("bt", cmd_obj_sp);
AddAlias ("bt", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("target create", false);
if (cmd_obj_sp)
AddAlias ("file", cmd_obj_sp);
AddAlias ("file", cmd_obj_sp, alias_arguments_vector_sp);
cmd_obj_sp = GetCommandSPExact ("target modules", false);
if (cmd_obj_sp)
AddAlias ("image", cmd_obj_sp);
AddAlias ("image", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset(new OptionArgVector);
@ -343,23 +343,19 @@ CommandInterpreter::Initialize ()
if (cmd_obj_sp)
{
ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
AddAlias ("p", cmd_obj_sp);
AddAlias ("print", cmd_obj_sp);
AddAlias ("call", cmd_obj_sp);
AddOrReplaceAliasOptions ("p", alias_arguments_vector_sp);
AddOrReplaceAliasOptions ("print", alias_arguments_vector_sp);
AddOrReplaceAliasOptions ("call", alias_arguments_vector_sp);
AddAlias ("p", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("print", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("call", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset (new OptionArgVector);
ProcessAliasOptionsArgs (cmd_obj_sp, "-O -- ", alias_arguments_vector_sp);
AddAlias ("po", cmd_obj_sp);
AddOrReplaceAliasOptions ("po", alias_arguments_vector_sp);
AddAlias ("po", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset(new OptionArgVector);
}
cmd_obj_sp = GetCommandSPExact ("process kill", false);
if (cmd_obj_sp)
{
AddAlias ("kill", cmd_obj_sp);
AddAlias ("kill", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("process launch", false);
@ -383,16 +379,15 @@ CommandInterpreter::Initialize ()
ProcessAliasOptionsArgs (cmd_obj_sp, shell_option.c_str(), alias_arguments_vector_sp);
#endif
#endif
AddAlias ("r", cmd_obj_sp);
AddAlias ("run", cmd_obj_sp);
AddOrReplaceAliasOptions ("r", alias_arguments_vector_sp);
AddOrReplaceAliasOptions ("run", alias_arguments_vector_sp);
AddAlias ("r", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("run", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset(new OptionArgVector);
}
cmd_obj_sp = GetCommandSPExact ("target symbols add", false);
if (cmd_obj_sp)
{
AddAlias ("add-dsym", cmd_obj_sp);
AddAlias ("add-dsym", cmd_obj_sp, alias_arguments_vector_sp);
}
cmd_obj_sp = GetCommandSPExact ("breakpoint set", false);
@ -400,8 +395,8 @@ CommandInterpreter::Initialize ()
{
alias_arguments_vector_sp.reset (new OptionArgVector);
ProcessAliasOptionsArgs (cmd_obj_sp, "--func-regex %1", alias_arguments_vector_sp);
AddAlias ("rbreak", cmd_obj_sp);
AddOrReplaceAliasOptions("rbreak", alias_arguments_vector_sp);
AddAlias ("rbreak", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset(new OptionArgVector);
}
}
@ -761,11 +756,11 @@ int
CommandInterpreter::GetCommandNamesMatchingPartialString (const char *cmd_str, bool include_aliases,
StringList &matches)
{
CommandObject::AddNamesMatchingPartialString (m_command_dict, cmd_str, matches);
AddNamesMatchingPartialString (m_command_dict, cmd_str, matches);
if (include_aliases)
{
CommandObject::AddNamesMatchingPartialString (m_alias_dict, cmd_str, matches);
AddNamesMatchingPartialString (m_alias_dict, cmd_str, matches);
}
return matches.GetSize();
@ -788,9 +783,9 @@ CommandInterpreter::GetCommandSP (const char *cmd_cstr, bool include_aliases, bo
if (include_aliases && HasAliases())
{
pos = m_alias_dict.find(cmd);
if (pos != m_alias_dict.end())
command_sp = pos->second;
CommandAliasMap::iterator alias_pos = m_alias_dict.find(cmd);
if (alias_pos != m_alias_dict.end())
command_sp = alias_pos->second.m_underlying_command_sp;
}
if (HasUserCommands())
@ -819,7 +814,7 @@ CommandInterpreter::GetCommandSP (const char *cmd_cstr, bool include_aliases, bo
if (HasCommands())
{
num_cmd_matches = CommandObject::AddNamesMatchingPartialString (m_command_dict, cmd_cstr, *matches);
num_cmd_matches = AddNamesMatchingPartialString (m_command_dict, cmd_cstr, *matches);
}
if (num_cmd_matches == 1)
@ -832,21 +827,21 @@ CommandInterpreter::GetCommandSP (const char *cmd_cstr, bool include_aliases, bo
if (include_aliases && HasAliases())
{
num_alias_matches = CommandObject::AddNamesMatchingPartialString (m_alias_dict, cmd_cstr, *matches);
num_alias_matches = AddNamesMatchingPartialString (m_alias_dict, cmd_cstr, *matches);
}
if (num_alias_matches == 1)
{
cmd.assign(matches->GetStringAtIndex (num_cmd_matches));
pos = m_alias_dict.find(cmd);
if (pos != m_alias_dict.end())
alias_match_sp = pos->second;
CommandAliasMap::iterator alias_pos = m_alias_dict.find(cmd);
if (alias_pos != m_alias_dict.end())
alias_match_sp = alias_pos->second.m_underlying_command_sp;
}
if (HasUserCommands())
{
num_user_matches = CommandObject::AddNamesMatchingPartialString (m_user_dict, cmd_cstr, *matches);
num_user_matches = AddNamesMatchingPartialString (m_user_dict, cmd_cstr, *matches);
}
if (num_user_matches == 1)
@ -1087,7 +1082,7 @@ CommandInterpreter::GetAliasFullName (const char *cmd, std::string &full_name)
{
StringList matches;
size_t num_alias_matches;
num_alias_matches = CommandObject::AddNamesMatchingPartialString (m_alias_dict, cmd, matches);
num_alias_matches = AddNamesMatchingPartialString (m_alias_dict, cmd, matches);
if (num_alias_matches == 1)
{
// Make sure this isn't shadowing a command in the regular command space:
@ -1121,19 +1116,21 @@ CommandInterpreter::UserCommandExists (const char *cmd)
}
void
CommandInterpreter::AddAlias (const char *alias_name, CommandObjectSP& command_obj_sp)
CommandInterpreter::AddAlias (const char *alias_name,
CommandObjectSP& command_obj_sp,
OptionArgVectorSP args_sp)
{
if (command_obj_sp.get())
assert((this == &command_obj_sp->GetCommandInterpreter()) && "tried to add a CommandObject from a different interpreter");
command_obj_sp->SetIsAlias (true);
m_alias_dict[alias_name] = command_obj_sp;
m_alias_dict[alias_name] = {command_obj_sp,args_sp};
}
bool
CommandInterpreter::RemoveAlias (const char *alias_name)
{
CommandObject::CommandMap::iterator pos = m_alias_dict.find(alias_name);
auto pos = m_alias_dict.find(alias_name);
if (pos != m_alias_dict.end())
{
m_alias_dict.erase(pos);
@ -1203,14 +1200,14 @@ CommandInterpreter::GetAliasHelp (const char *alias_name, const char *command_na
help_string.Printf ("'");
}
template <typename ValueType>
size_t
CommandInterpreter::FindLongestCommandWord (CommandObject::CommandMap &dict)
CommandInterpreter::FindLongestCommandWord (std::map<std::string,ValueType> &dict)
{
CommandObject::CommandMap::const_iterator pos;
CommandObject::CommandMap::const_iterator end = dict.end();
auto end = dict.end();
size_t max_len = 0;
for (pos = dict.begin(); pos != end; ++pos)
for (auto pos = dict.begin(); pos != end; ++pos)
{
size_t len = pos->first.size();
if (max_len < len)
@ -1257,16 +1254,16 @@ CommandInterpreter::GetHelp (CommandReturnObject &result,
result.AppendMessage("");
max_len = FindLongestCommandWord (m_alias_dict);
for (pos = m_alias_dict.begin(); pos != m_alias_dict.end(); ++pos)
for (auto alias_pos = m_alias_dict.begin(); alias_pos != m_alias_dict.end(); ++alias_pos)
{
StreamString sstr;
StreamString translation_and_help;
std::string entry_name = pos->first;
std::string second_entry = pos->second.get()->GetCommandName();
GetAliasHelp (pos->first.c_str(), pos->second->GetCommandName(), sstr);
std::string entry_name = alias_pos->first;
std::string second_entry = alias_pos->second.m_underlying_command_sp->GetCommandName();
GetAliasHelp (alias_pos->first.c_str(), alias_pos->second.m_underlying_command_sp->GetCommandName(), sstr);
translation_and_help.Printf ("(%s) %s", sstr.GetData(), pos->second->GetHelp());
OutputFormattedHelpText (result.GetOutputStream(), pos->first.c_str(), "--",
translation_and_help.Printf ("(%s) %s", sstr.GetData(), alias_pos->second.m_underlying_command_sp->GetHelp());
OutputFormattedHelpText (result.GetOutputStream(), alias_pos->first.c_str(), "--",
translation_and_help.GetData(), max_len);
}
result.AppendMessage("");
@ -2105,37 +2102,17 @@ CommandInterpreter::Confirm (const char *message, bool default_answer)
OptionArgVectorSP
CommandInterpreter::GetAliasOptions (const char *alias_name)
{
OptionArgMap::iterator pos;
OptionArgVectorSP ret_val;
std::string alias (alias_name);
if (HasAliasOptions())
{
pos = m_alias_options.find (alias);
if (pos != m_alias_options.end())
ret_val = pos->second;
}
auto pos = m_alias_dict.find(alias);
if (pos != m_alias_dict.end())
ret_val = pos->second.m_option_args_sp;
return ret_val;
}
void
CommandInterpreter::RemoveAliasOptions (const char *alias_name)
{
OptionArgMap::iterator pos = m_alias_options.find(alias_name);
if (pos != m_alias_options.end())
{
m_alias_options.erase (pos);
}
}
void
CommandInterpreter::AddOrReplaceAliasOptions (const char *alias_name, OptionArgVectorSP &option_arg_vector_sp)
{
m_alias_options[alias_name] = option_arg_vector_sp;
}
bool
CommandInterpreter::HasCommands ()
{
@ -2157,7 +2134,7 @@ CommandInterpreter::HasUserCommands ()
bool
CommandInterpreter::HasAliasOptions ()
{
return (!m_alias_options.empty());
return HasAliases();
}
void

View File

@ -346,45 +346,6 @@ CommandObject::Cleanup ()
m_api_locker.Unlock();
}
class CommandDictCommandPartialMatch
{
public:
CommandDictCommandPartialMatch (const char *match_str)
{
m_match_str = match_str;
}
bool operator() (const std::pair<std::string, lldb::CommandObjectSP> map_element) const
{
// A NULL or empty string matches everything.
if (m_match_str == nullptr || *m_match_str == '\0')
return true;
return map_element.first.find (m_match_str, 0) == 0;
}
private:
const char *m_match_str;
};
int
CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, const char *cmd_str,
StringList &matches)
{
int number_added = 0;
CommandDictCommandPartialMatch matcher(cmd_str);
CommandObject::CommandMap::iterator matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher);
while (matching_cmds != in_map.end())
{
++number_added;
matches.AppendString((*matching_cmds).first.c_str());
matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);;
}
return number_added;
}
int
CommandObject::HandleCompletion
(