1 //===-- CommandObjectMultiword.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_CommandObjectMultiword_h_
11 #define liblldb_CommandObjectMultiword_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <map>
16 
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/Interpreter/CommandObject.h"
20 
21 namespace lldb_private {
22 
23 //-------------------------------------------------------------------------
24 // CommandObjectMultiword
25 //-------------------------------------------------------------------------
26 
27 class CommandObjectMultiword : public CommandObject
28 {
29 // These two want to iterate over the subcommand dictionary.
30 friend class CommandInterpreter;
31 friend class CommandObjectSyntax;
32 public:
33     CommandObjectMultiword (CommandInterpreter &interpreter,
34                             const char *name,
35                             const char *help = NULL,
36                             const char *syntax = NULL,
37                             uint32_t flags = 0);
38 
39     virtual
40     ~CommandObjectMultiword ();
41 
42     virtual bool
IsMultiwordObject()43     IsMultiwordObject () { return true; }
44 
45     virtual bool
46     LoadSubCommand (const char *cmd_name,
47                     const lldb::CommandObjectSP& command_obj);
48 
49     virtual void
50     GenerateHelpText (Stream &output_stream);
51 
52     virtual lldb::CommandObjectSP
53     GetSubcommandSP (const char *sub_cmd, StringList *matches = NULL);
54 
55     virtual CommandObject *
56     GetSubcommandObject (const char *sub_cmd, StringList *matches = NULL);
57 
58     virtual void
59     AproposAllSubCommands (const char *prefix,
60                            const char *search_word,
61                            StringList &commands_found,
62                            StringList &commands_help);
63 
64     virtual bool
WantsRawCommandString()65     WantsRawCommandString() { return false; };
66 
67     virtual int
68     HandleCompletion (Args &input,
69                       int &cursor_index,
70                       int &cursor_char_position,
71                       int match_start_point,
72                       int max_return_elements,
73                       bool &word_complete,
74                       StringList &matches);
75 
76     virtual const char *GetRepeatCommand (Args &current_command_args, uint32_t index);
77 
78     virtual bool
79     Execute (const char *args_string,
80              CommandReturnObject &result);
81 
82     virtual bool
IsRemovable()83     IsRemovable() const { return m_can_be_removed; }
84 
85     void
SetRemovable(bool removable)86     SetRemovable (bool removable)
87     {
88         m_can_be_removed = removable;
89     }
90 
91 protected:
92 
93     CommandObject::CommandMap m_subcommand_dict;
94     bool m_can_be_removed;
95 };
96 
97 
98 class CommandObjectProxy : public CommandObject
99 {
100 public:
101     CommandObjectProxy (CommandInterpreter &interpreter,
102                         const char *name,
103                         const char *help = NULL,
104                         const char *syntax = NULL,
105                         uint32_t flags = 0);
106 
107     virtual
108     ~CommandObjectProxy ();
109 
110     // Subclasses must provide a command object that will be transparently
111     // used for this object.
112     virtual CommandObject *
113     GetProxyCommandObject() = 0;
114 
115     virtual const char *
116     GetHelpLong ();
117 
118     virtual bool
119     IsRemovable() const;
120 
121     virtual bool
122     IsMultiwordObject ();
123 
124     virtual lldb::CommandObjectSP
125     GetSubcommandSP (const char *sub_cmd, StringList *matches = NULL);
126 
127     virtual CommandObject *
128     GetSubcommandObject (const char *sub_cmd, StringList *matches = NULL);
129 
130     virtual void
131     AproposAllSubCommands (const char *prefix,
132                            const char *search_word,
133                            StringList &commands_found,
134                            StringList &commands_help);
135 
136     virtual bool
137     LoadSubCommand (const char *cmd_name,
138                     const lldb::CommandObjectSP& command_obj);
139 
140     virtual bool
141     WantsRawCommandString();
142 
143     virtual bool
144     WantsCompletion();
145 
146     virtual Options *
147     GetOptions ();
148 
149 
150     virtual int
151     HandleCompletion (Args &input,
152                       int &cursor_index,
153                       int &cursor_char_position,
154                       int match_start_point,
155                       int max_return_elements,
156                       bool &word_complete,
157                       StringList &matches);
158 
159     virtual int
160     HandleArgumentCompletion (Args &input,
161                               int &cursor_index,
162                               int &cursor_char_position,
163                               OptionElementVector &opt_element_vector,
164                               int match_start_point,
165                               int max_return_elements,
166                               bool &word_complete,
167                               StringList &matches);
168 
169     virtual const char *
170     GetRepeatCommand (Args &current_command_args,
171                       uint32_t index);
172 
173     virtual bool
174     Execute (const char *args_string,
175              CommandReturnObject &result);
176 
177 protected:
178 
179     // These two want to iterate over the subcommand dictionary.
180     friend class CommandInterpreter;
181     friend class CommandObjectSyntax;
182 
183 };
184 
185 } // namespace lldb_private
186 
187 #endif  // liblldb_CommandObjectMultiword_h_
188