]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/CommandCompletions.h
Merge clang 7.0.1 and several follow-up changes
[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 // C Includes
14 // C++ Includes
15 #include <set>
16
17 // Other libraries and framework includes
18 // Project 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"
24
25 #include "llvm/ADT/Twine.h"
26
27 namespace lldb_private {
28 class TildeExpressionResolver;
29 class CommandCompletions {
30 public:
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);
40   typedef enum {
41     eNoCompletion = 0u,
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;
56
57   struct CommonCompletionElement {
58     uint32_t type;
59     CompletionCallback callback;
60   };
61
62   static bool InvokeCommonCompletionCallbacks(
63       CommandInterpreter &interpreter, uint32_t completion_mask,
64       lldb_private::CompletionRequest &request, SearchFilter *searcher);
65
66   //----------------------------------------------------------------------
67   // These are the generic completer functions:
68   //----------------------------------------------------------------------
69   static int DiskFiles(CommandInterpreter &interpreter,
70                        CompletionRequest &request, SearchFilter *searcher);
71
72   static int DiskFiles(const llvm::Twine &partial_file_name,
73                        StringList &matches, TildeExpressionResolver &Resolver);
74
75   static int DiskDirectories(CommandInterpreter &interpreter,
76                              CompletionRequest &request,
77                              SearchFilter *searcher);
78
79   static int DiskDirectories(const llvm::Twine &partial_file_name,
80                              StringList &matches,
81                              TildeExpressionResolver &Resolver);
82
83   static int SourceFiles(CommandInterpreter &interpreter,
84                          CompletionRequest &request, SearchFilter *searcher);
85
86   static int Modules(CommandInterpreter &interpreter,
87                      CompletionRequest &request, SearchFilter *searcher);
88
89   static int Symbols(CommandInterpreter &interpreter,
90                      CompletionRequest &request, SearchFilter *searcher);
91
92   static int SettingsNames(CommandInterpreter &interpreter,
93                            CompletionRequest &request, SearchFilter *searcher);
94
95   static int PlatformPluginNames(CommandInterpreter &interpreter,
96                                  CompletionRequest &request,
97                                  SearchFilter *searcher);
98
99   static int ArchitectureNames(CommandInterpreter &interpreter,
100                                CompletionRequest &request,
101                                SearchFilter *searcher);
102
103   static int VariablePath(CommandInterpreter &interpreter,
104                           CompletionRequest &request, SearchFilter *searcher);
105
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 {
111   public:
112     Completer(CommandInterpreter &interpreter, CompletionRequest &request);
113
114     ~Completer() override;
115
116     CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
117                                   Address *addr, bool complete) override = 0;
118
119     Depth GetDepth() override = 0;
120
121     virtual size_t DoCompletion(SearchFilter *filter) = 0;
122
123   protected:
124     CommandInterpreter &m_interpreter;
125     CompletionRequest &m_request;
126
127   private:
128     DISALLOW_COPY_AND_ASSIGN(Completer);
129   };
130
131   //----------------------------------------------------------------------
132   // SourceFileCompleter implements the source file completer
133   //----------------------------------------------------------------------
134   class SourceFileCompleter : public Completer {
135   public:
136     SourceFileCompleter(CommandInterpreter &interpreter,
137                         bool include_support_files, CompletionRequest &request);
138
139     Searcher::Depth GetDepth() override;
140
141     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
142                                             SymbolContext &context,
143                                             Address *addr,
144                                             bool complete) override;
145
146     size_t DoCompletion(SearchFilter *filter) override;
147
148   private:
149     bool m_include_support_files;
150     FileSpecList m_matching_files;
151     const char *m_file_name;
152     const char *m_dir_name;
153
154     DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
155   };
156
157   //----------------------------------------------------------------------
158   // ModuleCompleter implements the module completer
159   //----------------------------------------------------------------------
160   class ModuleCompleter : public Completer {
161   public:
162     ModuleCompleter(CommandInterpreter &interpreter,
163                     CompletionRequest &request);
164
165     Searcher::Depth GetDepth() override;
166
167     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
168                                             SymbolContext &context,
169                                             Address *addr,
170                                             bool complete) override;
171
172     size_t DoCompletion(SearchFilter *filter) override;
173
174   private:
175     const char *m_file_name;
176     const char *m_dir_name;
177
178     DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
179   };
180
181   //----------------------------------------------------------------------
182   // SymbolCompleter implements the symbol completer
183   //----------------------------------------------------------------------
184   class SymbolCompleter : public Completer {
185   public:
186     SymbolCompleter(CommandInterpreter &interpreter,
187                     CompletionRequest &request);
188
189     Searcher::Depth GetDepth() override;
190
191     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
192                                             SymbolContext &context,
193                                             Address *addr,
194                                             bool complete) override;
195
196     size_t DoCompletion(SearchFilter *filter) override;
197
198   private:
199     //        struct NameCmp {
200     //            bool operator() (const ConstString& lhs, const ConstString&
201     //            rhs) const
202     //            {
203     //                return lhs < rhs;
204     //            }
205     //        };
206
207     RegularExpression m_regex;
208     typedef std::set<ConstString> collection;
209     collection m_match_set;
210
211     DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
212   };
213
214 private:
215   static CommonCompletionElement g_common_completions[];
216 };
217
218 } // namespace lldb_private
219
220 #endif // lldb_CommandCompletions_h_