CommandObject.h revision 63094e0bb161580564954dee512955c1c79d3476
1//===-- CommandObject.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 liblldb_CommandObject_h_ 11#define liblldb_CommandObject_h_ 12 13#include <map> 14#include <set> 15#include <string> 16#include <vector> 17 18#include "lldb/lldb-private.h" 19#include "lldb/Interpreter/Args.h" 20#include "lldb/Core/StringList.h" 21#include "lldb/Core/Flags.h" 22 23namespace lldb_private { 24 25class CommandObject 26{ 27public: 28 typedef std::map<std::string, lldb::CommandObjectSP> CommandMap; 29 30 31 CommandObject (const char *name, 32 const char *help = NULL, 33 const char *syntax = NULL, 34 uint32_t flags = 0); 35 36 virtual 37 ~CommandObject (); 38 39 const char * 40 GetHelp (); 41 42 const char * 43 GetHelpLong (); 44 45 const char * 46 GetSyntax (); 47 48 const char * 49 Translate (); 50 51 const char * 52 GetCommandName (); 53 54 void 55 SetHelp (const char * str); 56 57 void 58 SetHelpLong (const char * str); 59 60 void 61 SetSyntax (const char *str); 62 63 virtual void 64 AddObject (const char *obj_name) {} 65 66 virtual bool 67 IsCrossRefObject () { return false; } 68 69 virtual bool 70 IsMultiwordObject () { return false; } 71 72 virtual bool 73 WantsRawCommandString() { return false; } 74 75 virtual Options * 76 GetOptions (); 77 78 enum 79 { 80 eFlagProcessMustBeLaunched = (1 << 0), 81 eFlagProcessMustBePaused = (1 << 1) 82 }; 83 84 // Do not override this 85 bool 86 ExecuteCommandString (CommandInterpreter &interpreter, 87 const char *command, 88 CommandReturnObject &result); 89 90 bool 91 ParseOptions (CommandInterpreter &interpreter, 92 Args& args, 93 CommandReturnObject &result); 94 95 bool 96 ExecuteWithOptions (CommandInterpreter &interpreter, 97 Args& command, 98 CommandReturnObject &result); 99 100 virtual bool 101 ExecuteRawCommandString (CommandInterpreter &interpreter, 102 const char *command, 103 CommandReturnObject &result) 104 { 105 return false; 106 } 107 108 109 virtual bool 110 Execute (CommandInterpreter &interpreter, 111 Args& command, 112 CommandReturnObject &result) = 0; 113 114 void 115 SetCommandName (const char *name); 116 117 // This function really deals with CommandObjectLists, but we didn't make a 118 // CommandObjectList class, so I'm sticking it here. But we really should have 119 // such a class. Anyway, it looks up the commands in the map that match the partial 120 // string cmd_str, inserts the matches into matches, and returns the number added. 121 122 static int 123 AddNamesMatchingPartialString (CommandMap &in_map, const char *cmd_str, StringList &matches); 124 125 // The input array contains a parsed version of the line. The insertion 126 // point is given by cursor_index (the index in input of the word containing 127 // the cursor) and cursor_char_position (the position of the cursor in that word.) 128 // This default version handles calling option argument completions and then calls 129 // HandleArgumentCompletion if the cursor is on an argument, not an option. 130 // Don't override this method, override HandleArgumentCompletion instead unless 131 // you have special reasons. 132 virtual int 133 HandleCompletion (CommandInterpreter &interpreter, 134 Args &input, 135 int &cursor_index, 136 int &cursor_char_position, 137 int match_start_point, 138 int max_return_elements, 139 StringList &matches); 140 141 // The input array contains a parsed version of the line. The insertion 142 // point is given by cursor_index (the index in input of the word containing 143 // the cursor) and cursor_char_position (the position of the cursor in that word.) 144 // We've constructed the map of options and their arguments as well if that is 145 // helpful for the completion. 146 147 virtual int 148 HandleArgumentCompletion (CommandInterpreter &interpreter, 149 Args &input, 150 int &cursor_index, 151 int &cursor_char_position, 152 OptionElementVector &opt_element_vector, 153 int match_start_point, 154 int max_return_elements, 155 StringList &matches) 156 { 157 return 0; 158 } 159 160 bool 161 HelpTextContainsWord (const char *search_word); 162 163 //------------------------------------------------------------------ 164 /// The flags accessor. 165 /// 166 /// @return 167 /// A reference to the Flags member variable. 168 //------------------------------------------------------------------ 169 Flags& 170 GetFlags(); 171 172 //------------------------------------------------------------------ 173 /// The flags const accessor. 174 /// 175 /// @return 176 /// A const reference to the Flags member variable. 177 //------------------------------------------------------------------ 178 const Flags& 179 GetFlags() const; 180 181protected: 182 std::string m_cmd_name; 183 std::string m_cmd_help_short; 184 std::string m_cmd_help_long; 185 std::string m_cmd_syntax; 186 Flags m_flags; 187}; 188 189} // namespace lldb_private 190 191 192#endif // liblldb_CommandObject_h_ 193