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_
15 #include "lldb/Core/FileSpecList.h"
16 #include "lldb/Core/SearchFilter.h"
17 #include "lldb/Utility/CompletionRequest.h"
18 #include "lldb/Utility/RegularExpression.h"
19 #include "lldb/lldb-private.h"
21 #include "llvm/ADT/Twine.h"
23 namespace lldb_private {
24 class TildeExpressionResolver;
25 class CommandCompletions {
27 //----------------------------------------------------------------------
28 // This is the command completion callback that is used to complete the
29 // argument of the option it is bound to (in the OptionDefinition table
30 // below). Return the total number of matches.
31 //----------------------------------------------------------------------
32 typedef int (*CompletionCallback)(CommandInterpreter &interpreter,
33 CompletionRequest &request,
34 // A search filter to limit the search...
35 lldb_private::SearchFilter *searcher);
38 eSourceFileCompletion = (1u << 0),
39 eDiskFileCompletion = (1u << 1),
40 eDiskDirectoryCompletion = (1u << 2),
41 eSymbolCompletion = (1u << 3),
42 eModuleCompletion = (1u << 4),
43 eSettingsNameCompletion = (1u << 5),
44 ePlatformPluginCompletion = (1u << 6),
45 eArchitectureCompletion = (1u << 7),
46 eVariablePathCompletion = (1u << 8),
47 // This item serves two purposes. It is the last element in the enum, so
48 // you can add custom enums starting from here in your Option class. Also
49 // if you & in this bit the base code will not process the option.
50 eCustomCompletion = (1u << 9)
51 } CommonCompletionTypes;
53 struct CommonCompletionElement {
55 CompletionCallback callback;
58 static bool InvokeCommonCompletionCallbacks(
59 CommandInterpreter &interpreter, uint32_t completion_mask,
60 lldb_private::CompletionRequest &request, SearchFilter *searcher);
62 //----------------------------------------------------------------------
63 // These are the generic completer functions:
64 //----------------------------------------------------------------------
65 static int DiskFiles(CommandInterpreter &interpreter,
66 CompletionRequest &request, SearchFilter *searcher);
68 static int DiskFiles(const llvm::Twine &partial_file_name,
69 StringList &matches, TildeExpressionResolver &Resolver);
71 static int DiskDirectories(CommandInterpreter &interpreter,
72 CompletionRequest &request,
73 SearchFilter *searcher);
75 static int DiskDirectories(const llvm::Twine &partial_file_name,
77 TildeExpressionResolver &Resolver);
79 static int SourceFiles(CommandInterpreter &interpreter,
80 CompletionRequest &request, SearchFilter *searcher);
82 static int Modules(CommandInterpreter &interpreter,
83 CompletionRequest &request, SearchFilter *searcher);
85 static int Symbols(CommandInterpreter &interpreter,
86 CompletionRequest &request, SearchFilter *searcher);
88 static int SettingsNames(CommandInterpreter &interpreter,
89 CompletionRequest &request, SearchFilter *searcher);
91 static int PlatformPluginNames(CommandInterpreter &interpreter,
92 CompletionRequest &request,
93 SearchFilter *searcher);
95 static int ArchitectureNames(CommandInterpreter &interpreter,
96 CompletionRequest &request,
97 SearchFilter *searcher);
99 static int VariablePath(CommandInterpreter &interpreter,
100 CompletionRequest &request, SearchFilter *searcher);
102 //----------------------------------------------------------------------
103 // The Completer class is a convenient base class for building searchers that
104 // go along with the SearchFilter passed to the standard Completer functions.
105 //----------------------------------------------------------------------
106 class Completer : public Searcher {
108 Completer(CommandInterpreter &interpreter, CompletionRequest &request);
110 ~Completer() override;
112 CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
113 Address *addr, bool complete) override = 0;
115 lldb::SearchDepth GetDepth() override = 0;
117 virtual size_t DoCompletion(SearchFilter *filter) = 0;
120 CommandInterpreter &m_interpreter;
121 CompletionRequest &m_request;
124 DISALLOW_COPY_AND_ASSIGN(Completer);
127 //----------------------------------------------------------------------
128 // SourceFileCompleter implements the source file completer
129 //----------------------------------------------------------------------
130 class SourceFileCompleter : public Completer {
132 SourceFileCompleter(CommandInterpreter &interpreter,
133 bool include_support_files, CompletionRequest &request);
135 lldb::SearchDepth GetDepth() override;
137 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
138 SymbolContext &context,
140 bool complete) override;
142 size_t DoCompletion(SearchFilter *filter) override;
145 bool m_include_support_files;
146 FileSpecList m_matching_files;
147 const char *m_file_name;
148 const char *m_dir_name;
150 DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
153 //----------------------------------------------------------------------
154 // ModuleCompleter implements the module completer
155 //----------------------------------------------------------------------
156 class ModuleCompleter : public Completer {
158 ModuleCompleter(CommandInterpreter &interpreter,
159 CompletionRequest &request);
161 lldb::SearchDepth GetDepth() override;
163 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
164 SymbolContext &context,
166 bool complete) override;
168 size_t DoCompletion(SearchFilter *filter) override;
171 const char *m_file_name;
172 const char *m_dir_name;
174 DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
177 //----------------------------------------------------------------------
178 // SymbolCompleter implements the symbol completer
179 //----------------------------------------------------------------------
180 class SymbolCompleter : public Completer {
182 SymbolCompleter(CommandInterpreter &interpreter,
183 CompletionRequest &request);
185 lldb::SearchDepth GetDepth() override;
187 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
188 SymbolContext &context,
190 bool complete) override;
192 size_t DoCompletion(SearchFilter *filter) override;
196 // bool operator() (const ConstString& lhs, const ConstString&
203 RegularExpression m_regex;
204 typedef std::set<ConstString> collection;
205 collection m_match_set;
207 DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
211 static CommonCompletionElement g_common_completions[];
214 } // namespace lldb_private
216 #endif // lldb_CommandCompletions_h_