CommandCompletions.h revision 73844aa19a7360b662e2be710fc3c969d6c86606
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 = 0u, 42 eSourceFileCompletion = (1u << 0), 43 eDiskFileCompletion = (1u << 1), 44 eDiskDirectoryCompletion = (1u << 2), 45 eSymbolCompletion = (1u << 3), 46 eModuleCompletion = (1u << 4), 47 eSettingsNameCompletion = (1u << 5), 48 ePlatformPluginCompletion = (1u << 6), 49 eArchitectureCompletion = (1u << 7), 50 // This item serves two purposes. It is the last element in the enum, 51 // so you can add custom enums starting from here in your Option class. 52 // Also if you & in this bit the base code will not process the option. 53 eCustomCompletion = (1u << 8) 54 55 } CommonCompletionTypes; 56 57 struct CommonCompletionElement 58 { 59 uint32_t type; 60 CompletionCallback callback; 61 }; 62 63 static bool InvokeCommonCompletionCallbacks (CommandInterpreter &interpreter, 64 uint32_t completion_mask, 65 const char *completion_str, 66 int match_start_point, 67 int max_return_elements, 68 SearchFilter *searcher, 69 bool &word_complete, 70 StringList &matches); 71 72 //---------------------------------------------------------------------- 73 // These are the generic completer functions: 74 //---------------------------------------------------------------------- 75 static int 76 DiskFiles (CommandInterpreter &interpreter, 77 const char *partial_file_name, 78 int match_start_point, 79 int max_return_elements, 80 SearchFilter *searcher, 81 bool &word_complete, 82 StringList &matches); 83 static int 84 DiskDirectories (CommandInterpreter &interpreter, 85 const char *partial_file_name, 86 int match_start_point, 87 int max_return_elements, 88 SearchFilter *searcher, 89 bool &word_complete, 90 StringList &matches); 91 92 static int 93 SourceFiles (CommandInterpreter &interpreter, 94 const char *partial_file_name, 95 int match_start_point, 96 int max_return_elements, 97 SearchFilter *searcher, 98 bool &word_complete, 99 StringList &matches); 100 101 static int 102 Modules (CommandInterpreter &interpreter, 103 const char *partial_file_name, 104 int match_start_point, 105 int max_return_elements, 106 SearchFilter *searcher, 107 bool &word_complete, 108 lldb_private::StringList &matches); 109 110 static int 111 Symbols (CommandInterpreter &interpreter, 112 const char *partial_file_name, 113 int match_start_point, 114 int max_return_elements, 115 SearchFilter *searcher, 116 bool &word_complete, 117 lldb_private::StringList &matches); 118 119 static int 120 SettingsNames (CommandInterpreter &interpreter, 121 const char *partial_file_name, 122 int match_start_point, 123 int max_return_elements, 124 SearchFilter *searcher, 125 bool &word_complete, 126 lldb_private::StringList &matches); 127 128 static int 129 PlatformPluginNames (CommandInterpreter &interpreter, 130 const char *partial_file_name, 131 int match_start_point, 132 int max_return_elements, 133 SearchFilter *searcher, 134 bool &word_complete, 135 lldb_private::StringList &matches); 136 137 138 static int 139 ArchitectureNames (CommandInterpreter &interpreter, 140 const char *partial_file_name, 141 int match_start_point, 142 int max_return_elements, 143 SearchFilter *searcher, 144 bool &word_complete, 145 lldb_private::StringList &matches); 146 147 //---------------------------------------------------------------------- 148 // The Completer class is a convenient base class for building searchers 149 // that go along with the SearchFilter passed to the standard Completer 150 // functions. 151 //---------------------------------------------------------------------- 152 class Completer : public Searcher 153 { 154 public: 155 Completer (CommandInterpreter &interpreter, 156 const char *completion_str, 157 int match_start_point, 158 int max_return_elements, 159 StringList &matches); 160 161 virtual ~Completer (); 162 163 virtual CallbackReturn 164 SearchCallback (SearchFilter &filter, 165 SymbolContext &context, 166 Address *addr, 167 bool complete) = 0; 168 169 virtual Depth 170 GetDepth () = 0; 171 172 virtual size_t 173 DoCompletion (SearchFilter *filter) = 0; 174 175 protected: 176 CommandInterpreter &m_interpreter; 177 std::string m_completion_str; 178 int m_match_start_point; 179 int m_max_return_elements; 180 StringList &m_matches; 181 private: 182 DISALLOW_COPY_AND_ASSIGN (Completer); 183 }; 184 185 //---------------------------------------------------------------------- 186 // SouceFileCompleter implements the source file completer 187 //---------------------------------------------------------------------- 188 class SourceFileCompleter : public Completer 189 { 190 public: 191 192 SourceFileCompleter (CommandInterpreter &interpreter, 193 bool include_support_files, 194 const char *completion_str, 195 int match_start_point, 196 int max_return_elements, 197 StringList &matches); 198 199 virtual Searcher::Depth GetDepth (); 200 201 virtual Searcher::CallbackReturn 202 SearchCallback (SearchFilter &filter, 203 SymbolContext &context, 204 Address *addr, 205 bool complete); 206 207 size_t 208 DoCompletion (SearchFilter *filter); 209 210 private: 211 bool m_include_support_files; 212 FileSpecList m_matching_files; 213 const char *m_file_name; 214 const char *m_dir_name; 215 DISALLOW_COPY_AND_ASSIGN (SourceFileCompleter); 216 217 }; 218 219 //---------------------------------------------------------------------- 220 // ModuleCompleter implements the module completer 221 //---------------------------------------------------------------------- 222 class ModuleCompleter : public Completer 223 { 224 public: 225 226 ModuleCompleter (CommandInterpreter &interpreter, 227 const char *completion_str, 228 int match_start_point, 229 int max_return_elements, 230 StringList &matches); 231 232 virtual Searcher::Depth GetDepth (); 233 234 virtual Searcher::CallbackReturn 235 SearchCallback (SearchFilter &filter, 236 SymbolContext &context, 237 Address *addr, 238 bool complete); 239 240 size_t 241 DoCompletion (SearchFilter *filter); 242 243 private: 244 const char *m_file_name; 245 const char *m_dir_name; 246 DISALLOW_COPY_AND_ASSIGN (ModuleCompleter); 247 248 }; 249 250 //---------------------------------------------------------------------- 251 // SymbolCompleter implements the symbol completer 252 //---------------------------------------------------------------------- 253 class SymbolCompleter : public Completer 254 { 255 public: 256 257 SymbolCompleter (CommandInterpreter &interpreter, 258 const char *completion_str, 259 int match_start_point, 260 int max_return_elements, 261 StringList &matches); 262 263 virtual Searcher::Depth GetDepth (); 264 265 virtual Searcher::CallbackReturn 266 SearchCallback (SearchFilter &filter, 267 SymbolContext &context, 268 Address *addr, 269 bool complete); 270 271 size_t 272 DoCompletion (SearchFilter *filter); 273 274 private: 275// struct NameCmp { 276// bool operator() (const ConstString& lhs, const ConstString& rhs) const 277// { 278// return lhs < rhs; 279// } 280// }; 281 282 RegularExpression m_regex; 283 typedef std::set<ConstString> collection; 284 collection m_match_set; 285 DISALLOW_COPY_AND_ASSIGN (SymbolCompleter); 286 287 }; 288 289private: 290 static CommonCompletionElement g_common_completions[]; 291 292}; 293 294} // namespace lldb_private 295#endif // lldb_CommandCompletions_h_ 296