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/lldb-private.h"
20 #include "lldb/Core/SearchFilter.h"
21 #include "lldb/Core/FileSpecList.h"
22 #include "lldb/Core/RegularExpression.h"
24 namespace lldb_private
26 class CommandCompletions
30 //----------------------------------------------------------------------
31 // This is the command completion callback that is used to complete the argument of the option
32 // it is bound to (in the OptionDefinition table below). Return the total number of matches.
33 //----------------------------------------------------------------------
34 typedef int (*CompletionCallback) (CommandInterpreter &interpreter,
35 const char *completion_str, // This is the argument we are completing
36 int match_start_point, // This is the point in the list of matches that you should start returning elements
37 int max_return_elements, // This is the number of matches requested.
38 lldb_private::SearchFilter *searcher,// A search filter to limit the search...
40 lldb_private::StringList &matches); // The array of matches we return.
44 eSourceFileCompletion = (1u << 0),
45 eDiskFileCompletion = (1u << 1),
46 eDiskDirectoryCompletion = (1u << 2),
47 eSymbolCompletion = (1u << 3),
48 eModuleCompletion = (1u << 4),
49 eSettingsNameCompletion = (1u << 5),
50 ePlatformPluginCompletion = (1u << 6),
51 eArchitectureCompletion = (1u << 7),
52 eVariablePathCompletion = (1u << 8),
53 // This item serves two purposes. It is the last element in the enum,
54 // so you can add custom enums starting from here in your Option class.
55 // Also if you & in this bit the base code will not process the option.
56 eCustomCompletion = (1u << 9)
58 } CommonCompletionTypes;
60 struct CommonCompletionElement
63 CompletionCallback callback;
66 static bool InvokeCommonCompletionCallbacks (CommandInterpreter &interpreter,
67 uint32_t completion_mask,
68 const char *completion_str,
69 int match_start_point,
70 int max_return_elements,
71 SearchFilter *searcher,
75 //----------------------------------------------------------------------
76 // These are the generic completer functions:
77 //----------------------------------------------------------------------
79 DiskFiles (CommandInterpreter &interpreter,
80 const char *partial_file_name,
81 int match_start_point,
82 int max_return_elements,
83 SearchFilter *searcher,
87 DiskDirectories (CommandInterpreter &interpreter,
88 const char *partial_file_name,
89 int match_start_point,
90 int max_return_elements,
91 SearchFilter *searcher,
96 SourceFiles (CommandInterpreter &interpreter,
97 const char *partial_file_name,
98 int match_start_point,
99 int max_return_elements,
100 SearchFilter *searcher,
102 StringList &matches);
105 Modules (CommandInterpreter &interpreter,
106 const char *partial_file_name,
107 int match_start_point,
108 int max_return_elements,
109 SearchFilter *searcher,
111 lldb_private::StringList &matches);
114 Symbols (CommandInterpreter &interpreter,
115 const char *partial_file_name,
116 int match_start_point,
117 int max_return_elements,
118 SearchFilter *searcher,
120 lldb_private::StringList &matches);
123 SettingsNames (CommandInterpreter &interpreter,
124 const char *partial_file_name,
125 int match_start_point,
126 int max_return_elements,
127 SearchFilter *searcher,
129 lldb_private::StringList &matches);
132 PlatformPluginNames (CommandInterpreter &interpreter,
133 const char *partial_file_name,
134 int match_start_point,
135 int max_return_elements,
136 SearchFilter *searcher,
138 lldb_private::StringList &matches);
142 ArchitectureNames (CommandInterpreter &interpreter,
143 const char *partial_file_name,
144 int match_start_point,
145 int max_return_elements,
146 SearchFilter *searcher,
148 lldb_private::StringList &matches);
151 VariablePath (CommandInterpreter &interpreter,
152 const char *partial_file_name,
153 int match_start_point,
154 int max_return_elements,
155 SearchFilter *searcher,
157 lldb_private::StringList &matches);
159 //----------------------------------------------------------------------
160 // The Completer class is a convenient base class for building searchers
161 // that go along with the SearchFilter passed to the standard Completer
163 //----------------------------------------------------------------------
164 class Completer : public Searcher
167 Completer (CommandInterpreter &interpreter,
168 const char *completion_str,
169 int match_start_point,
170 int max_return_elements,
171 StringList &matches);
173 virtual ~Completer ();
175 virtual CallbackReturn
176 SearchCallback (SearchFilter &filter,
177 SymbolContext &context,
185 DoCompletion (SearchFilter *filter) = 0;
188 CommandInterpreter &m_interpreter;
189 std::string m_completion_str;
190 int m_match_start_point;
191 int m_max_return_elements;
192 StringList &m_matches;
194 DISALLOW_COPY_AND_ASSIGN (Completer);
197 //----------------------------------------------------------------------
198 // SouceFileCompleter implements the source file completer
199 //----------------------------------------------------------------------
200 class SourceFileCompleter : public Completer
204 SourceFileCompleter (CommandInterpreter &interpreter,
205 bool include_support_files,
206 const char *completion_str,
207 int match_start_point,
208 int max_return_elements,
209 StringList &matches);
211 virtual Searcher::Depth GetDepth ();
213 virtual Searcher::CallbackReturn
214 SearchCallback (SearchFilter &filter,
215 SymbolContext &context,
220 DoCompletion (SearchFilter *filter);
223 bool m_include_support_files;
224 FileSpecList m_matching_files;
225 const char *m_file_name;
226 const char *m_dir_name;
227 DISALLOW_COPY_AND_ASSIGN (SourceFileCompleter);
231 //----------------------------------------------------------------------
232 // ModuleCompleter implements the module completer
233 //----------------------------------------------------------------------
234 class ModuleCompleter : public Completer
238 ModuleCompleter (CommandInterpreter &interpreter,
239 const char *completion_str,
240 int match_start_point,
241 int max_return_elements,
242 StringList &matches);
244 virtual Searcher::Depth GetDepth ();
246 virtual Searcher::CallbackReturn
247 SearchCallback (SearchFilter &filter,
248 SymbolContext &context,
253 DoCompletion (SearchFilter *filter);
256 const char *m_file_name;
257 const char *m_dir_name;
258 DISALLOW_COPY_AND_ASSIGN (ModuleCompleter);
262 //----------------------------------------------------------------------
263 // SymbolCompleter implements the symbol completer
264 //----------------------------------------------------------------------
265 class SymbolCompleter : public Completer
269 SymbolCompleter (CommandInterpreter &interpreter,
270 const char *completion_str,
271 int match_start_point,
272 int max_return_elements,
273 StringList &matches);
275 virtual Searcher::Depth GetDepth ();
277 virtual Searcher::CallbackReturn
278 SearchCallback (SearchFilter &filter,
279 SymbolContext &context,
284 DoCompletion (SearchFilter *filter);
288 // bool operator() (const ConstString& lhs, const ConstString& rhs) const
294 RegularExpression m_regex;
295 typedef std::set<ConstString> collection;
296 collection m_match_set;
297 DISALLOW_COPY_AND_ASSIGN (SymbolCompleter);
302 static CommonCompletionElement g_common_completions[];
306 } // namespace lldb_private
307 #endif // lldb_CommandCompletions_h_