1 //===-- CommandCompletions.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_CommandCompletions_h_
11 #define lldb_CommandCompletions_h_
17 // Other libraries and framework includes
19 #include "lldb/Core/FileSpecList.h"
20 #include "lldb/Core/RegularExpression.h"
21 #include "lldb/Core/SearchFilter.h"
22 #include "lldb/lldb-private.h"
24 namespace lldb_private {
25 class CommandCompletions {
27 //----------------------------------------------------------------------
28 // This is the command completion callback that is used to complete the
29 // argument of the option
30 // it is bound to (in the OptionDefinition table below). Return the total
32 //----------------------------------------------------------------------
33 typedef int (*CompletionCallback)(
34 CommandInterpreter &interpreter,
35 llvm::StringRef completion_str, // This is the argument we are completing
36 int match_start_point, // This is the point in the list of matches that
37 // you should start returning elements
38 int max_return_elements, // This is the number of matches requested.
39 lldb_private::SearchFilter
40 *searcher, // A search filter to limit the search...
42 lldb_private::StringList &matches); // The array of matches we return.
45 eSourceFileCompletion = (1u << 0),
46 eDiskFileCompletion = (1u << 1),
47 eDiskDirectoryCompletion = (1u << 2),
48 eSymbolCompletion = (1u << 3),
49 eModuleCompletion = (1u << 4),
50 eSettingsNameCompletion = (1u << 5),
51 ePlatformPluginCompletion = (1u << 6),
52 eArchitectureCompletion = (1u << 7),
53 eVariablePathCompletion = (1u << 8),
54 // This item serves two purposes. It is the last element in the enum,
55 // so you can add custom enums starting from here in your Option class.
56 // Also if you & in this bit the base code will not process the option.
57 eCustomCompletion = (1u << 9)
58 } CommonCompletionTypes;
60 struct CommonCompletionElement {
62 CompletionCallback callback;
65 static bool InvokeCommonCompletionCallbacks(
66 CommandInterpreter &interpreter, uint32_t completion_mask,
67 llvm::StringRef completion_str, int match_start_point,
68 int max_return_elements, SearchFilter *searcher, bool &word_complete,
71 //----------------------------------------------------------------------
72 // These are the generic completer functions:
73 //----------------------------------------------------------------------
74 static int DiskFiles(CommandInterpreter &interpreter,
75 llvm::StringRef partial_file_name, int match_start_point,
76 int max_return_elements, SearchFilter *searcher,
77 bool &word_complete, StringList &matches);
79 static int DiskDirectories(CommandInterpreter &interpreter,
80 llvm::StringRef partial_file_name,
81 int match_start_point, int max_return_elements,
82 SearchFilter *searcher, bool &word_complete,
85 static int SourceFiles(CommandInterpreter &interpreter,
86 llvm::StringRef partial_file_name,
87 int match_start_point, int max_return_elements,
88 SearchFilter *searcher, bool &word_complete,
91 static int Modules(CommandInterpreter &interpreter,
92 llvm::StringRef partial_file_name, int match_start_point,
93 int max_return_elements, SearchFilter *searcher,
94 bool &word_complete, lldb_private::StringList &matches);
96 static int Symbols(CommandInterpreter &interpreter,
97 llvm::StringRef partial_file_name, int match_start_point,
98 int max_return_elements, SearchFilter *searcher,
99 bool &word_complete, lldb_private::StringList &matches);
101 static int SettingsNames(CommandInterpreter &interpreter,
102 llvm::StringRef partial_file_name,
103 int match_start_point, int max_return_elements,
104 SearchFilter *searcher, bool &word_complete,
105 lldb_private::StringList &matches);
107 static int PlatformPluginNames(CommandInterpreter &interpreter,
108 llvm::StringRef partial_file_name,
109 int match_start_point, int max_return_elements,
110 SearchFilter *searcher, bool &word_complete,
111 lldb_private::StringList &matches);
113 static int ArchitectureNames(CommandInterpreter &interpreter,
114 llvm::StringRef partial_file_name,
115 int match_start_point, int max_return_elements,
116 SearchFilter *searcher, bool &word_complete,
117 lldb_private::StringList &matches);
119 static int VariablePath(CommandInterpreter &interpreter,
120 llvm::StringRef partial_file_name,
121 int match_start_point, int max_return_elements,
122 SearchFilter *searcher, bool &word_complete,
123 lldb_private::StringList &matches);
125 //----------------------------------------------------------------------
126 // The Completer class is a convenient base class for building searchers
127 // that go along with the SearchFilter passed to the standard Completer
129 //----------------------------------------------------------------------
130 class Completer : public Searcher {
132 Completer(CommandInterpreter &interpreter, llvm::StringRef completion_str,
133 int match_start_point, int max_return_elements,
134 StringList &matches);
136 ~Completer() override;
138 CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
139 Address *addr, bool complete) override = 0;
141 Depth GetDepth() override = 0;
143 virtual size_t DoCompletion(SearchFilter *filter) = 0;
146 CommandInterpreter &m_interpreter;
147 std::string m_completion_str;
148 int m_match_start_point;
149 int m_max_return_elements;
150 StringList &m_matches;
153 DISALLOW_COPY_AND_ASSIGN(Completer);
156 //----------------------------------------------------------------------
157 // SourceFileCompleter implements the source file completer
158 //----------------------------------------------------------------------
159 class SourceFileCompleter : public Completer {
161 SourceFileCompleter(CommandInterpreter &interpreter,
162 bool include_support_files,
163 llvm::StringRef completion_str, int match_start_point,
164 int max_return_elements, StringList &matches);
166 Searcher::Depth GetDepth() override;
168 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
169 SymbolContext &context,
171 bool complete) override;
173 size_t DoCompletion(SearchFilter *filter) override;
176 bool m_include_support_files;
177 FileSpecList m_matching_files;
178 const char *m_file_name;
179 const char *m_dir_name;
181 DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
184 //----------------------------------------------------------------------
185 // ModuleCompleter implements the module completer
186 //----------------------------------------------------------------------
187 class ModuleCompleter : public Completer {
189 ModuleCompleter(CommandInterpreter &interpreter,
190 llvm::StringRef completion_str, int match_start_point,
191 int max_return_elements, StringList &matches);
193 Searcher::Depth GetDepth() override;
195 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
196 SymbolContext &context,
198 bool complete) override;
200 size_t DoCompletion(SearchFilter *filter) override;
203 const char *m_file_name;
204 const char *m_dir_name;
206 DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
209 //----------------------------------------------------------------------
210 // SymbolCompleter implements the symbol completer
211 //----------------------------------------------------------------------
212 class SymbolCompleter : public Completer {
214 SymbolCompleter(CommandInterpreter &interpreter,
215 llvm::StringRef completion_str, int match_start_point,
216 int max_return_elements, StringList &matches);
218 Searcher::Depth GetDepth() override;
220 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
221 SymbolContext &context,
223 bool complete) override;
225 size_t DoCompletion(SearchFilter *filter) override;
229 // bool operator() (const ConstString& lhs, const ConstString&
236 RegularExpression m_regex;
237 typedef std::set<ConstString> collection;
238 collection m_match_set;
240 DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
244 static CommonCompletionElement g_common_completions[];
247 } // namespace lldb_private
249 #endif // lldb_CommandCompletions_h_