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