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/CompletionRequest.h"
22 #include "lldb/Utility/RegularExpression.h"
23 #include "lldb/lldb-private.h"
25 #include "llvm/ADT/Twine.h"
27 namespace lldb_private {
28 class TildeExpressionResolver;
29 class CommandCompletions {
31 //----------------------------------------------------------------------
32 // This is the command completion callback that is used to complete the
33 // argument of the option it is bound to (in the OptionDefinition table
34 // below). Return the total number of matches.
35 //----------------------------------------------------------------------
36 typedef int (*CompletionCallback)(CommandInterpreter &interpreter,
37 CompletionRequest &request,
38 // A search filter to limit the search...
39 lldb_private::SearchFilter *searcher);
42 eSourceFileCompletion = (1u << 0),
43 eDiskFileCompletion = (1u << 1),
44 eDiskDirectoryCompletion = (1u << 2),
45 eSymbolCompletion = (1u << 3),
46 eModuleCompletion = (1u << 4),
47 eSettingsNameCompletion = (1u << 5),
48 ePlatformPluginCompletion = (1u << 6),
49 eArchitectureCompletion = (1u << 7),
50 eVariablePathCompletion = (1u << 8),
51 // This item serves two purposes. It is the last element in the enum, so
52 // you can add custom enums starting from here in your Option class. Also
53 // if you & in this bit the base code will not process the option.
54 eCustomCompletion = (1u << 9)
55 } CommonCompletionTypes;
57 struct CommonCompletionElement {
59 CompletionCallback callback;
62 static bool InvokeCommonCompletionCallbacks(
63 CommandInterpreter &interpreter, uint32_t completion_mask,
64 lldb_private::CompletionRequest &request, SearchFilter *searcher);
66 //----------------------------------------------------------------------
67 // These are the generic completer functions:
68 //----------------------------------------------------------------------
69 static int DiskFiles(CommandInterpreter &interpreter,
70 CompletionRequest &request, SearchFilter *searcher);
72 static int DiskFiles(const llvm::Twine &partial_file_name,
73 StringList &matches, TildeExpressionResolver &Resolver);
75 static int DiskDirectories(CommandInterpreter &interpreter,
76 CompletionRequest &request,
77 SearchFilter *searcher);
79 static int DiskDirectories(const llvm::Twine &partial_file_name,
81 TildeExpressionResolver &Resolver);
83 static int SourceFiles(CommandInterpreter &interpreter,
84 CompletionRequest &request, SearchFilter *searcher);
86 static int Modules(CommandInterpreter &interpreter,
87 CompletionRequest &request, SearchFilter *searcher);
89 static int Symbols(CommandInterpreter &interpreter,
90 CompletionRequest &request, SearchFilter *searcher);
92 static int SettingsNames(CommandInterpreter &interpreter,
93 CompletionRequest &request, SearchFilter *searcher);
95 static int PlatformPluginNames(CommandInterpreter &interpreter,
96 CompletionRequest &request,
97 SearchFilter *searcher);
99 static int ArchitectureNames(CommandInterpreter &interpreter,
100 CompletionRequest &request,
101 SearchFilter *searcher);
103 static int VariablePath(CommandInterpreter &interpreter,
104 CompletionRequest &request, SearchFilter *searcher);
106 //----------------------------------------------------------------------
107 // The Completer class is a convenient base class for building searchers that
108 // go along with the SearchFilter passed to the standard Completer functions.
109 //----------------------------------------------------------------------
110 class Completer : public Searcher {
112 Completer(CommandInterpreter &interpreter, CompletionRequest &request);
114 ~Completer() override;
116 CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
117 Address *addr, bool complete) override = 0;
119 Depth GetDepth() override = 0;
121 virtual size_t DoCompletion(SearchFilter *filter) = 0;
124 CommandInterpreter &m_interpreter;
125 CompletionRequest &m_request;
128 DISALLOW_COPY_AND_ASSIGN(Completer);
131 //----------------------------------------------------------------------
132 // SourceFileCompleter implements the source file completer
133 //----------------------------------------------------------------------
134 class SourceFileCompleter : public Completer {
136 SourceFileCompleter(CommandInterpreter &interpreter,
137 bool include_support_files, CompletionRequest &request);
139 Searcher::Depth GetDepth() override;
141 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
142 SymbolContext &context,
144 bool complete) override;
146 size_t DoCompletion(SearchFilter *filter) override;
149 bool m_include_support_files;
150 FileSpecList m_matching_files;
151 const char *m_file_name;
152 const char *m_dir_name;
154 DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
157 //----------------------------------------------------------------------
158 // ModuleCompleter implements the module completer
159 //----------------------------------------------------------------------
160 class ModuleCompleter : public Completer {
162 ModuleCompleter(CommandInterpreter &interpreter,
163 CompletionRequest &request);
165 Searcher::Depth GetDepth() override;
167 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
168 SymbolContext &context,
170 bool complete) override;
172 size_t DoCompletion(SearchFilter *filter) override;
175 const char *m_file_name;
176 const char *m_dir_name;
178 DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
181 //----------------------------------------------------------------------
182 // SymbolCompleter implements the symbol completer
183 //----------------------------------------------------------------------
184 class SymbolCompleter : public Completer {
186 SymbolCompleter(CommandInterpreter &interpreter,
187 CompletionRequest &request);
189 Searcher::Depth GetDepth() override;
191 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
192 SymbolContext &context,
194 bool complete) override;
196 size_t DoCompletion(SearchFilter *filter) override;
200 // bool operator() (const ConstString& lhs, const ConstString&
207 RegularExpression m_regex;
208 typedef std::set<ConstString> collection;
209 collection m_match_set;
211 DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
215 static CommonCompletionElement g_common_completions[];
218 } // namespace lldb_private
220 #endif // lldb_CommandCompletions_h_