diff options
Diffstat (limited to 'source/Commands/CommandCompletions.cpp')
-rw-r--r-- | source/Commands/CommandCompletions.cpp | 263 |
1 files changed, 108 insertions, 155 deletions
diff --git a/source/Commands/CommandCompletions.cpp b/source/Commands/CommandCompletions.cpp index 37696e3bbfdb5..dd0ecb4b82e98 100644 --- a/source/Commands/CommandCompletions.cpp +++ b/source/Commands/CommandCompletions.cpp @@ -15,11 +15,14 @@ // C++ Includes // Other libraries and framework includes +#include "llvm/ADT/SmallString.h" + // Project includes -#include "lldb/Host/FileSpec.h" #include "lldb/Core/FileSpecList.h" -#include "lldb/Core/PluginManager.h" #include "lldb/Core/Module.h" +#include "lldb/Core/PluginManager.h" +#include "lldb/Host/FileSpec.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/CommandCompletions.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -36,7 +39,7 @@ using namespace lldb_private; CommandCompletions::CommonCompletionElement CommandCompletions::g_common_completions[] = { - {eCustomCompletion, NULL}, + {eCustomCompletion, nullptr}, {eSourceFileCompletion, CommandCompletions::SourceFiles}, {eDiskFileCompletion, CommandCompletions::DiskFiles}, {eDiskDirectoryCompletion, CommandCompletions::DiskDirectories}, @@ -46,21 +49,18 @@ CommandCompletions::g_common_completions[] = {ePlatformPluginCompletion, CommandCompletions::PlatformPluginNames}, {eArchitectureCompletion, CommandCompletions::ArchitectureNames}, {eVariablePathCompletion, CommandCompletions::VariablePath}, - {eNoCompletion, NULL} // This one has to be last in the list. + {eNoCompletion, nullptr} // This one has to be last in the list. }; bool -CommandCompletions::InvokeCommonCompletionCallbacks -( - CommandInterpreter &interpreter, - uint32_t completion_mask, - const char *completion_str, - int match_start_point, - int max_return_elements, - SearchFilter *searcher, - bool &word_complete, - StringList &matches -) +CommandCompletions::InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, + uint32_t completion_mask, + const char *completion_str, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches) { bool handled = false; @@ -72,7 +72,7 @@ CommandCompletions::InvokeCommonCompletionCallbacks if (g_common_completions[i].type == eNoCompletion) break; else if ((g_common_completions[i].type & completion_mask) == g_common_completions[i].type - && g_common_completions[i].callback != NULL) + && g_common_completions[i].callback != nullptr) { handled = true; g_common_completions[i].callback (interpreter, @@ -88,16 +88,13 @@ CommandCompletions::InvokeCommonCompletionCallbacks } int -CommandCompletions::SourceFiles -( - CommandInterpreter &interpreter, - const char *partial_file_name, - int match_start_point, - int max_return_elements, - SearchFilter *searcher, - bool &word_complete, - StringList &matches -) +CommandCompletions::SourceFiles(CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches) { word_complete = true; // Find some way to switch "include support files..." @@ -108,7 +105,7 @@ CommandCompletions::SourceFiles max_return_elements, matches); - if (searcher == NULL) + if (searcher == nullptr) { lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget(); SearchFilterForUnconstrainedSearches null_searcher (target_sp); @@ -166,8 +163,7 @@ FileSpec::EnumerateDirectoryResult DiskFilesOrDirectoriesCallback(void *baton, F isa_directory = true; else if (file_type == FileSpec::eFileTypeSymbolicLink) { - struct stat stat_buf; - if ((stat(partial_name_copy, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode)) + if (FileSpec(partial_name_copy, false).IsDirectory()) isa_directory = true; } @@ -187,13 +183,10 @@ FileSpec::EnumerateDirectoryResult DiskFilesOrDirectoriesCallback(void *baton, F } static int -DiskFilesOrDirectories -( - const char *partial_file_name, - bool only_directories, - bool &saw_directory, - StringList &matches -) +DiskFilesOrDirectories(const char *partial_file_name, + bool only_directories, + bool &saw_directory, + StringList &matches) { // I'm going to use the "glob" function with GLOB_TILDE for user directory expansion. // If it is not defined on your host system, you'll need to implement it yourself... @@ -224,7 +217,7 @@ DiskFilesOrDirectories // This will store the resolved form of the containing directory llvm::SmallString<64> containing_part; - if (end_ptr == NULL) + if (end_ptr == nullptr) { // There's no directory. If the thing begins with a "~" then this is a bare // user name. @@ -312,18 +305,14 @@ DiskFilesOrDirectories } int -CommandCompletions::DiskFiles -( - CommandInterpreter &interpreter, - const char *partial_file_name, - int match_start_point, - int max_return_elements, - SearchFilter *searcher, - bool &word_complete, - StringList &matches -) +CommandCompletions::DiskFiles(CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches) { - int ret_val = DiskFilesOrDirectories (partial_file_name, false, word_complete, @@ -333,16 +322,13 @@ CommandCompletions::DiskFiles } int -CommandCompletions::DiskDirectories -( - CommandInterpreter &interpreter, - const char *partial_file_name, - int match_start_point, - int max_return_elements, - SearchFilter *searcher, - bool &word_complete, - StringList &matches -) +CommandCompletions::DiskDirectories(CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches) { int ret_val = DiskFilesOrDirectories (partial_file_name, true, @@ -353,16 +339,13 @@ CommandCompletions::DiskDirectories } int -CommandCompletions::Modules -( - CommandInterpreter &interpreter, - const char *partial_file_name, - int match_start_point, - int max_return_elements, - SearchFilter *searcher, - bool &word_complete, - StringList &matches -) +CommandCompletions::Modules(CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches) { word_complete = true; ModuleCompleter completer (interpreter, @@ -371,7 +354,7 @@ CommandCompletions::Modules max_return_elements, matches); - if (searcher == NULL) + if (searcher == nullptr) { lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget(); SearchFilterForUnconstrainedSearches null_searcher (target_sp); @@ -385,15 +368,13 @@ CommandCompletions::Modules } int -CommandCompletions::Symbols -( - CommandInterpreter &interpreter, - const char *partial_file_name, - int match_start_point, - int max_return_elements, - SearchFilter *searcher, - bool &word_complete, - StringList &matches) +CommandCompletions::Symbols(CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches) { word_complete = true; SymbolCompleter completer (interpreter, @@ -402,7 +383,7 @@ CommandCompletions::Symbols max_return_elements, matches); - if (searcher == NULL) + if (searcher == nullptr) { lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget(); SearchFilterForUnconstrainedSearches null_searcher (target_sp); @@ -433,7 +414,7 @@ CommandCompletions::SettingsNames (CommandInterpreter &interpreter, if (properties_sp) { StreamString strm; - properties_sp->DumpValue(NULL, strm, OptionValue::eDumpOptionName); + properties_sp->DumpValue(nullptr, strm, OptionValue::eDumpOptionName); const std::string &str = strm.GetString(); g_property_names.SplitIntoLines(str.c_str(), str.size()); } @@ -445,7 +426,6 @@ CommandCompletions::SettingsNames (CommandInterpreter &interpreter, return num_matches; } - int CommandCompletions::PlatformPluginNames (CommandInterpreter &interpreter, const char *partial_name, @@ -474,7 +454,6 @@ CommandCompletions::ArchitectureNames (CommandInterpreter &interpreter, return num_matches; } - int CommandCompletions::VariablePath (CommandInterpreter &interpreter, const char *partial_name, @@ -487,15 +466,11 @@ CommandCompletions::VariablePath (CommandInterpreter &interpreter, return Variable::AutoComplete (interpreter.GetExecutionContext(), partial_name, matches, word_complete); } - -CommandCompletions::Completer::Completer -( - CommandInterpreter &interpreter, - const char *completion_str, - int match_start_point, - int max_return_elements, - StringList &matches -) : +CommandCompletions::Completer::Completer(CommandInterpreter &interpreter, + const char *completion_str, + int match_start_point, + int max_return_elements, + StringList &matches) : m_interpreter (interpreter), m_completion_str (completion_str), m_match_start_point (match_start_point), @@ -504,24 +479,18 @@ CommandCompletions::Completer::Completer { } -CommandCompletions::Completer::~Completer () -{ - -} +CommandCompletions::Completer::~Completer() = default; //---------------------------------------------------------------------- // SourceFileCompleter //---------------------------------------------------------------------- -CommandCompletions::SourceFileCompleter::SourceFileCompleter -( - CommandInterpreter &interpreter, - bool include_support_files, - const char *completion_str, - int match_start_point, - int max_return_elements, - StringList &matches -) : +CommandCompletions::SourceFileCompleter::SourceFileCompleter(CommandInterpreter &interpreter, + bool include_support_files, + const char *completion_str, + int match_start_point, + int max_return_elements, + StringList &matches) : CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches), m_include_support_files (include_support_files), m_matching_files() @@ -538,14 +507,12 @@ CommandCompletions::SourceFileCompleter::GetDepth() } Searcher::CallbackReturn -CommandCompletions::SourceFileCompleter::SearchCallback ( - SearchFilter &filter, - SymbolContext &context, - Address *addr, - bool complete -) +CommandCompletions::SourceFileCompleter::SearchCallback(SearchFilter &filter, + SymbolContext &context, + Address *addr, + bool complete) { - if (context.comp_unit != NULL) + if (context.comp_unit != nullptr) { if (m_include_support_files) { @@ -568,7 +535,6 @@ CommandCompletions::SourceFileCompleter::SearchCallback ( m_matching_files.AppendIfUnique(sfile_spec); } } - } else { @@ -603,7 +569,6 @@ CommandCompletions::SourceFileCompleter::DoCompletion (SearchFilter *filter) m_matches.AppendString (m_matching_files.GetFileSpecAtIndex(i).GetFilename().GetCString()); } return m_matches.GetSize(); - } //---------------------------------------------------------------------- @@ -613,29 +578,24 @@ CommandCompletions::SourceFileCompleter::DoCompletion (SearchFilter *filter) static bool regex_chars (const char comp) { - if (comp == '[' || comp == ']' || - comp == '(' || comp == ')' || - comp == '{' || comp == '}' || - comp == '+' || - comp == '.' || - comp == '*' || - comp == '|' || - comp == '^' || - comp == '$' || - comp == '\\' || - comp == '?') - return true; - else - return false; + return (comp == '[' || comp == ']' || + comp == '(' || comp == ')' || + comp == '{' || comp == '}' || + comp == '+' || + comp == '.' || + comp == '*' || + comp == '|' || + comp == '^' || + comp == '$' || + comp == '\\' || + comp == '?'); } -CommandCompletions::SymbolCompleter::SymbolCompleter -( - CommandInterpreter &interpreter, - const char *completion_str, - int match_start_point, - int max_return_elements, - StringList &matches -) : + +CommandCompletions::SymbolCompleter::SymbolCompleter(CommandInterpreter &interpreter, + const char *completion_str, + int match_start_point, + int max_return_elements, + StringList &matches) : CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches) { std::string regex_str; @@ -665,12 +625,10 @@ CommandCompletions::SymbolCompleter::GetDepth() } Searcher::CallbackReturn -CommandCompletions::SymbolCompleter::SearchCallback ( - SearchFilter &filter, - SymbolContext &context, - Address *addr, - bool complete -) +CommandCompletions::SymbolCompleter::SearchCallback(SearchFilter &filter, + SymbolContext &context, + Address *addr, + bool complete) { if (context.module_sp) { @@ -709,14 +667,11 @@ CommandCompletions::SymbolCompleter::DoCompletion (SearchFilter *filter) //---------------------------------------------------------------------- // ModuleCompleter //---------------------------------------------------------------------- -CommandCompletions::ModuleCompleter::ModuleCompleter -( - CommandInterpreter &interpreter, - const char *completion_str, - int match_start_point, - int max_return_elements, - StringList &matches -) : +CommandCompletions::ModuleCompleter::ModuleCompleter(CommandInterpreter &interpreter, + const char *completion_str, + int match_start_point, + int max_return_elements, + StringList &matches) : CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches) { FileSpec partial_spec (m_completion_str.c_str(), false); @@ -731,12 +686,10 @@ CommandCompletions::ModuleCompleter::GetDepth() } Searcher::CallbackReturn -CommandCompletions::ModuleCompleter::SearchCallback ( - SearchFilter &filter, - SymbolContext &context, - Address *addr, - bool complete -) +CommandCompletions::ModuleCompleter::SearchCallback(SearchFilter &filter, + SymbolContext &context, + Address *addr, + bool complete) { if (context.module_sp) { |