• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- CommandObjectMultiword.h --------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_INTERPRETER_COMMANDOBJECTMULTIWORD_H
10 #define LLDB_INTERPRETER_COMMANDOBJECTMULTIWORD_H
11 
12 #include "lldb/Interpreter/CommandObject.h"
13 #include "lldb/Utility/CompletionRequest.h"
14 
15 namespace lldb_private {
16 
17 // CommandObjectMultiword
18 
19 class CommandObjectMultiword : public CommandObject {
20   // These two want to iterate over the subcommand dictionary.
21   friend class CommandInterpreter;
22   friend class CommandObjectSyntax;
23 
24 public:
25   CommandObjectMultiword(CommandInterpreter &interpreter, const char *name,
26                          const char *help = nullptr,
27                          const char *syntax = nullptr, uint32_t flags = 0);
28 
29   ~CommandObjectMultiword() override;
30 
IsMultiwordObject()31   bool IsMultiwordObject() override { return true; }
32 
GetAsMultiwordCommand()33   CommandObjectMultiword *GetAsMultiwordCommand() override { return this; }
34 
35   bool LoadSubCommand(llvm::StringRef cmd_name,
36                       const lldb::CommandObjectSP &command_obj) override;
37 
38   void GenerateHelpText(Stream &output_stream) override;
39 
40   lldb::CommandObjectSP GetSubcommandSP(llvm::StringRef sub_cmd,
41                                         StringList *matches = nullptr) override;
42 
43   CommandObject *GetSubcommandObject(llvm::StringRef sub_cmd,
44                                      StringList *matches = nullptr) override;
45 
46   void AproposAllSubCommands(llvm::StringRef prefix,
47                              llvm::StringRef search_word,
48                              StringList &commands_found,
49                              StringList &commands_help) override;
50 
WantsRawCommandString()51   bool WantsRawCommandString() override { return false; }
52 
53   void HandleCompletion(CompletionRequest &request) override;
54 
55   const char *GetRepeatCommand(Args &current_command_args,
56                                uint32_t index) override;
57 
58   bool Execute(const char *args_string, CommandReturnObject &result) override;
59 
IsRemovable()60   bool IsRemovable() const override { return m_can_be_removed; }
61 
SetRemovable(bool removable)62   void SetRemovable(bool removable) { m_can_be_removed = removable; }
63 
64 protected:
GetSubcommandDictionary()65   CommandObject::CommandMap &GetSubcommandDictionary() {
66     return m_subcommand_dict;
67   }
68 
69   CommandObject::CommandMap m_subcommand_dict;
70   bool m_can_be_removed;
71 };
72 
73 class CommandObjectProxy : public CommandObject {
74 public:
75   CommandObjectProxy(CommandInterpreter &interpreter, const char *name,
76                      const char *help = nullptr, const char *syntax = nullptr,
77                      uint32_t flags = 0);
78 
79   ~CommandObjectProxy() override;
80 
81   // Subclasses must provide a command object that will be transparently used
82   // for this object.
83   virtual CommandObject *GetProxyCommandObject() = 0;
84 
85   llvm::StringRef GetSyntax() override;
86 
87   llvm::StringRef GetHelp() override;
88 
89   llvm::StringRef GetHelpLong() override;
90 
91   bool IsRemovable() const override;
92 
93   bool IsMultiwordObject() override;
94 
95   CommandObjectMultiword *GetAsMultiwordCommand() override;
96 
97   void GenerateHelpText(Stream &result) override;
98 
99   lldb::CommandObjectSP GetSubcommandSP(llvm::StringRef sub_cmd,
100                                         StringList *matches = nullptr) override;
101 
102   CommandObject *GetSubcommandObject(llvm::StringRef sub_cmd,
103                                      StringList *matches = nullptr) override;
104 
105   void AproposAllSubCommands(llvm::StringRef prefix,
106                              llvm::StringRef search_word,
107                              StringList &commands_found,
108                              StringList &commands_help) override;
109 
110   bool LoadSubCommand(llvm::StringRef cmd_name,
111                       const lldb::CommandObjectSP &command_obj) override;
112 
113   bool WantsRawCommandString() override;
114 
115   bool WantsCompletion() override;
116 
117   Options *GetOptions() override;
118 
119   void HandleCompletion(CompletionRequest &request) override;
120 
121   void
122   HandleArgumentCompletion(CompletionRequest &request,
123                            OptionElementVector &opt_element_vector) override;
124 
125   const char *GetRepeatCommand(Args &current_command_args,
126                                uint32_t index) override;
127 
128   /// \return
129   ///     An error message to be displayed when the command is executed (i.e.
130   ///     Execute is called) and \a GetProxyCommandObject returned null.
131   virtual llvm::StringRef GetUnsupportedError();
132 
133   bool Execute(const char *args_string, CommandReturnObject &result) override;
134 
135 protected:
136   // These two want to iterate over the subcommand dictionary.
137   friend class CommandInterpreter;
138   friend class CommandObjectSyntax;
139 };
140 
141 } // namespace lldb_private
142 
143 #endif // LLDB_INTERPRETER_COMMANDOBJECTMULTIWORD_H
144