diff options
author | Zachary Turner <zturner@google.com> | 2016-12-09 05:46:41 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-12-09 05:46:41 +0000 |
commit | 2c84f908afc851a1ba83c6a8471a62db81475ef8 (patch) | |
tree | d51372b98dfbb090aafdab5dc233b32f790981d3 /lldb/source/Commands/CommandObjectMultiword.cpp | |
parent | 8db7e5e4eed4c4e697dc3164f2c9351d8c3e942b (diff) | |
download | bcm5719-llvm-2c84f908afc851a1ba83c6a8471a62db81475ef8.tar.gz bcm5719-llvm-2c84f908afc851a1ba83c6a8471a62db81475ef8.zip |
Remove some more uses of Args::GetArgumentAtIndex.
llvm-svn: 289188
Diffstat (limited to 'lldb/source/Commands/CommandObjectMultiword.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectMultiword.cpp | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp index 8aa28562011..0d0aa108a4c 100644 --- a/lldb/source/Commands/CommandObjectMultiword.cpp +++ b/lldb/source/Commands/CommandObjectMultiword.cpp @@ -98,58 +98,61 @@ bool CommandObjectMultiword::Execute(const char *args_string, const size_t argc = args.GetArgumentCount(); if (argc == 0) { this->CommandObject::GenerateHelpText(result); - } else { - const char *sub_command = args.GetArgumentAtIndex(0); - - if (sub_command) { - if (::strcasecmp(sub_command, "help") == 0) { - this->CommandObject::GenerateHelpText(result); - } else if (!m_subcommand_dict.empty()) { - StringList matches; - CommandObject *sub_cmd_obj = GetSubcommandObject(sub_command, &matches); - if (sub_cmd_obj != nullptr) { - // Now call CommandObject::Execute to process and options in - // 'rest_of_line'. From there - // the command-specific version of Execute will be called, with the - // processed arguments. - - args.Shift(); - - sub_cmd_obj->Execute(args_string, result); - } else { - std::string error_msg; - const size_t num_subcmd_matches = matches.GetSize(); - if (num_subcmd_matches > 0) - error_msg.assign("ambiguous command "); - else - error_msg.assign("invalid command "); - - error_msg.append("'"); - error_msg.append(GetCommandName()); - error_msg.append(" "); - error_msg.append(sub_command); - error_msg.append("'."); - - if (num_subcmd_matches > 0) { - error_msg.append(" Possible completions:"); - for (size_t i = 0; i < num_subcmd_matches; i++) { - error_msg.append("\n\t"); - error_msg.append(matches.GetStringAtIndex(i)); - } - } - error_msg.append("\n"); - result.AppendRawError(error_msg.c_str()); - result.SetStatus(eReturnStatusFailed); - } - } else { - result.AppendErrorWithFormat("'%s' does not have any subcommands.\n", - GetCommandName().str().c_str()); - result.SetStatus(eReturnStatusFailed); - } - } + return result.Succeeded(); + } + + auto sub_command = args[0].ref; + if (sub_command.empty()) + return result.Succeeded(); + + if (sub_command.equals_lower("help")) { + this->CommandObject::GenerateHelpText(result); + return result.Succeeded(); } - return result.Succeeded(); + if (m_subcommand_dict.empty()) { + result.AppendErrorWithFormat("'%s' does not have any subcommands.\n", + GetCommandName().str().c_str()); + result.SetStatus(eReturnStatusFailed); + return false; + } + + StringList matches; + CommandObject *sub_cmd_obj = GetSubcommandObject(sub_command, &matches); + if (sub_cmd_obj != nullptr) { + // Now call CommandObject::Execute to process options in `rest_of_line`. + // From there the command-specific version of Execute will be called, + // with the processed arguments. + + args.Shift(); + sub_cmd_obj->Execute(args_string, result); + return result.Succeeded(); + } + + std::string error_msg; + const size_t num_subcmd_matches = matches.GetSize(); + if (num_subcmd_matches > 0) + error_msg.assign("ambiguous command "); + else + error_msg.assign("invalid command "); + + error_msg.append("'"); + error_msg.append(GetCommandName()); + error_msg.append(" "); + error_msg.append(sub_command); + error_msg.append("'."); + + if (num_subcmd_matches > 0) { + error_msg.append(" Possible completions:"); + for (size_t i = 0; i < num_subcmd_matches; i++) { + error_msg.append("\n\t"); + error_msg.append(matches.GetStringAtIndex(i)); + } + } + error_msg.append("\n"); + result.AppendRawError(error_msg.c_str()); + result.SetStatus(eReturnStatusFailed); + return false; } void CommandObjectMultiword::GenerateHelpText(Stream &output_stream) { @@ -191,16 +194,15 @@ int CommandObjectMultiword::HandleCompletion(Args &input, int &cursor_index, bool &word_complete, StringList &matches) { // Any of the command matches will provide a complete word, otherwise the - // individual - // completers will override this. + // individual completers will override this. word_complete = true; - const char *arg0 = input.GetArgumentAtIndex(0); + auto arg0 = input[0].ref; if (cursor_index == 0) { AddNamesMatchingPartialString(m_subcommand_dict, arg0, matches); if (matches.GetSize() == 1 && matches.GetStringAtIndex(0) != nullptr && - strcmp(arg0, matches.GetStringAtIndex(0)) == 0) { + (arg0 == matches.GetStringAtIndex(0))) { StringList temp_matches; CommandObject *cmd_obj = GetSubcommandObject(arg0, &temp_matches); if (cmd_obj != nullptr) { @@ -240,7 +242,7 @@ const char *CommandObjectMultiword::GetRepeatCommand(Args ¤t_command_args, if (current_command_args.GetArgumentCount() <= index) return nullptr; CommandObject *sub_command_object = - GetSubcommandObject(current_command_args.GetArgumentAtIndex(index)); + GetSubcommandObject(current_command_args[index].ref); if (sub_command_object == nullptr) return nullptr; return sub_command_object->GetRepeatCommand(current_command_args, index); |