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