diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-08-22 09:02:54 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-08-22 09:02:54 +0000 |
commit | 1153dc9603c74f85314505abdae28b3f0dc85c39 (patch) | |
tree | 4f32ee69f63bdcbfb94470ae767186cdfb6de47d | |
parent | 35038c914c187484e65440d204029e716ea1eeca (diff) | |
download | bcm5719-llvm-1153dc9603c74f85314505abdae28b3f0dc85c39.tar.gz bcm5719-llvm-1153dc9603c74f85314505abdae28b3f0dc85c39.zip |
[lldb][NFC] NFC cleanup for the completion code
llvm-svn: 369632
-rw-r--r-- | lldb/source/Commands/CommandObjectHelp.cpp | 26 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectMultiword.cpp | 28 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectPlatform.cpp | 51 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectProcess.cpp | 52 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectSettings.cpp | 35 | ||||
-rw-r--r-- | lldb/source/Core/IOHandler.cpp | 9 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionValueEnumeration.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionValueUUID.cpp | 36 |
8 files changed, 121 insertions, 121 deletions
diff --git a/lldb/source/Commands/CommandObjectHelp.cpp b/lldb/source/Commands/CommandObjectHelp.cpp index 811841fa47a..78e19f73416 100644 --- a/lldb/source/Commands/CommandObjectHelp.cpp +++ b/lldb/source/Commands/CommandObjectHelp.cpp @@ -205,20 +205,20 @@ void CommandObjectHelp::HandleCompletion(CompletionRequest &request) { // Return the completions of the commands in the help system: if (request.GetCursorIndex() == 0) { m_interpreter.HandleCompletionMatches(request); - } else { - CommandObject *cmd_obj = - m_interpreter.GetCommandObject(request.GetParsedLine()[0].ref); + return; + } + CommandObject *cmd_obj = + m_interpreter.GetCommandObject(request.GetParsedLine()[0].ref); - // The command that they are getting help on might be ambiguous, in which - // case we should complete that, otherwise complete with the command the - // user is getting help on... + // The command that they are getting help on might be ambiguous, in which + // case we should complete that, otherwise complete with the command the + // user is getting help on... - if (cmd_obj) { - request.GetParsedLine().Shift(); - request.SetCursorIndex(request.GetCursorIndex() - 1); - cmd_obj->HandleCompletion(request); - } else { - m_interpreter.HandleCompletionMatches(request); - } + if (cmd_obj) { + request.GetParsedLine().Shift(); + request.SetCursorIndex(request.GetCursorIndex() - 1); + cmd_obj->HandleCompletion(request); + return; } + m_interpreter.HandleCompletionMatches(request); } diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp index ecc73a8cbe9..a223d709535 100644 --- a/lldb/source/Commands/CommandObjectMultiword.cpp +++ b/lldb/source/Commands/CommandObjectMultiword.cpp @@ -201,20 +201,22 @@ void CommandObjectMultiword::HandleCompletion(CompletionRequest &request) { } } } - } else { - StringList new_matches; - CommandObject *sub_command_object = GetSubcommandObject(arg0, &new_matches); - if (sub_command_object == nullptr) { - request.AddCompletions(new_matches); - } else { - // Remove the one match that we got from calling GetSubcommandObject. - new_matches.DeleteStringAtIndex(0); - request.AddCompletions(new_matches); - request.GetParsedLine().Shift(); - request.SetCursorIndex(request.GetCursorIndex() - 1); - return sub_command_object->HandleCompletion(request); - } + return; } + + StringList new_matches; + CommandObject *sub_command_object = GetSubcommandObject(arg0, &new_matches); + if (sub_command_object == nullptr) { + request.AddCompletions(new_matches); + return; + } + + // Remove the one match that we got from calling GetSubcommandObject. + new_matches.DeleteStringAtIndex(0); + request.AddCompletions(new_matches); + request.GetParsedLine().Shift(); + request.SetCursorIndex(request.GetCursorIndex() - 1); + sub_command_object->HandleCompletion(request); } const char *CommandObjectMultiword::GetRepeatCommand(Args ¤t_command_args, diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index c1e78d703d7..8433fbdc985 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -1440,36 +1440,37 @@ public: // We are only completing the name option for now... - if (GetDefinitions()[opt_defs_index].short_option == 'n') { - // Are we in the name? + // Are we in the name? + if (GetDefinitions()[opt_defs_index].short_option != 'n') + return false; - // Look to see if there is a -P argument provided, and if so use that - // plugin, otherwise use the default plugin. + // Look to see if there is a -P argument provided, and if so use that + // plugin, otherwise use the default plugin. - const char *partial_name = nullptr; - partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos); + const char *partial_name = nullptr; + partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos); - PlatformSP platform_sp(interpreter.GetPlatform(true)); - if (platform_sp) { - ProcessInstanceInfoList process_infos; - ProcessInstanceInfoMatch match_info; - if (partial_name) { - match_info.GetProcessInfo().GetExecutableFile().SetFile( - partial_name, FileSpec::Style::native); - match_info.SetNameMatchType(NameMatch::StartsWith); - } - platform_sp->FindProcesses(match_info, process_infos); - const uint32_t num_matches = process_infos.GetSize(); - if (num_matches > 0) { - for (uint32_t i = 0; i < num_matches; ++i) { - request.AddCompletion(llvm::StringRef( - process_infos.GetProcessNameAtIndex(i), - process_infos.GetProcessNameLengthAtIndex(i))); - } - } - } + PlatformSP platform_sp(interpreter.GetPlatform(true)); + if (!platform_sp) + return false; + + ProcessInstanceInfoList process_infos; + ProcessInstanceInfoMatch match_info; + if (partial_name) { + match_info.GetProcessInfo().GetExecutableFile().SetFile( + partial_name, FileSpec::Style::native); + match_info.SetNameMatchType(NameMatch::StartsWith); } + platform_sp->FindProcesses(match_info, process_infos); + const uint32_t num_matches = process_infos.GetSize(); + if (num_matches == 0) + return false; + for (uint32_t i = 0; i < num_matches; ++i) { + request.AddCompletion( + llvm::StringRef(process_infos.GetProcessNameAtIndex(i), + process_infos.GetProcessNameLengthAtIndex(i))); + } return false; } diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 10af1a35872..1a1378b1938 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -328,35 +328,35 @@ public: // We are only completing the name option for now... - if (GetDefinitions()[opt_defs_index].short_option == 'n') { - // Are we in the name? - - // Look to see if there is a -P argument provided, and if so use that - // plugin, otherwise use the default plugin. - - const char *partial_name = nullptr; - partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos); - - PlatformSP platform_sp(interpreter.GetPlatform(true)); - if (platform_sp) { - ProcessInstanceInfoList process_infos; - ProcessInstanceInfoMatch match_info; - if (partial_name) { - match_info.GetProcessInfo().GetExecutableFile().SetFile( - partial_name, FileSpec::Style::native); - match_info.SetNameMatchType(NameMatch::StartsWith); - } + // Are we in the name? + if (GetDefinitions()[opt_defs_index].short_option != 'n') + return false; + + // Look to see if there is a -P argument provided, and if so use that + // plugin, otherwise use the default plugin. + + const char *partial_name = nullptr; + partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos); + + PlatformSP platform_sp(interpreter.GetPlatform(true)); + if (!platform_sp) + return false; + ProcessInstanceInfoList process_infos; + ProcessInstanceInfoMatch match_info; + if (partial_name) { + match_info.GetProcessInfo().GetExecutableFile().SetFile( + partial_name, FileSpec::Style::native); + match_info.SetNameMatchType(NameMatch::StartsWith); + } platform_sp->FindProcesses(match_info, process_infos); const size_t num_matches = process_infos.GetSize(); - if (num_matches > 0) { - for (size_t i = 0; i < num_matches; ++i) { - request.AddCompletion(llvm::StringRef( - process_infos.GetProcessNameAtIndex(i), - process_infos.GetProcessNameLengthAtIndex(i))); - } + if (num_matches == 0) + return false; + for (size_t i = 0; i < num_matches; ++i) { + request.AddCompletion( + llvm::StringRef(process_infos.GetProcessNameAtIndex(i), + process_infos.GetProcessNameLengthAtIndex(i))); } - } - } return false; } diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index 05e8ec919de..5f6a4dc97ae 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -142,26 +142,27 @@ insert-before or insert-after."); CommandCompletions::InvokeCommonCompletionCallbacks( GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion, request, nullptr); - } else { + return; + } arg = request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex()); - if (arg) { - if (arg[0] == '-') { - // Complete option name - } else { - // Complete setting value - const char *setting_var_name = - request.GetParsedLine().GetArgumentAtIndex(setting_var_idx); - Status error; - lldb::OptionValueSP value_sp(GetDebugger().GetPropertyValue( - &m_exe_ctx, setting_var_name, false, error)); - if (value_sp) { - value_sp->AutoComplete(m_interpreter, request); - } - } - } - } + if (!arg) + return; + + // Complete option name + if (arg[0] != '-') + return; + + // Complete setting value + const char *setting_var_name = + request.GetParsedLine().GetArgumentAtIndex(setting_var_idx); + Status error; + lldb::OptionValueSP value_sp(GetDebugger().GetPropertyValue( + &m_exe_ctx, setting_var_name, false, error)); + if (!value_sp) + return; + value_sp->AutoComplete(m_interpreter, request); } protected: diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index a95e4c17f08..5394f16b7f9 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -172,12 +172,9 @@ IOHandlerConfirm::~IOHandlerConfirm() = default; void IOHandlerConfirm::IOHandlerComplete(IOHandler &io_handler, CompletionRequest &request) { - if (request.GetRawCursorPos() == 0) { - if (m_default_response) - request.AddCompletion("y"); - else - request.AddCompletion("n"); - } + if (request.GetRawCursorPos() != 0) + return; + request.AddCompletion(m_default_response ? "y" : "n"); } void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler, diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp index 3df0e27bab4..126a4f53e10 100644 --- a/lldb/source/Interpreter/OptionValueEnumeration.cpp +++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp @@ -111,9 +111,8 @@ void OptionValueEnumeration::AutoComplete(CommandInterpreter &interpreter, if (name.startswith(request.GetCursorArgumentPrefix())) request.AddCompletion(name); } - } else { - // only suggest "true" or "false" by default + return; + } for (size_t i = 0; i < num_enumerators; ++i) request.AddCompletion(m_enumerations.GetCStringAtIndex(i).GetStringRef()); - } } diff --git a/lldb/source/Interpreter/OptionValueUUID.cpp b/lldb/source/Interpreter/OptionValueUUID.cpp index d2226ff3743..483c47807d2 100644 --- a/lldb/source/Interpreter/OptionValueUUID.cpp +++ b/lldb/source/Interpreter/OptionValueUUID.cpp @@ -66,24 +66,24 @@ void OptionValueUUID::AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request) { ExecutionContext exe_ctx(interpreter.GetExecutionContext()); Target *target = exe_ctx.GetTargetPtr(); - if (target) { - auto prefix = request.GetCursorArgumentPrefix(); - llvm::SmallVector<uint8_t, 20> uuid_bytes; - if (UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty()) { - const size_t num_modules = target->GetImages().GetSize(); - for (size_t i = 0; i < num_modules; ++i) { - ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i)); - if (module_sp) { - const UUID &module_uuid = module_sp->GetUUID(); - if (module_uuid.IsValid()) { - llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes(); - if (module_bytes.size() >= uuid_bytes.size() && - module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) { - request.AddCompletion(module_uuid.GetAsString()); - } - } - } - } + if (!target) + return; + auto prefix = request.GetCursorArgumentPrefix(); + llvm::SmallVector<uint8_t, 20> uuid_bytes; + if (!UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty()) + return; + const size_t num_modules = target->GetImages().GetSize(); + for (size_t i = 0; i < num_modules; ++i) { + ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i)); + if (!module_sp) + continue; + const UUID &module_uuid = module_sp->GetUUID(); + if (!module_uuid.IsValid()) + continue; + llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes(); + if (module_bytes.size() >= uuid_bytes.size() && + module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) { + request.AddCompletion(module_uuid.GetAsString()); } } } |