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/SearchFilter.h"
21 #include "lldb/Utility/RegularExpression.h"
22 #include "lldb/lldb-private.h"
24 #include "llvm/ADT/Twine.h"
26 namespace lldb_private {
27 class TildeExpressionResolver;
28 class CommandCompletions {
30 //----------------------------------------------------------------------
31 // This is the command completion callback that is used to complete the
32 // argument of the option
33 // it is bound to (in the OptionDefinition table below). Return the total
35 //----------------------------------------------------------------------
36 typedef int (*CompletionCallback)(
37 CommandInterpreter &interpreter,
38 llvm::StringRef completion_str, // This is the argument we are completing
39 int match_start_point, // This is the point in the list of matches that
40 // you should start returning elements
41 int max_return_elements, // This is the number of matches requested.
42 lldb_private::SearchFilter
43 *searcher, // A search filter to limit the search...
45 lldb_private::StringList &matches); // The array of matches we return.
48 eSourceFileCompletion = (1u << 0),
49 eDiskFileCompletion = (1u << 1),
50 eDiskDirectoryCompletion = (1u << 2),
51 eSymbolCompletion = (1u << 3),
52 eModuleCompletion = (1u << 4),
53 eSettingsNameCompletion = (1u << 5),
54 ePlatformPluginCompletion = (1u << 6),
55 eArchitectureCompletion = (1u << 7),
56 eVariablePathCompletion = (1u << 8),
57 // This item serves two purposes. It is the last element in the enum,
58 // so you can add custom enums starting from here in your Option class.
59 // Also if you & in this bit the base code will not process the option.
60 eCustomCompletion = (1u << 9)
61 } CommonCompletionTypes;
63 struct CommonCompletionElement {
65 CompletionCallback callback;
68 static bool InvokeCommonCompletionCallbacks(
69 CommandInterpreter &interpreter, uint32_t completion_mask,
70 llvm::StringRef completion_str, int match_start_point,
71 int max_return_elements, SearchFilter *searcher, bool &word_complete,
74 //----------------------------------------------------------------------
75 // These are the generic completer functions:
76 //----------------------------------------------------------------------
77 static int DiskFiles(CommandInterpreter &interpreter,
78 llvm::StringRef partial_file_name, int match_start_point,
79 int max_return_elements, SearchFilter *searcher,
80 bool &word_complete, StringList &matches);
82 static int DiskFiles(const llvm::Twine &partial_file_name,
83 StringList &matches, TildeExpressionResolver &Resolver);
85 static int DiskDirectories(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 DiskDirectories(const llvm::Twine &partial_file_name,
93 TildeExpressionResolver &Resolver);
95 static int SourceFiles(CommandInterpreter &interpreter,
96 llvm::StringRef partial_file_name,
97 int match_start_point, int max_return_elements,
98 SearchFilter *searcher, bool &word_complete,
101 static int Modules(CommandInterpreter &interpreter,
102 llvm::StringRef partial_file_name, int match_start_point,
103 int max_return_elements, SearchFilter *searcher,
104 bool &word_complete, lldb_private::StringList &matches);
106 static int Symbols(CommandInterpreter &interpreter,
107 llvm::StringRef partial_file_name, int match_start_point,
108 int max_return_elements, SearchFilter *searcher,
109 bool &word_complete, lldb_private::StringList &matches);
111 static int SettingsNames(CommandInterpreter &interpreter,
112 llvm::StringRef partial_file_name,
113 int match_start_point, int max_return_elements,
114 SearchFilter *searcher, bool &word_complete,
115 lldb_private::StringList &matches);
117 static int PlatformPluginNames(CommandInterpreter &interpreter,
118 llvm::StringRef partial_file_name,
119 int match_start_point, int max_return_elements,
120 SearchFilter *searcher, bool &word_complete,
121 lldb_private::StringList &matches);
123 static int ArchitectureNames(CommandInterpreter &interpreter,
124 llvm::StringRef partial_file_name,
125 int match_start_point, int max_return_elements,
126 SearchFilter *searcher, bool &word_complete,
127 lldb_private::StringList &matches);
129 static int VariablePath(CommandInterpreter &interpreter,
130 llvm::StringRef partial_file_name,
131 int match_start_point, int max_return_elements,
132 SearchFilter *searcher, bool &word_complete,
133 lldb_private::StringList &matches);
135 //----------------------------------------------------------------------
136 // The Completer class is a convenient base class for building searchers
137 // that go along with the SearchFilter passed to the standard Completer
139 //----------------------------------------------------------------------
140 class Completer : public Searcher {
142 Completer(CommandInterpreter &interpreter, llvm::StringRef completion_str,
143 int match_start_point, int max_return_elements,
144 StringList &matches);
146 ~Completer() override;
148 CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
149 Address *addr, bool complete) override = 0;
151 Depth GetDepth() override = 0;
153 virtual size_t DoCompletion(SearchFilter *filter) = 0;
156 CommandInterpreter &m_interpreter;
157 std::string m_completion_str;
158 int m_match_start_point;
159 int m_max_return_elements;
160 StringList &m_matches;
163 DISALLOW_COPY_AND_ASSIGN(Completer);
166 //----------------------------------------------------------------------
167 // SourceFileCompleter implements the source file completer
168 //----------------------------------------------------------------------
169 class SourceFileCompleter : public Completer {
171 SourceFileCompleter(CommandInterpreter &interpreter,
172 bool include_support_files,
173 llvm::StringRef completion_str, int match_start_point,
174 int max_return_elements, StringList &matches);
176 Searcher::Depth GetDepth() override;
178 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
179 SymbolContext &context,
181 bool complete) override;
183 size_t DoCompletion(SearchFilter *filter) override;
186 bool m_include_support_files;
187 FileSpecList m_matching_files;
188 const char *m_file_name;
189 const char *m_dir_name;
191 DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
194 //----------------------------------------------------------------------
195 // ModuleCompleter implements the module completer
196 //----------------------------------------------------------------------
197 class ModuleCompleter : public Completer {
199 ModuleCompleter(CommandInterpreter &interpreter,
200 llvm::StringRef completion_str, int match_start_point,
201 int max_return_elements, StringList &matches);
203 Searcher::Depth GetDepth() override;
205 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
206 SymbolContext &context,
208 bool complete) override;
210 size_t DoCompletion(SearchFilter *filter) override;
213 const char *m_file_name;
214 const char *m_dir_name;
216 DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
219 //----------------------------------------------------------------------
220 // SymbolCompleter implements the symbol completer
221 //----------------------------------------------------------------------
222 class SymbolCompleter : public Completer {
224 SymbolCompleter(CommandInterpreter &interpreter,
225 llvm::StringRef completion_str, int match_start_point,
226 int max_return_elements, StringList &matches);
228 Searcher::Depth GetDepth() override;
230 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
231 SymbolContext &context,
233 bool complete) override;
235 size_t DoCompletion(SearchFilter *filter) override;
239 // bool operator() (const ConstString& lhs, const ConstString&
246 RegularExpression m_regex;
247 typedef std::set<ConstString> collection;
248 collection m_match_set;
250 DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
254 static CommonCompletionElement g_common_completions[];
257 } // namespace lldb_private
259 #endif // lldb_CommandCompletions_h_