[Lldb-commits] [lldb] r369632 - [lldb][NFC] NFC cleanup for the completion code
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 22 02:02:55 PDT 2019
Author: teemperor
Date: Thu Aug 22 02:02:54 2019
New Revision: 369632
URL: http://llvm.org/viewvc/llvm-project?rev=369632&view=rev
Log:
[lldb][NFC] NFC cleanup for the completion code
Modified:
lldb/trunk/source/Commands/CommandObjectHelp.cpp
lldb/trunk/source/Commands/CommandObjectMultiword.cpp
lldb/trunk/source/Commands/CommandObjectPlatform.cpp
lldb/trunk/source/Commands/CommandObjectProcess.cpp
lldb/trunk/source/Commands/CommandObjectSettings.cpp
lldb/trunk/source/Core/IOHandler.cpp
lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp
lldb/trunk/source/Interpreter/OptionValueUUID.cpp
Modified: lldb/trunk/source/Commands/CommandObjectHelp.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=369632&r1=369631&r2=369632&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectHelp.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectHelp.cpp Thu Aug 22 02:02:54 2019
@@ -205,20 +205,20 @@ void CommandObjectHelp::HandleCompletion
// 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);
}
Modified: lldb/trunk/source/Commands/CommandObjectMultiword.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMultiword.cpp?rev=369632&r1=369631&r2=369632&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMultiword.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMultiword.cpp Thu Aug 22 02:02:54 2019
@@ -201,20 +201,22 @@ void CommandObjectMultiword::HandleCompl
}
}
}
- } 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,
Modified: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlatform.cpp?rev=369632&r1=369631&r2=369632&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp Thu Aug 22 02:02:54 2019
@@ -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?
-
- // 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);
- }
- 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)));
- }
- }
- }
+ // 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 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;
}
Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=369632&r1=369631&r2=369632&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Thu Aug 22 02:02:54 2019
@@ -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;
}
Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=369632&r1=369631&r2=369632&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Thu Aug 22 02:02:54 2019
@@ -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:
Modified: lldb/trunk/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=369632&r1=369631&r2=369632&view=diff
==============================================================================
--- lldb/trunk/source/Core/IOHandler.cpp (original)
+++ lldb/trunk/source/Core/IOHandler.cpp Thu Aug 22 02:02:54 2019
@@ -172,12 +172,9 @@ IOHandlerConfirm::~IOHandlerConfirm() =
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,
Modified: lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp?rev=369632&r1=369631&r2=369632&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp Thu Aug 22 02:02:54 2019
@@ -111,9 +111,8 @@ void OptionValueEnumeration::AutoComplet
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());
- }
}
Modified: lldb/trunk/source/Interpreter/OptionValueUUID.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueUUID.cpp?rev=369632&r1=369631&r2=369632&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueUUID.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueUUID.cpp Thu Aug 22 02:02:54 2019
@@ -66,24 +66,24 @@ void OptionValueUUID::AutoComplete(Comma
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());
}
}
}
More information about the lldb-commits
mailing list