1 //===-- CommandCompletions.h ------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef lldb_CommandCompletions_h_
10 #define lldb_CommandCompletions_h_
14 #include "lldb/Core/FileSpecList.h"
15 #include "lldb/Core/SearchFilter.h"
16 #include "lldb/Utility/CompletionRequest.h"
17 #include "lldb/Utility/RegularExpression.h"
18 #include "lldb/lldb-private.h"
20 #include "llvm/ADT/Twine.h"
22 namespace lldb_private {
23 class TildeExpressionResolver;
24 class CommandCompletions {
26 // This is the command completion callback that is used to complete the
27 // argument of the option it is bound to (in the OptionDefinition table
28 // below). Return the total number of matches.
29 typedef int (*CompletionCallback)(CommandInterpreter &interpreter,
30 CompletionRequest &request,
31 // A search filter to limit the search...
32 lldb_private::SearchFilter *searcher);
33 enum CommonCompletionTypes {
35 eSourceFileCompletion = (1u << 0),
36 eDiskFileCompletion = (1u << 1),
37 eDiskDirectoryCompletion = (1u << 2),
38 eSymbolCompletion = (1u << 3),
39 eModuleCompletion = (1u << 4),
40 eSettingsNameCompletion = (1u << 5),
41 ePlatformPluginCompletion = (1u << 6),
42 eArchitectureCompletion = (1u << 7),
43 eVariablePathCompletion = (1u << 8),
44 // This item serves two purposes. It is the last element in the enum, so
45 // you can add custom enums starting from here in your Option class. Also
46 // if you & in this bit the base code will not process the option.
47 eCustomCompletion = (1u << 9)
50 struct CommonCompletionElement {
52 CompletionCallback callback;
55 static bool InvokeCommonCompletionCallbacks(
56 CommandInterpreter &interpreter, uint32_t completion_mask,
57 lldb_private::CompletionRequest &request, SearchFilter *searcher);
59 // These are the generic completer functions:
60 static int DiskFiles(CommandInterpreter &interpreter,
61 CompletionRequest &request, SearchFilter *searcher);
63 static int DiskFiles(const llvm::Twine &partial_file_name,
64 StringList &matches, TildeExpressionResolver &Resolver);
66 static int DiskDirectories(CommandInterpreter &interpreter,
67 CompletionRequest &request,
68 SearchFilter *searcher);
70 static int DiskDirectories(const llvm::Twine &partial_file_name,
72 TildeExpressionResolver &Resolver);
74 static int SourceFiles(CommandInterpreter &interpreter,
75 CompletionRequest &request, SearchFilter *searcher);
77 static int Modules(CommandInterpreter &interpreter,
78 CompletionRequest &request, SearchFilter *searcher);
80 static int Symbols(CommandInterpreter &interpreter,
81 CompletionRequest &request, SearchFilter *searcher);
83 static int SettingsNames(CommandInterpreter &interpreter,
84 CompletionRequest &request, SearchFilter *searcher);
86 static int PlatformPluginNames(CommandInterpreter &interpreter,
87 CompletionRequest &request,
88 SearchFilter *searcher);
90 static int ArchitectureNames(CommandInterpreter &interpreter,
91 CompletionRequest &request,
92 SearchFilter *searcher);
94 static int VariablePath(CommandInterpreter &interpreter,
95 CompletionRequest &request, SearchFilter *searcher);
97 // The Completer class is a convenient base class for building searchers that
98 // go along with the SearchFilter passed to the standard Completer functions.
99 class Completer : public Searcher {
101 Completer(CommandInterpreter &interpreter, CompletionRequest &request);
103 ~Completer() override;
105 CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
106 Address *addr, bool complete) override = 0;
108 lldb::SearchDepth GetDepth() override = 0;
110 virtual size_t DoCompletion(SearchFilter *filter) = 0;
113 CommandInterpreter &m_interpreter;
114 CompletionRequest &m_request;
117 DISALLOW_COPY_AND_ASSIGN(Completer);
120 // SourceFileCompleter implements the source file completer
121 class SourceFileCompleter : public Completer {
123 SourceFileCompleter(CommandInterpreter &interpreter,
124 bool include_support_files, CompletionRequest &request);
126 lldb::SearchDepth GetDepth() override;
128 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
129 SymbolContext &context,
131 bool complete) override;
133 size_t DoCompletion(SearchFilter *filter) override;
136 bool m_include_support_files;
137 FileSpecList m_matching_files;
138 const char *m_file_name;
139 const char *m_dir_name;
141 DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
144 // ModuleCompleter implements the module completer
145 class ModuleCompleter : public Completer {
147 ModuleCompleter(CommandInterpreter &interpreter,
148 CompletionRequest &request);
150 lldb::SearchDepth GetDepth() override;
152 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
153 SymbolContext &context,
155 bool complete) override;
157 size_t DoCompletion(SearchFilter *filter) override;
160 const char *m_file_name;
161 const char *m_dir_name;
163 DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
166 // SymbolCompleter implements the symbol completer
167 class SymbolCompleter : public Completer {
169 SymbolCompleter(CommandInterpreter &interpreter,
170 CompletionRequest &request);
172 lldb::SearchDepth GetDepth() override;
174 Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
175 SymbolContext &context,
177 bool complete) override;
179 size_t DoCompletion(SearchFilter *filter) override;
183 // bool operator() (const ConstString& lhs, const ConstString&
190 RegularExpression m_regex;
191 typedef std::set<ConstString> collection;
192 collection m_match_set;
194 DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
198 static CommonCompletionElement g_common_completions[];
201 } // namespace lldb_private
203 #endif // lldb_CommandCompletions_h_