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