]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/CommandCompletions.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Interpreter / CommandCompletions.h
1 //===-- CommandCompletions.h ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef lldb_CommandCompletions_h_
11 #define lldb_CommandCompletions_h_
12
13 #include <set>
14
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"
20
21 #include "llvm/ADT/Twine.h"
22
23 namespace lldb_private {
24 class TildeExpressionResolver;
25 class CommandCompletions {
26 public:
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);
36   typedef enum {
37     eNoCompletion = 0u,
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;
52
53   struct CommonCompletionElement {
54     uint32_t type;
55     CompletionCallback callback;
56   };
57
58   static bool InvokeCommonCompletionCallbacks(
59       CommandInterpreter &interpreter, uint32_t completion_mask,
60       lldb_private::CompletionRequest &request, SearchFilter *searcher);
61
62   //----------------------------------------------------------------------
63   // These are the generic completer functions:
64   //----------------------------------------------------------------------
65   static int DiskFiles(CommandInterpreter &interpreter,
66                        CompletionRequest &request, SearchFilter *searcher);
67
68   static int DiskFiles(const llvm::Twine &partial_file_name,
69                        StringList &matches, TildeExpressionResolver &Resolver);
70
71   static int DiskDirectories(CommandInterpreter &interpreter,
72                              CompletionRequest &request,
73                              SearchFilter *searcher);
74
75   static int DiskDirectories(const llvm::Twine &partial_file_name,
76                              StringList &matches,
77                              TildeExpressionResolver &Resolver);
78
79   static int SourceFiles(CommandInterpreter &interpreter,
80                          CompletionRequest &request, SearchFilter *searcher);
81
82   static int Modules(CommandInterpreter &interpreter,
83                      CompletionRequest &request, SearchFilter *searcher);
84
85   static int Symbols(CommandInterpreter &interpreter,
86                      CompletionRequest &request, SearchFilter *searcher);
87
88   static int SettingsNames(CommandInterpreter &interpreter,
89                            CompletionRequest &request, SearchFilter *searcher);
90
91   static int PlatformPluginNames(CommandInterpreter &interpreter,
92                                  CompletionRequest &request,
93                                  SearchFilter *searcher);
94
95   static int ArchitectureNames(CommandInterpreter &interpreter,
96                                CompletionRequest &request,
97                                SearchFilter *searcher);
98
99   static int VariablePath(CommandInterpreter &interpreter,
100                           CompletionRequest &request, SearchFilter *searcher);
101
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 {
107   public:
108     Completer(CommandInterpreter &interpreter, CompletionRequest &request);
109
110     ~Completer() override;
111
112     CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
113                                   Address *addr, bool complete) override = 0;
114
115     lldb::SearchDepth GetDepth() override = 0;
116
117     virtual size_t DoCompletion(SearchFilter *filter) = 0;
118
119   protected:
120     CommandInterpreter &m_interpreter;
121     CompletionRequest &m_request;
122
123   private:
124     DISALLOW_COPY_AND_ASSIGN(Completer);
125   };
126
127   //----------------------------------------------------------------------
128   // SourceFileCompleter implements the source file completer
129   //----------------------------------------------------------------------
130   class SourceFileCompleter : public Completer {
131   public:
132     SourceFileCompleter(CommandInterpreter &interpreter,
133                         bool include_support_files, CompletionRequest &request);
134
135     lldb::SearchDepth GetDepth() override;
136
137     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
138                                             SymbolContext &context,
139                                             Address *addr,
140                                             bool complete) override;
141
142     size_t DoCompletion(SearchFilter *filter) override;
143
144   private:
145     bool m_include_support_files;
146     FileSpecList m_matching_files;
147     const char *m_file_name;
148     const char *m_dir_name;
149
150     DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
151   };
152
153   //----------------------------------------------------------------------
154   // ModuleCompleter implements the module completer
155   //----------------------------------------------------------------------
156   class ModuleCompleter : public Completer {
157   public:
158     ModuleCompleter(CommandInterpreter &interpreter,
159                     CompletionRequest &request);
160
161     lldb::SearchDepth GetDepth() override;
162
163     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
164                                             SymbolContext &context,
165                                             Address *addr,
166                                             bool complete) override;
167
168     size_t DoCompletion(SearchFilter *filter) override;
169
170   private:
171     const char *m_file_name;
172     const char *m_dir_name;
173
174     DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
175   };
176
177   //----------------------------------------------------------------------
178   // SymbolCompleter implements the symbol completer
179   //----------------------------------------------------------------------
180   class SymbolCompleter : public Completer {
181   public:
182     SymbolCompleter(CommandInterpreter &interpreter,
183                     CompletionRequest &request);
184
185     lldb::SearchDepth GetDepth() override;
186
187     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
188                                             SymbolContext &context,
189                                             Address *addr,
190                                             bool complete) override;
191
192     size_t DoCompletion(SearchFilter *filter) override;
193
194   private:
195     //        struct NameCmp {
196     //            bool operator() (const ConstString& lhs, const ConstString&
197     //            rhs) const
198     //            {
199     //                return lhs < rhs;
200     //            }
201     //        };
202
203     RegularExpression m_regex;
204     typedef std::set<ConstString> collection;
205     collection m_match_set;
206
207     DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
208   };
209
210 private:
211   static CommonCompletionElement g_common_completions[];
212 };
213
214 } // namespace lldb_private
215
216 #endif // lldb_CommandCompletions_h_