]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/CommandCompletions.h
Merge compiler-rt trunk r321017 to contrib/compiler-rt.
[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/RegularExpression.h"
22 #include "lldb/lldb-private.h"
23
24 #include "llvm/ADT/Twine.h"
25
26 namespace lldb_private {
27 class TildeExpressionResolver;
28 class CommandCompletions {
29 public:
30   //----------------------------------------------------------------------
31   // This is the command completion callback that is used to complete the
32   // argument of the option
33   // it is bound to (in the OptionDefinition table below).  Return the total
34   // number of matches.
35   //----------------------------------------------------------------------
36   typedef int (*CompletionCallback)(
37       CommandInterpreter &interpreter,
38       llvm::StringRef completion_str, // This is the argument we are completing
39       int match_start_point,   // This is the point in the list of matches that
40                                // you should start returning elements
41       int max_return_elements, // This is the number of matches requested.
42       lldb_private::SearchFilter
43           *searcher, // A search filter to limit the search...
44       bool &word_complete,
45       lldb_private::StringList &matches); // The array of matches we return.
46   typedef enum {
47     eNoCompletion = 0u,
48     eSourceFileCompletion = (1u << 0),
49     eDiskFileCompletion = (1u << 1),
50     eDiskDirectoryCompletion = (1u << 2),
51     eSymbolCompletion = (1u << 3),
52     eModuleCompletion = (1u << 4),
53     eSettingsNameCompletion = (1u << 5),
54     ePlatformPluginCompletion = (1u << 6),
55     eArchitectureCompletion = (1u << 7),
56     eVariablePathCompletion = (1u << 8),
57     // This item serves two purposes.  It is the last element in the enum,
58     // so you can add custom enums starting from here in your Option class.
59     // Also if you & in this bit the base code will not process the option.
60     eCustomCompletion = (1u << 9)
61   } CommonCompletionTypes;
62
63   struct CommonCompletionElement {
64     uint32_t type;
65     CompletionCallback callback;
66   };
67
68   static bool InvokeCommonCompletionCallbacks(
69       CommandInterpreter &interpreter, uint32_t completion_mask,
70       llvm::StringRef completion_str, int match_start_point,
71       int max_return_elements, SearchFilter *searcher, bool &word_complete,
72       StringList &matches);
73
74   //----------------------------------------------------------------------
75   // These are the generic completer functions:
76   //----------------------------------------------------------------------
77   static int DiskFiles(CommandInterpreter &interpreter,
78                        llvm::StringRef partial_file_name, int match_start_point,
79                        int max_return_elements, SearchFilter *searcher,
80                        bool &word_complete, StringList &matches);
81
82   static int DiskFiles(const llvm::Twine &partial_file_name,
83                        StringList &matches, TildeExpressionResolver &Resolver);
84
85   static int DiskDirectories(CommandInterpreter &interpreter,
86                              llvm::StringRef partial_file_name,
87                              int match_start_point, int max_return_elements,
88                              SearchFilter *searcher, bool &word_complete,
89                              StringList &matches);
90
91   static int DiskDirectories(const llvm::Twine &partial_file_name,
92                              StringList &matches,
93                              TildeExpressionResolver &Resolver);
94
95   static int SourceFiles(CommandInterpreter &interpreter,
96                          llvm::StringRef partial_file_name,
97                          int match_start_point, int max_return_elements,
98                          SearchFilter *searcher, bool &word_complete,
99                          StringList &matches);
100
101   static int Modules(CommandInterpreter &interpreter,
102                      llvm::StringRef partial_file_name, int match_start_point,
103                      int max_return_elements, SearchFilter *searcher,
104                      bool &word_complete, lldb_private::StringList &matches);
105
106   static int Symbols(CommandInterpreter &interpreter,
107                      llvm::StringRef partial_file_name, int match_start_point,
108                      int max_return_elements, SearchFilter *searcher,
109                      bool &word_complete, lldb_private::StringList &matches);
110
111   static int SettingsNames(CommandInterpreter &interpreter,
112                            llvm::StringRef partial_file_name,
113                            int match_start_point, int max_return_elements,
114                            SearchFilter *searcher, bool &word_complete,
115                            lldb_private::StringList &matches);
116
117   static int PlatformPluginNames(CommandInterpreter &interpreter,
118                                  llvm::StringRef partial_file_name,
119                                  int match_start_point, int max_return_elements,
120                                  SearchFilter *searcher, bool &word_complete,
121                                  lldb_private::StringList &matches);
122
123   static int ArchitectureNames(CommandInterpreter &interpreter,
124                                llvm::StringRef partial_file_name,
125                                int match_start_point, int max_return_elements,
126                                SearchFilter *searcher, bool &word_complete,
127                                lldb_private::StringList &matches);
128
129   static int VariablePath(CommandInterpreter &interpreter,
130                           llvm::StringRef partial_file_name,
131                           int match_start_point, int max_return_elements,
132                           SearchFilter *searcher, bool &word_complete,
133                           lldb_private::StringList &matches);
134
135   //----------------------------------------------------------------------
136   // The Completer class is a convenient base class for building searchers
137   // that go along with the SearchFilter passed to the standard Completer
138   // functions.
139   //----------------------------------------------------------------------
140   class Completer : public Searcher {
141   public:
142     Completer(CommandInterpreter &interpreter, llvm::StringRef completion_str,
143               int match_start_point, int max_return_elements,
144               StringList &matches);
145
146     ~Completer() override;
147
148     CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context,
149                                   Address *addr, bool complete) override = 0;
150
151     Depth GetDepth() override = 0;
152
153     virtual size_t DoCompletion(SearchFilter *filter) = 0;
154
155   protected:
156     CommandInterpreter &m_interpreter;
157     std::string m_completion_str;
158     int m_match_start_point;
159     int m_max_return_elements;
160     StringList &m_matches;
161
162   private:
163     DISALLOW_COPY_AND_ASSIGN(Completer);
164   };
165
166   //----------------------------------------------------------------------
167   // SourceFileCompleter implements the source file completer
168   //----------------------------------------------------------------------
169   class SourceFileCompleter : public Completer {
170   public:
171     SourceFileCompleter(CommandInterpreter &interpreter,
172                         bool include_support_files,
173                         llvm::StringRef completion_str, int match_start_point,
174                         int max_return_elements, StringList &matches);
175
176     Searcher::Depth GetDepth() override;
177
178     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
179                                             SymbolContext &context,
180                                             Address *addr,
181                                             bool complete) override;
182
183     size_t DoCompletion(SearchFilter *filter) override;
184
185   private:
186     bool m_include_support_files;
187     FileSpecList m_matching_files;
188     const char *m_file_name;
189     const char *m_dir_name;
190
191     DISALLOW_COPY_AND_ASSIGN(SourceFileCompleter);
192   };
193
194   //----------------------------------------------------------------------
195   // ModuleCompleter implements the module completer
196   //----------------------------------------------------------------------
197   class ModuleCompleter : public Completer {
198   public:
199     ModuleCompleter(CommandInterpreter &interpreter,
200                     llvm::StringRef completion_str, int match_start_point,
201                     int max_return_elements, StringList &matches);
202
203     Searcher::Depth GetDepth() override;
204
205     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
206                                             SymbolContext &context,
207                                             Address *addr,
208                                             bool complete) override;
209
210     size_t DoCompletion(SearchFilter *filter) override;
211
212   private:
213     const char *m_file_name;
214     const char *m_dir_name;
215
216     DISALLOW_COPY_AND_ASSIGN(ModuleCompleter);
217   };
218
219   //----------------------------------------------------------------------
220   // SymbolCompleter implements the symbol completer
221   //----------------------------------------------------------------------
222   class SymbolCompleter : public Completer {
223   public:
224     SymbolCompleter(CommandInterpreter &interpreter,
225                     llvm::StringRef completion_str, int match_start_point,
226                     int max_return_elements, StringList &matches);
227
228     Searcher::Depth GetDepth() override;
229
230     Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
231                                             SymbolContext &context,
232                                             Address *addr,
233                                             bool complete) override;
234
235     size_t DoCompletion(SearchFilter *filter) override;
236
237   private:
238     //        struct NameCmp {
239     //            bool operator() (const ConstString& lhs, const ConstString&
240     //            rhs) const
241     //            {
242     //                return lhs < rhs;
243     //            }
244     //        };
245
246     RegularExpression m_regex;
247     typedef std::set<ConstString> collection;
248     collection m_match_set;
249
250     DISALLOW_COPY_AND_ASSIGN(SymbolCompleter);
251   };
252
253 private:
254   static CommonCompletionElement g_common_completions[];
255 };
256
257 } // namespace lldb_private
258
259 #endif // lldb_CommandCompletions_h_