CommandObject.h revision 84cdc15005983e5244d665fa779e33c2b6fac95f
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 (const char *command,
87                          CommandContext *context,
88                          CommandInterpreter *interpreter,
89                          CommandReturnObject &result);
90
91    bool
92    ParseOptions(Args& args,
93                 CommandInterpreter *interpreter,
94                 CommandReturnObject &result);
95
96    bool
97    ExecuteWithOptions (Args& command,
98                        CommandContext *context,
99                        CommandInterpreter *interpreter,
100                        CommandReturnObject &result);
101
102    virtual bool
103    ExecuteRawCommandString (const char *command,
104                             CommandContext *context,
105                             CommandInterpreter *interpreter,
106                             CommandReturnObject &result)
107    {
108        return false;
109    }
110
111
112    virtual bool
113    Execute (Args& command,
114             CommandContext *context,
115             CommandInterpreter *interpreter,
116             CommandReturnObject &result) = 0;
117
118    void
119    SetCommandName (const char *name);
120
121    // This function really deals with CommandObjectLists, but we didn't make a
122    // CommandObjectList class, so I'm sticking it here.  But we really should have
123    // such a class.  Anyway, it looks up the commands in the map that match the partial
124    // string cmd_str, inserts the matches into matches, and returns the number added.
125
126    static int
127    AddNamesMatchingPartialString (CommandMap &in_map, const char *cmd_str, StringList &matches);
128
129    // The input array contains a parsed version of the line.  The insertion
130    // point is given by cursor_index (the index in input of the word containing
131    // the cursor) and cursor_char_position (the position of the cursor in that word.)
132    // This default version handles calling option argument completions and then calls
133    // HandleArgumentCompletion if the cursor is on an argument, not an option.
134    // Don't override this method, override HandleArgumentCompletion instead unless
135    // you have special reasons.
136    virtual int
137    HandleCompletion (Args &input,
138                      int &cursor_index,
139                      int &cursor_char_position,
140                      int match_start_point,
141                      int max_return_elements,
142                      CommandInterpreter *interpreter,
143                      StringList &matches);
144
145    // The input array contains a parsed version of the line.  The insertion
146    // point is given by cursor_index (the index in input of the word containing
147    // the cursor) and cursor_char_position (the position of the cursor in that word.)
148    // We've constructed the map of options and their arguments as well if that is
149    // helpful for the completion.
150
151    virtual int
152    HandleArgumentCompletion (Args &input,
153                      int &cursor_index,
154                      int &cursor_char_position,
155                      OptionElementVector &opt_element_vector,
156                      int match_start_point,
157                      int max_return_elements,
158                      CommandInterpreter *interpreter,
159                      StringList &matches);
160
161
162    bool
163    HelpTextContainsWord (const char *search_word);
164
165    //------------------------------------------------------------------
166    /// The flags accessor.
167    ///
168    /// @return
169    ///     A reference to the Flags member variable.
170    //------------------------------------------------------------------
171    Flags&
172    GetFlags();
173
174    //------------------------------------------------------------------
175    /// The flags const accessor.
176    ///
177    /// @return
178    ///     A const reference to the Flags member variable.
179    //------------------------------------------------------------------
180    const Flags&
181    GetFlags() const;
182
183protected:
184    std::string m_cmd_name;
185    std::string m_cmd_help_short;
186    std::string m_cmd_help_long;
187    std::string m_cmd_syntax;
188    Flags       m_flags;
189};
190
191} // namespace lldb_private
192
193
194#endif  // liblldb_CommandObject_h_
195