aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Interpreter/CommandCompletions.h
blob: c4ab1b61adebf13d7e321d7f6fd2f1b85bf6f958 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//===-- CommandCompletions.h ------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef lldb_CommandCompletions_h_
#define lldb_CommandCompletions_h_

// C Includes
// C++ Includes
#include <set>

// Other libraries and framework includes
// Project includes
#include "lldb/lldb-private.h"
#include "lldb/Core/SearchFilter.h"
#include "lldb/Core/FileSpecList.h"
#include "lldb/Core/RegularExpression.h"

namespace lldb_private
{
class CommandCompletions
{
public:

    //----------------------------------------------------------------------
    // This is the command completion callback that is used to complete the argument of the option
    // it is bound to (in the OptionDefinition table below).  Return the total number of matches.
    //----------------------------------------------------------------------
    typedef int (*CompletionCallback) (CommandInterpreter &interpreter,
                                       const char *completion_str,          // This is the argument we are completing
                                       int match_start_point,               // This is the point in the list of matches that you should start returning elements
                                       int max_return_elements,             // This is the number of matches requested.
                                       lldb_private::SearchFilter *searcher,// A search filter to limit the search...
                                       bool &word_complete,
                                       lldb_private::StringList &matches);  // The array of matches we return.
    typedef enum
    {
        eNoCompletion             = 0u,
        eSourceFileCompletion     = (1u << 0),
        eDiskFileCompletion       = (1u << 1),
        eDiskDirectoryCompletion  = (1u << 2),
        eSymbolCompletion         = (1u << 3),
        eModuleCompletion         = (1u << 4),
        eSettingsNameCompletion   = (1u << 5),
        ePlatformPluginCompletion = (1u << 6),
        eArchitectureCompletion   = (1u << 7),
        eVariablePathCompletion   = (1u << 8),
        // This item serves two purposes.  It is the last element in the enum,
        // so you can add custom enums starting from here in your Option class.
        // Also if you & in this bit the base code will not process the option.
        eCustomCompletion         = (1u << 9)

    } CommonCompletionTypes;

    struct CommonCompletionElement
    {
        uint32_t type;
        CompletionCallback callback;
    };

    static bool InvokeCommonCompletionCallbacks (CommandInterpreter &interpreter,
                                                 uint32_t completion_mask,
                                                 const char *completion_str,
                                                 int match_start_point,
                                                 int max_return_elements,
                                                 SearchFilter *searcher,
                                                 bool &word_complete,
                                                 StringList &matches);
    
    //----------------------------------------------------------------------
    // These are the generic completer functions:
    //----------------------------------------------------------------------
    static int
    DiskFiles (CommandInterpreter &interpreter,
               const char *partial_file_name,
               int match_start_point,
               int max_return_elements,
               SearchFilter *searcher,
               bool &word_complete,
               StringList &matches);
    static int
    DiskDirectories (CommandInterpreter &interpreter,
                     const char *partial_file_name,
                     int match_start_point,
                     int max_return_elements,
                     SearchFilter *searcher,
                     bool &word_complete,
                     StringList &matches);
    
    static int
    SourceFiles (CommandInterpreter &interpreter,
                 const char *partial_file_name,
                 int match_start_point,
                 int max_return_elements,
                 SearchFilter *searcher,
                 bool &word_complete,
                 StringList &matches);
    
    static int
    Modules (CommandInterpreter &interpreter,
             const char *partial_file_name,
             int match_start_point,
             int max_return_elements,
             SearchFilter *searcher,
             bool &word_complete,
             lldb_private::StringList &matches);
    
    static int
    Symbols (CommandInterpreter &interpreter,
             const char *partial_file_name,
             int match_start_point,
             int max_return_elements,
             SearchFilter *searcher,
             bool &word_complete,
             lldb_private::StringList &matches);
    
    static int
    SettingsNames (CommandInterpreter &interpreter,
                   const char *partial_file_name,
                   int match_start_point,
                   int max_return_elements,
                   SearchFilter *searcher,
                   bool &word_complete,
                   lldb_private::StringList &matches);

    static int
    PlatformPluginNames (CommandInterpreter &interpreter,
                         const char *partial_file_name,
                         int match_start_point,
                         int max_return_elements,
                         SearchFilter *searcher,
                         bool &word_complete,
                         lldb_private::StringList &matches);

    
    static int
    ArchitectureNames (CommandInterpreter &interpreter,
                       const char *partial_file_name,
                       int match_start_point,
                       int max_return_elements,
                       SearchFilter *searcher,
                       bool &word_complete,
                       lldb_private::StringList &matches);

    static int
    VariablePath (CommandInterpreter &interpreter,
                  const char *partial_file_name,
                  int match_start_point,
                  int max_return_elements,
                  SearchFilter *searcher,
                  bool &word_complete,
                  lldb_private::StringList &matches);

    //----------------------------------------------------------------------
    // The Completer class is a convenient base class for building searchers
    // that go along with the SearchFilter passed to the standard Completer
    // functions.
    //----------------------------------------------------------------------
    class Completer : public Searcher
    {
    public:
        Completer (CommandInterpreter &interpreter,
                   const char *completion_str,
                   int match_start_point,
                   int max_return_elements,
                   StringList &matches);

        virtual ~Completer ();

        virtual CallbackReturn
        SearchCallback (SearchFilter &filter,
                        SymbolContext &context,
                        Address *addr,
                        bool complete) = 0;

        virtual Depth
        GetDepth () = 0;

        virtual size_t
        DoCompletion (SearchFilter *filter) = 0;

        protected:
            CommandInterpreter &m_interpreter;
            std::string m_completion_str;
            int m_match_start_point;
            int m_max_return_elements;
            StringList &m_matches;
        private:
            DISALLOW_COPY_AND_ASSIGN (Completer);
    };

    //----------------------------------------------------------------------
    // SouceFileCompleter implements the source file completer
    //----------------------------------------------------------------------
    class SourceFileCompleter : public Completer
    {
    public:

        SourceFileCompleter (CommandInterpreter &interpreter,
                             bool include_support_files,
                             const char *completion_str,
                             int match_start_point,
                             int max_return_elements,
                             StringList &matches);
        
        virtual Searcher::Depth GetDepth ();

        virtual Searcher::CallbackReturn
        SearchCallback (SearchFilter &filter,
                        SymbolContext &context,
                        Address *addr,
                        bool complete);

        size_t
        DoCompletion (SearchFilter *filter);

    private:
        bool m_include_support_files;
        FileSpecList m_matching_files;
        const char *m_file_name;
        const char *m_dir_name;
        DISALLOW_COPY_AND_ASSIGN (SourceFileCompleter);

    };

    //----------------------------------------------------------------------
    // ModuleCompleter implements the module completer
    //----------------------------------------------------------------------
    class ModuleCompleter : public Completer
    {
    public:

        ModuleCompleter (CommandInterpreter &interpreter,
                         const char *completion_str,
                         int match_start_point,
                         int max_return_elements,
                         StringList &matches);
        
        virtual Searcher::Depth GetDepth ();

        virtual Searcher::CallbackReturn
        SearchCallback (SearchFilter &filter,
                        SymbolContext &context,
                        Address *addr,
                        bool complete);

        size_t
        DoCompletion (SearchFilter *filter);

    private:
        const char *m_file_name;
        const char *m_dir_name;
        DISALLOW_COPY_AND_ASSIGN (ModuleCompleter);

    };

    //----------------------------------------------------------------------
    // SymbolCompleter implements the symbol completer
    //----------------------------------------------------------------------
    class SymbolCompleter : public Completer
    {
    public:

        SymbolCompleter (CommandInterpreter &interpreter,
                         const char *completion_str,
                         int match_start_point,
                         int max_return_elements,
                         StringList &matches);
        
        virtual Searcher::Depth GetDepth ();

        virtual Searcher::CallbackReturn
        SearchCallback (SearchFilter &filter,
                        SymbolContext &context,
                        Address *addr,
                        bool complete);

        size_t
        DoCompletion (SearchFilter *filter);

    private:
//        struct NameCmp {
//            bool operator() (const ConstString& lhs, const ConstString& rhs) const
//            {
//                return lhs < rhs;
//            }
//        };

        RegularExpression m_regex;
        typedef std::set<ConstString> collection;
        collection m_match_set;
        DISALLOW_COPY_AND_ASSIGN (SymbolCompleter);

    };

private:
    static CommonCompletionElement g_common_completions[];

};

} // namespace lldb_private
#endif  // lldb_CommandCompletions_h_